]> source.dussan.org Git - aspectj.git/commitdiff
258510: promoted additional annotation/class/interface storage from delegate to refer...
authoraclement <aclement>
Tue, 20 Jan 2009 22:41:35 +0000 (22:41 +0000)
committeraclement <aclement>
Tue, 20 Jan 2009 22:41:35 +0000 (22:41 +0000)
org.aspectj.matcher/src/org/aspectj/weaver/BoundedReferenceType.java
org.aspectj.matcher/src/org/aspectj/weaver/GeneratedReferenceTypeDelegate.java
org.aspectj.matcher/src/org/aspectj/weaver/ReferenceType.java
org.aspectj.matcher/src/org/aspectj/weaver/ReferenceTypeDelegate.java
org.aspectj.matcher/src/org/aspectj/weaver/ResolvedType.java
org.aspectj.matcher/src/org/aspectj/weaver/TypeVariable.java
org.aspectj.matcher/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegate.java

index 1839d2c738fb8062e3c817f36a7fe20d9d22aaba..e983c4aeb35f826abd1fc6ad02e8069499141672 100644 (file)
@@ -18,11 +18,10 @@ import java.util.Map;
 import org.aspectj.weaver.patterns.PerClause;
 
 /**
- * A BoundedReferenceType is the result of a generics wildcard expression ?
- * extends String, ? super Foo etc..
+ * A BoundedReferenceType is the result of a generics wildcard expression ? extends String, ? super Foo etc..
  * 
- * The "signature" for a bounded reference type follows the generic signature
- * specification in section 4.4 of JVM spec: *,+,- plus signature strings.
+ * The "signature" for a bounded reference type follows the generic signature specification in section 4.4 of JVM spec: *,+,- plus
+ * signature strings.
  * 
  * The bound may be a type variable (e.g. ? super T)
  */
@@ -46,10 +45,8 @@ public class BoundedReferenceType extends ReferenceType {
                return lowerBound;
        }
 
-       public BoundedReferenceType(ReferenceType aBound, boolean isExtends,
-                       World world) {
-               super((isExtends ? "+" : "-") + aBound.signature,
-                               aBound.signatureErasure, world);
+       public BoundedReferenceType(ReferenceType aBound, boolean isExtends, World world) {
+               super((isExtends ? "+" : "-") + aBound.signature, aBound.signatureErasure, world);
                this.isExtends = isExtends;
                this.isSuper = !isExtends;
                if (isExtends) {
@@ -58,12 +55,10 @@ public class BoundedReferenceType extends ReferenceType {
                        lowerBound = aBound;
                        upperBound = world.resolve(UnresolvedType.OBJECT);
                }
-               setDelegate(new ReferenceTypeReferenceTypeDelegate(
-                               (ReferenceType) getUpperBound()));
+               setDelegate(new ReferenceTypeReferenceTypeDelegate((ReferenceType) getUpperBound()));
        }
 
-       public BoundedReferenceType(ReferenceType aBound, boolean isExtends,
-                       World world, ReferenceType[] additionalInterfaces) {
+       public BoundedReferenceType(ReferenceType aBound, boolean isExtends, World world, ReferenceType[] additionalInterfaces) {
                this(aBound, isExtends, world);
                this.additionalInterfaceBounds = additionalInterfaces;
        }
@@ -76,29 +71,24 @@ public class BoundedReferenceType extends ReferenceType {
                ReferenceType[] parameterizedAdditionalInterfaces = new ReferenceType[additionalInterfaceBounds == null ? 0
                                : additionalInterfaceBounds.length];
                for (int i = 0; i < parameterizedAdditionalInterfaces.length; i++) {
-                       parameterizedAdditionalInterfaces[i] = (ReferenceType) additionalInterfaceBounds[i]
-                                       .parameterize(typeBindings);
+                       parameterizedAdditionalInterfaces[i] = (ReferenceType) additionalInterfaceBounds[i].parameterize(typeBindings);
                }
                if (isExtends) {
-                       return new BoundedReferenceType((ReferenceType) getUpperBound()
-                                       .parameterize(typeBindings), isExtends, world,
+                       return new BoundedReferenceType((ReferenceType) getUpperBound().parameterize(typeBindings), isExtends, world,
                                        parameterizedAdditionalInterfaces);
                } else {
-                       return new BoundedReferenceType((ReferenceType) getLowerBound()
-                                       .parameterize(typeBindings), isExtends, world,
+                       return new BoundedReferenceType((ReferenceType) getLowerBound().parameterize(typeBindings), isExtends, world,
                                        parameterizedAdditionalInterfaces);
                }
        }
 
        /**
-        * only for use when resolving GenericsWildcardTypeX or a
-        * TypeVariableReferenceType
+        * only for use when resolving GenericsWildcardTypeX or a TypeVariableReferenceType
         */
        protected BoundedReferenceType(String sig, String sigErasure, World world) {
                super(sig, sigErasure, world);
                upperBound = world.resolve(UnresolvedType.OBJECT);
-               setDelegate(new ReferenceTypeReferenceTypeDelegate(
-                               (ReferenceType) getUpperBound()));
+               setDelegate(new ReferenceTypeReferenceTypeDelegate((ReferenceType) getUpperBound()));
        }
 
        public ReferenceType[] getInterfaceBounds() {
@@ -110,8 +100,7 @@ public class BoundedReferenceType extends ReferenceType {
        }
 
        public boolean isExtends() {
-               return (isExtends && !getUpperBound().getSignature().equals(
-                               "Ljava/lang/Object;"));
+               return (isExtends && !getUpperBound().getSignature().equals("Ljava/lang/Object;"));
        }
 
        public boolean isSuper() {
@@ -121,12 +110,10 @@ public class BoundedReferenceType extends ReferenceType {
        public boolean alwaysMatches(ResolvedType aCandidateType) {
                if (isExtends()) {
                        // aCandidateType must be a subtype of upperBound
-                       return ((ReferenceType) getUpperBound())
-                                       .isAssignableFrom(aCandidateType);
+                       return ((ReferenceType) getUpperBound()).isAssignableFrom(aCandidateType);
                } else if (isSuper()) {
                        // aCandidateType must be a supertype of lowerBound
-                       return aCandidateType
-                                       .isAssignableFrom((ReferenceType) getLowerBound());
+                       return aCandidateType.isAssignableFrom((ReferenceType) getLowerBound());
                } else {
                        return true; // straight '?'
                }
@@ -142,9 +129,7 @@ public class BoundedReferenceType extends ReferenceType {
                        ResolvedType myLowerBound = (ResolvedType) getLowerBound();
                        if (isExtends()) {
                                if (boundedRT.isExtends()) {
-                                       return myUpperBound
-                                                       .isAssignableFrom((ResolvedType) boundedRT
-                                                                       .getUpperBound());
+                                       return myUpperBound.isAssignableFrom((ResolvedType) boundedRT.getUpperBound());
                                } else if (boundedRT.isSuper()) {
                                        return myUpperBound == boundedRT.getLowerBound();
                                } else {
@@ -152,8 +137,7 @@ public class BoundedReferenceType extends ReferenceType {
                                }
                        } else if (isSuper()) {
                                if (boundedRT.isSuper()) {
-                                       return ((ResolvedType) boundedRT.getLowerBound())
-                                                       .isAssignableFrom(myLowerBound);
+                                       return ((ResolvedType) boundedRT.getLowerBound()).isAssignableFrom(myLowerBound);
                                } else if (boundedRT.isExtends()) {
                                        return myLowerBound == boundedRT.getUpperBound();
                                } else {
@@ -181,13 +165,9 @@ public class BoundedReferenceType extends ReferenceType {
        public ResolvedType[] getDeclaredInterfaces() {
                ResolvedType[] interfaces = super.getDeclaredInterfaces();
                if (additionalInterfaceBounds.length > 0) {
-                       ResolvedType[] allInterfaces = new ResolvedType[interfaces.length
-                                       + additionalInterfaceBounds.length];
-                       System
-                                       .arraycopy(interfaces, 0, allInterfaces, 0,
-                                                       interfaces.length);
-                       System.arraycopy(additionalInterfaceBounds, 0, allInterfaces,
-                                       interfaces.length, additionalInterfaceBounds.length);
+                       ResolvedType[] allInterfaces = new ResolvedType[interfaces.length + additionalInterfaceBounds.length];
+                       System.arraycopy(interfaces, 0, allInterfaces, 0, interfaces.length);
+                       System.arraycopy(additionalInterfaceBounds, 0, allInterfaces, interfaces.length, additionalInterfaceBounds.length);
                        return allInterfaces;
                } else {
                        return interfaces;
@@ -198,18 +178,12 @@ public class BoundedReferenceType extends ReferenceType {
                return true;
        }
 
-       protected static class ReferenceTypeReferenceTypeDelegate extends
-                       AbstractReferenceTypeDelegate {
+       protected static class ReferenceTypeReferenceTypeDelegate extends AbstractReferenceTypeDelegate {
 
                public ReferenceTypeReferenceTypeDelegate(ReferenceType backing) {
                        super(backing, false);
                }
 
-               public void addAnnotation(AnnotationAJ annotationX) {
-                       throw new UnsupportedOperationException(
-                                       "What on earth do you think you are doing???");
-               }
-
                public boolean isAspect() {
                        return resolvedTypeX.isAspect();
                }
@@ -326,9 +300,5 @@ public class BoundedReferenceType extends ReferenceType {
                        return resolvedTypeX.getTypeVariables();
                }
 
-               public void ensureDelegateConsistent() {
-                       resolvedTypeX.getDelegate().ensureDelegateConsistent();
-               }
-
        }
 }
index 88e8c875943e2c1a9e728d98626db6ed13336443..6461ef135c943f4676dbb168ec5b5e85188d3a2d 100644 (file)
@@ -26,11 +26,6 @@ public class GeneratedReferenceTypeDelegate extends AbstractReferenceTypeDelegat
        public GeneratedReferenceTypeDelegate(ReferenceType backing) {
                super(backing, false);
        }
-
-       public void addAnnotation(AnnotationAJ annotationX) {
-               throw new UnsupportedOperationException("Not supported for GeneratedReferenceTypeDelegate");
-       }
-
        public boolean isAspect() {
                throw new UnsupportedOperationException("Not supported for GeneratedReferenceTypeDelegate");
        }
@@ -151,8 +146,4 @@ public class GeneratedReferenceTypeDelegate extends AbstractReferenceTypeDelegat
                throw new UnsupportedOperationException("Not supported for GeneratedReferenceTypeDelegate");
        }
 
-       public void ensureDelegateConsistent() {
-               throw new UnsupportedOperationException("Not supported for GeneratedReferenceTypeDelegate");
-       }
-
 }
\ No newline at end of file
index 1eb06cc90ccc66700d0550b11ad7ac08130e6eb6..9757e441ba818d847004cb9305a47c7378e4bcbb 100644 (file)
@@ -53,6 +53,18 @@ public class ReferenceType extends ResolvedType {
        Collection parameterizedDeclares = null;
        Collection parameterizedTypeMungers = null;
 
+       // During matching it can be necessary to temporary mark types as annotated. For example
+       // a declare @type may trigger a separate declare parents to match, and so the annotation
+       // is temporarily held against the referencetype, the annotation will be properly
+       // added to the class during weaving.
+       private ResolvedType[] annotationTypes = null;
+       private AnnotationAJ[] annotations = null;
+       
+       // Similarly these are temporary replacements and additions for the superclass and
+       // superinterfaces
+       private ResolvedType newSuperclass;
+       private ResolvedType[] newInterfaces;
+
        // ??? should set delegate before any use
        public ReferenceType(String signature, World world) {
                super(signature, world);
@@ -133,23 +145,72 @@ public class ReferenceType extends ResolvedType {
        }
 
        public void addAnnotation(AnnotationAJ annotationX) {
-               delegate.addAnnotation(annotationX);
+               if (annotations == null) {
+                       annotations = new AnnotationAJ[1];
+                       annotations[0] = annotationX;
+               } else {
+                       AnnotationAJ[] newAnnotations = new AnnotationAJ[annotations.length + 1];
+                       System.arraycopy(annotations, 0, newAnnotations, 1, annotations.length);
+                       newAnnotations[0] = annotationX;
+                       annotations = newAnnotations;
+               }
+               addAnnotationType(annotationX.getType());
        }
 
        public boolean hasAnnotation(UnresolvedType ofType) {
-               return delegate.hasAnnotation(ofType);
+               boolean onDelegate = delegate.hasAnnotation(ofType);
+               if (onDelegate) {
+                       return true;
+               }
+               if (annotationTypes != null) {
+                       for (int i = 0; i < annotationTypes.length; i++) {
+                               if (annotationTypes[i].equals(ofType)) {
+                                       return true;
+                               }
+                       }
+               }
+               return false;
+       }
+
+       private void addAnnotationType(ResolvedType ofType) {
+               if (annotationTypes == null) {
+                       annotationTypes = new ResolvedType[1];
+                       annotationTypes[0] = ofType;
+               } else {
+                       ResolvedType[] newAnnotationTypes = new ResolvedType[annotationTypes.length + 1];
+                       System.arraycopy(annotationTypes, 0, newAnnotationTypes, 1, annotationTypes.length);
+                       newAnnotationTypes[0] = ofType;
+                       annotationTypes = newAnnotationTypes;
+               }
        }
 
        public ResolvedType[] getAnnotationTypes() {
                if (delegate == null) {
                        throw new BCException("Unexpected null delegate for type " + this.getName());
                }
-               return delegate.getAnnotationTypes();
+               if (annotationTypes == null) {
+                       // there are no extras:
+                       return delegate.getAnnotationTypes();
+               } else {
+                       ResolvedType[] delegateAnnotationTypes = delegate.getAnnotationTypes();
+                       ResolvedType[] result = new ResolvedType[annotationTypes.length + delegateAnnotationTypes.length];
+                       System.arraycopy(delegateAnnotationTypes, 0, result, 0, delegateAnnotationTypes.length);
+                       System.arraycopy(annotationTypes, 0, result, delegateAnnotationTypes.length, annotationTypes.length);
+                       return result;
+               }
        }
 
        public AnnotationAJ getAnnotationOfType(UnresolvedType ofType) {
                AnnotationAJ[] axs = delegate.getAnnotations();
                if (axs == null) {
+                       if (annotations != null) {
+                               String searchSig = ofType.getSignature();
+                               for (int i = 0; i < annotations.length; i++) {
+                                       if (annotations[i].getTypeSignature().equals(searchSig)) {
+                                               return annotations[i];
+                                       }
+                               }
+                       }
                        return null;
                }
                for (int i = 0; i < axs.length; i++) {
@@ -477,8 +538,14 @@ public class ReferenceType extends ResolvedType {
        public ResolvedType[] getDeclaredInterfaces() {
                if (parameterizedInterfaces != null)
                        return parameterizedInterfaces;
+               ResolvedType[] delegateInterfaces = delegate.getDeclaredInterfaces();
+               if (newInterfaces != null) {
+                       ResolvedType[] extraInterfaces = new ResolvedType[delegateInterfaces.length + newInterfaces.length];
+                       System.arraycopy(delegateInterfaces, 0, extraInterfaces, 0, delegateInterfaces.length);
+                       System.arraycopy(newInterfaces, 0, extraInterfaces, delegateInterfaces.length, newInterfaces.length);
+                       delegateInterfaces = extraInterfaces;
+               }
                if (isParameterizedType()) {
-                       ResolvedType[] delegateInterfaces = delegate.getDeclaredInterfaces();
                        // UnresolvedType[] paramTypes =
                        // getTypesForMemberParameterization();
                        parameterizedInterfaces = new ResolvedType[delegateInterfaces.length];
@@ -495,7 +562,6 @@ public class ReferenceType extends ResolvedType {
                        }
                        return parameterizedInterfaces;
                } else if (isRawType()) {
-                       ResolvedType[] delegateInterfaces = delegate.getDeclaredInterfaces();
                        UnresolvedType[] paramTypes = getTypesForMemberParameterization();
                        parameterizedInterfaces = new ResolvedType[delegateInterfaces.length];
                        for (int i = 0; i < parameterizedInterfaces.length; i++) {
@@ -513,7 +579,7 @@ public class ReferenceType extends ResolvedType {
                        }
                        return parameterizedInterfaces;
                }
-               return delegate.getDeclaredInterfaces();
+               return delegateInterfaces;
        }
 
        /**
@@ -715,6 +781,12 @@ public class ReferenceType extends ResolvedType {
        }
 
        public ResolvedType getSuperclass() {
+               if (newSuperclass != null) {
+                       if (this.isParameterizedType() && newSuperclass.isParameterizedType()) {
+                               return newSuperclass.parameterize(getMemberParameterizationMap()).resolve(getWorld());
+                       }
+                       return newSuperclass;
+               }
                ResolvedType ret = null;
                try {
                        world.setTypeVariableLookupScope(this);
@@ -840,4 +912,36 @@ public class ReferenceType extends ResolvedType {
                return ret.toString();
        }
 
+       public void ensureConsistent() {
+               annotations = null;
+               annotationTypes = null;
+               newSuperclass = null;
+               newInterfaces = null;
+       }
+
+
+       public void addParent(ResolvedType newParent) {
+               if (newParent.isClass()) {
+                       newSuperclass = newParent;
+               } else {
+                       if (newInterfaces == null) {
+                               newInterfaces = new ResolvedType[1];
+                               newInterfaces[0] = newParent;
+                       } else {
+                               ResolvedType[] existing = delegate.getDeclaredInterfaces();
+                               if (existing != null) {
+                                       for (int i = 0; i < existing.length; i++) {
+                                               if (existing[i].equals(newParent)) {
+                                                       return; // already has this interface
+                                               }
+                                       }
+                               }
+                               ResolvedType[] newNewInterfaces = new ResolvedType[newInterfaces.length + 1];
+                               System.arraycopy(newInterfaces, 0, newNewInterfaces, 1, newInterfaces.length);
+                               newNewInterfaces[0] = newParent;
+                               newInterfaces = newNewInterfaces;
+                               parameterizedInterfaces = null;// invalidate cached info
+                       }
+               }
+       }
 }
\ No newline at end of file
index ec9d83915c9e83a1080bee1cd261c3604a13ae93..014e40b8328db356c2c42627e819797046c65b43 100644 (file)
@@ -17,21 +17,17 @@ import java.util.Collection;
 import org.aspectj.weaver.patterns.PerClause;
 
 /**
- * Abstraction over a type - a reference type is Object and a descendant of Object, other types (int/etc) are considered primitive
+ * Abstraction over a type - a reference type is Object or a descendant of Object, other types (int/etc) are considered primitive
  * types. Abstract implementation provided by AbstractReferenceTypeDelegate.
  */
-public interface ReferenceTypeDelegate {
-
-       // TODO asc move to proxy
-       public void addAnnotation(AnnotationAJ annotationX);
-
-       public void ensureDelegateConsistent(); // Required evil because of mutator
 
-       // methods in delegates :( (see
-       // pr85132)
+public interface ReferenceTypeDelegate {
 
        public boolean isAspect();
-
+       
+       /**
+        * @return true if the type is an annotation style aspect (a type marked @Aspect)
+        */
        public boolean isAnnotationStyleAspect();
 
        public boolean isInterface();
@@ -42,10 +38,19 @@ public interface ReferenceTypeDelegate {
 
        public String getRetentionPolicy();
 
+       /**
+        * @return true if this annotation type can be on a regular type (ie. it doesn't specify anything or it specifies TYPE)
+        */
        public boolean canAnnotationTargetType();
 
+       /**
+        * @return all the possible targets that this annotation can be placed upon
+        */
        public AnnotationTargetKind[] getAnnotationTargetKinds();
 
+       /**
+        * @return true if this annotation type has a retention policy of RUNTIME
+        */
        public boolean isAnnotationWithRuntimeRetention();
 
        public boolean isClass();
@@ -56,8 +61,6 @@ public interface ReferenceTypeDelegate {
 
        public boolean isNested();
 
-       public boolean isExposedToWeaver();
-
        public boolean hasAnnotation(UnresolvedType ofType);
 
        public AnnotationAJ[] getAnnotations();
@@ -74,6 +77,12 @@ public interface ReferenceTypeDelegate {
 
        public TypeVariable[] getTypeVariables();
 
+       public int getModifiers();
+
+       // aspect declaration related members
+       /**
+        * @return for an aspect declaration, return the
+        */
        public PerClause getPerClause();
 
        public Collection getDeclares();
@@ -82,7 +91,7 @@ public interface ReferenceTypeDelegate {
 
        public Collection getPrivilegedAccesses();
 
-       public int getModifiers();
+       // end of aspect declaration related members
 
        public ResolvedType getSuperclass();
 
@@ -90,6 +99,9 @@ public interface ReferenceTypeDelegate {
 
        public ReferenceType getResolvedTypeX();
 
+       // needs renaming isWeavable or removing from here
+       public boolean isExposedToWeaver();
+
        public boolean doesNotExposeShadowMungers();
 
        public ISourceContext getSourceContext();
index 118a1dc63f10f3b45bf8bc4e3daa7a2a23a17923..2b5fd8f4b6384cd43189077092200403f1b16c7a 100644 (file)
@@ -335,39 +335,39 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl
         * described in JVM spec 2ed 5.4.3.3. Doesnt check ITDs.
         * 
         * <p>
-        * Check the current type for the method.  If it is not found, check the super class and any super interfaces.  Taking
-        * care not to process interfaces multiple times.
+        * Check the current type for the method. If it is not found, check the super class and any super interfaces. Taking care not to
+        * process interfaces multiple times.
         */
        public ResolvedMember lookupMethod(Member m) {
                List typesTolookat = new ArrayList();
                typesTolookat.add(this);
                int pos = 0;
-               while (pos<typesTolookat.size()) {
-                       ResolvedType type = (ResolvedType)typesTolookat.get(pos++);
+               while (pos < typesTolookat.size()) {
+                       ResolvedType type = (ResolvedType) typesTolookat.get(pos++);
                        if (!type.isMissing()) {
                                ResolvedMember[] methods = type.getDeclaredMethods();
-                               if (methods!=null) {
-                                       for (int i=0;i<methods.length;i++) {
+                               if (methods != null) {
+                                       for (int i = 0; i < methods.length; i++) {
                                                ResolvedMember method = methods[i];
                                                if (matches(method, m)) {
                                                        return method;
                                                }
                                                // might be worth checking the method behind the parameterized method (137496)
-                                               if (method.hasBackingGenericMember() && m.getName().equals(method.getName())) { 
+                                               if (method.hasBackingGenericMember() && m.getName().equals(method.getName())) {
                                                        if (matches(method.getBackingGenericMember(), m))
                                                                return method;
-                                               }                                       
+                                               }
                                        }
                                }
                        }
                        // Queue the superclass:
                        ResolvedType superclass = type.getSuperclass();
-                       if (superclass!=null) {
+                       if (superclass != null) {
                                typesTolookat.add(superclass);
                        }
                        // Queue any interfaces not already checked:
                        ResolvedType[] superinterfaces = type.getDeclaredInterfaces();
-                       if (superinterfaces!=null) {
+                       if (superinterfaces != null) {
                                for (int i = 0; i < superinterfaces.length; i++) {
                                        ResolvedType interf = superinterfaces[i];
                                        if (!typesTolookat.contains(interf)) {
@@ -391,7 +391,6 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl
                return null;
        }
 
-       
        /**
         * return null if not found
         */
@@ -550,7 +549,7 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl
                        ResolvedPointcutDefinition f = (ResolvedPointcutDefinition) i.next();
                        // the resolvedpointcutdefinition can be null if there are other problems that
                        // prevented its resolution
-                       if (f!=null && name.equals(f.getName())) {
+                       if (f != null && name.equals(f.getName())) {
                                return f;
                        }
                }
@@ -650,6 +649,10 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl
                return acc;
        }
 
+       public void addParent(ResolvedType newParent) {
+               // Nothing to do for anything except a ReferenceType
+       }
+
        protected boolean doesNotExposeShadowMungers() {
                return false;
        }
@@ -1875,7 +1878,7 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl
                        // System.err.println("looking at: " + inherited + " in " + this);
                        // System.err.println("            " + inherited.isAbstract() +
                        // " in " + this.isAbstract());
-                       if (inherited!=null && inherited.isAbstract()) {
+                       if (inherited != null && inherited.isAbstract()) {
                                if (!this.isAbstract()) {
                                        getWorld().showMessage(IMessage.ERROR,
                                                        WeaverMessages.format(WeaverMessages.POINCUT_NOT_CONCRETE, inherited, this.getName()),
@@ -2243,4 +2246,13 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl
                return binaryPath;
        }
 
+       /**
+        * Undo any temporary modifications to the type (for example it may be holding annotations temporarily whilst some matching is
+        * occurring - These annotations will be added properly during weaving but sometimes for type completion they need to be held
+        * here for a while).
+        */
+       public void ensureConsistent() {
+               // Nothing to do for anything except a ReferenceType
+       }
+
 }
index 2762fa74826da5a1a7c17cb50dc4551b37b10ad3..2d599f0ef59727622a7b0085d98e384dc8f876c4 100644 (file)
@@ -18,108 +18,105 @@ import java.io.IOException;
  * Represents a type variable with bounds
  */
 public class TypeVariable {
-       
+
        public static final TypeVariable[] NONE = new TypeVariable[0];
        /**
-        * whether or not the bounds of this type variable have been 
-        * resolved
+        * whether or not the bounds of this type variable have been resolved
         */
        private boolean isResolved = false;
-       
-       
+
        private boolean beingResolved = false;
-       
+
        /**
         * the name of the type variable as recorded in the generic signature
         */
        private String name;
-       
+
        private int rank;
 
-    // It would be nice to push this field onto the TypeVariableDeclaringElement
-    // interface (a getKind()) but at the moment we don't always guarantee
-    // to set the declaring element (eclipse seems to utilise the knowledge of
-    // what declared the type variable, but we dont yet...)
+       // It would be nice to push this field onto the TypeVariableDeclaringElement
+       // interface (a getKind()) but at the moment we don't always guarantee
+       // to set the declaring element (eclipse seems to utilise the knowledge of
+       // what declared the type variable, but we dont yet...)
        /**
         * What kind of element declared this type variable?
         */
        private int declaringElementKind = UNKNOWN;
        public static final int UNKNOWN = -1;
-       public static final int METHOD  = 1;
-       public static final int TYPE    = 2;
+       public static final int METHOD = 1;
+       public static final int TYPE = 2;
        private TypeVariableDeclaringElement declaringElement;
-       
+
        /**
-        * the upper bound of the type variable (default to Object).
-        * From the extends clause, eg. T extends Number.
+        * the upper bound of the type variable (default to Object). From the extends clause, eg. T extends Number.
         */
        private UnresolvedType upperBound = UnresolvedType.OBJECT;
-       
+
        /**
-        * any additional upper (interface) bounds.
-        * from the extends clause, e.g. T extends Number & Comparable
+        * any additional upper (interface) bounds. from the extends clause, e.g. T extends Number & Comparable
         */
        private UnresolvedType[] additionalInterfaceBounds = new UnresolvedType[0];
-       
+
        /**
-        * any lower bound.
-        * from the super clause, eg T super Foo
+        * any lower bound. from the super clause, eg T super Foo
         */
        private UnresolvedType lowerBound = null;
-       
+
        public TypeVariable(String aName) {
                this.name = aName;
        }
-       
+
        public TypeVariable(String aName, UnresolvedType anUpperBound) {
                this(aName);
                this.upperBound = anUpperBound;
        }
-       
-       public TypeVariable(String aName, UnresolvedType anUpperBound, 
-                                               UnresolvedType[] someAdditionalInterfaceBounds) {
-               this(aName,anUpperBound);
+
+       public TypeVariable(String aName, UnresolvedType anUpperBound, UnresolvedType[] someAdditionalInterfaceBounds) {
+               this(aName, anUpperBound);
                this.additionalInterfaceBounds = someAdditionalInterfaceBounds;
        }
-       
-       public TypeVariable(String aName, UnresolvedType anUpperBound, 
-            UnresolvedType[] someAdditionalInterfaceBounds, UnresolvedType aLowerBound) {
-               this(aName,anUpperBound,someAdditionalInterfaceBounds);
+
+       public TypeVariable(String aName, UnresolvedType anUpperBound, UnresolvedType[] someAdditionalInterfaceBounds,
+                       UnresolvedType aLowerBound) {
+               this(aName, anUpperBound, someAdditionalInterfaceBounds);
                this.lowerBound = aLowerBound;
        }
-       
-       // First bound is the first 'real' bound, this can be an interface if 
+
+       // First bound is the first 'real' bound, this can be an interface if
        // no class bound was specified (it will default to object)
        public UnresolvedType getFirstBound() {
-               if (upperBound.equals(UnresolvedType.OBJECT) && additionalInterfaceBounds!=null && additionalInterfaceBounds.length!=0) {
+               if (upperBound.equals(UnresolvedType.OBJECT) && additionalInterfaceBounds != null && additionalInterfaceBounds.length != 0) {
                        return additionalInterfaceBounds[0];
                }
                return upperBound;
        }
-       
+
        public UnresolvedType getUpperBound() {
                return upperBound;
        }
-       
+
        public UnresolvedType[] getAdditionalInterfaceBounds() {
                return additionalInterfaceBounds;
        }
-       
+
        public UnresolvedType getLowerBound() {
                return lowerBound;
        }
-       
+
        public String getName() {
                return name;
        }
-       
+
        /**
         * resolve all the bounds of this type variable
         */
        public TypeVariable resolve(World inSomeWorld) {
-               if (beingResolved) { return this; } // avoid spiral of death
+               if (beingResolved) {
+                       return this;
+               } // avoid spiral of death
                beingResolved = true;
-               if (isResolved) return this;
+               if (isResolved)
+                       return this;
 
                TypeVariable resolvedTVar = null;
 
@@ -140,33 +137,35 @@ public class TypeVariable {
                                ResolvedMember declaring = (ResolvedMember) declaringElement;
                                TypeVariable[] tvrts = declaring.getTypeVariables();
                                for (int i = 0; i < tvrts.length; i++) {
-                                       if (tvrts[i].getName().equals(getName())) resolvedTVar = tvrts[i];
-//                                     if (tvrts[i].isTypeVariableReference()) {
-//                                             TypeVariableReferenceType tvrt = (TypeVariableReferenceType) tvrts[i].resolve(inSomeWorld);
-//                                             TypeVariable tv = tvrt.getTypeVariable();
-//                                             if (tv.getName().equals(getName())) resolvedTVar = tv;
-//                                     }
-                               }                       
+                                       if (tvrts[i].getName().equals(getName()))
+                                               resolvedTVar = tvrts[i];
+                                       // if (tvrts[i].isTypeVariableReference()) {
+                                       // TypeVariableReferenceType tvrt = (TypeVariableReferenceType) tvrts[i].resolve(inSomeWorld);
+                                       // TypeVariable tv = tvrt.getTypeVariable();
+                                       // if (tv.getName().equals(getName())) resolvedTVar = tv;
+                                       // }
+                               }
                        }
-                       
+
                        if (resolvedTVar == null) {
                                // well, this is bad... we didn't find the type variable on the member
                                // could be a separate compilation issue...
                                // should issue message, this is a workaround to get us going...
-                               resolvedTVar = this;                            
+                               resolvedTVar = this;
                        }
                } else {
                        resolvedTVar = this;
                }
-                               
+
                upperBound = resolvedTVar.upperBound;
                lowerBound = resolvedTVar.lowerBound;
                additionalInterfaceBounds = resolvedTVar.additionalInterfaceBounds;
-               
+
                upperBound = upperBound.resolve(inSomeWorld);
-               if (lowerBound != null) lowerBound = lowerBound.resolve(inSomeWorld);
-               
-               if (additionalInterfaceBounds!=null) {
+               if (lowerBound != null)
+                       lowerBound = lowerBound.resolve(inSomeWorld);
+
+               if (additionalInterfaceBounds != null) {
                        for (int i = 0; i < additionalInterfaceBounds.length; i++) {
                                additionalInterfaceBounds[i] = additionalInterfaceBounds[i].resolve(inSomeWorld);
                        }
@@ -175,63 +174,63 @@ public class TypeVariable {
                beingResolved = false;
                return this;
        }
-       
+
        /**
-        * answer true if the given type satisfies all of the bound constraints of this
-        * type variable.
-        * If type variable has not been resolved then throws IllegalStateException
+        * answer true if the given type satisfies all of the bound constraints of this type variable. If type variable has not been
+        * resolved then throws IllegalStateException
         */
        public boolean canBeBoundTo(ResolvedType aCandidateType) {
-               if (!isResolved) throw new IllegalStateException("Can't answer binding questions prior to resolving");
-               
+               if (!isResolved)
+                       throw new IllegalStateException("Can't answer binding questions prior to resolving");
+
                // wildcard can accept any binding
-               if (aCandidateType.isGenericWildcard()) {  // AMC - need a more robust test!
+               if (aCandidateType.isGenericWildcard()) { // AMC - need a more robust test!
                        return true;
                }
-               
+
                // otherwise can be bound iff...
-               //  aCandidateType is a subtype of upperBound
-               if (!isASubtypeOf(upperBound,aCandidateType)) {
+               // aCandidateType is a subtype of upperBound
+               if (!isASubtypeOf(upperBound, aCandidateType)) {
                        return false;
                }
-               //  aCandidateType is a subtype of all additionalInterfaceBounds
+               // aCandidateType is a subtype of all additionalInterfaceBounds
                for (int i = 0; i < additionalInterfaceBounds.length; i++) {
                        if (!isASubtypeOf(additionalInterfaceBounds[i], aCandidateType)) {
                                return false;
                        }
                }
-               //  lowerBound is a subtype of aCandidateType
-               if ((lowerBound != null) && (!isASubtypeOf(aCandidateType,lowerBound))) {
+               // lowerBound is a subtype of aCandidateType
+               if ((lowerBound != null) && (!isASubtypeOf(aCandidateType, lowerBound))) {
                        return false;
                }
                return true;
        }
-       
+
        private boolean isASubtypeOf(UnresolvedType candidateSuperType, UnresolvedType candidateSubType) {
                ResolvedType superType = (ResolvedType) candidateSuperType;
                ResolvedType subType = (ResolvedType) candidateSubType;
                return superType.isAssignableFrom(subType);
        }
 
-       // only used when resolving 
+       // only used when resolving
        public void setUpperBound(UnresolvedType aTypeX) {
                this.upperBound = aTypeX;
        }
-       
+
        // only used when resolving
        public void setLowerBound(UnresolvedType aTypeX) {
                this.lowerBound = aTypeX;
        }
-       
+
        // only used when resolving
        public void setAdditionalInterfaceBounds(UnresolvedType[] someTypeXs) {
                this.additionalInterfaceBounds = someTypeXs;
        }
-       
+
        public String toDebugString() {
                return getDisplayName();
        }
-       
+
        public String getDisplayName() {
                StringBuffer ret = new StringBuffer();
                ret.append(name);
@@ -253,54 +252,53 @@ public class TypeVariable {
                }
                return ret.toString();
        }
-       
+
        // good enough approximation
        public String toString() {
                return "TypeVar " + getDisplayName();
        }
-       
+
        /**
-        * Return complete signature, e.g. "T extends Number" would return "T:Ljava/lang/Number;"
-        * note: MAY INCLUDE P types if bounds are parameterized types
+        * Return complete signature, e.g. "T extends Number" would return "T:Ljava/lang/Number;" note: MAY INCLUDE P types if bounds
+        * are parameterized types
         */
        public String getSignature() {
-               StringBuffer sb = new StringBuffer();
-               sb.append(name);
+               StringBuffer sb = new StringBuffer();
+               sb.append(name);
                sb.append(":");
-               sb.append(upperBound.getSignature());
-               if (additionalInterfaceBounds!=null && additionalInterfaceBounds.length!=0) {
-                       sb.append(":");
-                       for (int i = 0; i < additionalInterfaceBounds.length; i++) {
+               sb.append(upperBound.getSignature());
+               if (additionalInterfaceBounds != null && additionalInterfaceBounds.length != 0) {
+                       sb.append(":");
+                       for (int i = 0; i < additionalInterfaceBounds.length; i++) {
                                UnresolvedType iBound = additionalInterfaceBounds[i];
                                sb.append(iBound.getSignature());
                        }
-               }
+               }
                return sb.toString();
        }
-       
+
        /**
         * @return signature for inclusion in an attribute, there must be no 'P' in it signatures
         */
        public String getSignatureForAttribute() {
-               StringBuffer sb = new StringBuffer();
-               sb.append(name);
+               StringBuffer sb = new StringBuffer();
+               sb.append(name);
                sb.append(":");
-               sb.append(((ResolvedType)upperBound).getSignatureForAttribute());
-               if (additionalInterfaceBounds!=null && additionalInterfaceBounds.length!=0) {
-                       sb.append(":");
-                       for (int i = 0; i < additionalInterfaceBounds.length; i++) {
-                               ResolvedType iBound = (ResolvedType)additionalInterfaceBounds[i];
+               sb.append(((ResolvedType) upperBound).getSignatureForAttribute());
+               if (additionalInterfaceBounds != null && additionalInterfaceBounds.length != 0) {
+                       sb.append(":");
+                       for (int i = 0; i < additionalInterfaceBounds.length; i++) {
+                               ResolvedType iBound = (ResolvedType) additionalInterfaceBounds[i];
                                sb.append(iBound.getSignatureForAttribute());
                        }
-               }
+               }
                return sb.toString();
        }
 
-       
        public void setRank(int rank) {
-               this.rank=rank;
+               this.rank = rank;
        }
-       
+
        public int getRank() {
                return rank;
        }
@@ -313,25 +311,25 @@ public class TypeVariable {
                        this.declaringElementKind = METHOD;
                }
        }
-       
+
        public TypeVariableDeclaringElement getDeclaringElement() {
                return declaringElement;
        }
-       
+
        public void setDeclaringElementKind(int kind) {
                this.declaringElementKind = kind;
        }
-       
+
        public int getDeclaringElementKind() {
-//             if (declaringElementKind==UNKNOWN) throw new RuntimeException("Dont know declarer of this tvar : "+this);
+               // if (declaringElementKind==UNKNOWN) throw new RuntimeException("Dont know declarer of this tvar : "+this);
                return declaringElementKind;
        }
-       
+
        public void write(DataOutputStream s) throws IOException {
-       // name, upperbound, additionalInterfaceBounds, lowerbound
+               // name, upperbound, additionalInterfaceBounds, lowerbound
                s.writeUTF(name);
                upperBound.write(s);
-               if (additionalInterfaceBounds==null || additionalInterfaceBounds.length==0) {
+               if (additionalInterfaceBounds == null || additionalInterfaceBounds.length == 0) {
                        s.writeInt(0);
                } else {
                        s.writeInt(additionalInterfaceBounds.length);
@@ -341,30 +339,31 @@ public class TypeVariable {
                        }
                }
        }
-       
+
        public static TypeVariable read(VersionedDataInputStream s) throws IOException {
-       
-               //if (s.getMajorVersion()>=AjAttribute.WeaverVersionInfo.WEAVER_VERSION_MAJOR_AJ150) {
-                       
+
+               // if (s.getMajorVersion()>=AjAttribute.WeaverVersionInfo.WEAVER_VERSION_MAJOR_AJ150) {
+
                String name = s.readUTF();
                UnresolvedType ubound = UnresolvedType.read(s);
                int iboundcount = s.readInt();
                UnresolvedType[] ibounds = UnresolvedType.NONE;
-               if (iboundcount>0) {
+               if (iboundcount > 0) {
                        ibounds = new UnresolvedType[iboundcount];
-                       for (int i=0; i<iboundcount; i++) {
+                       for (int i = 0; i < iboundcount; i++) {
                                ibounds[i] = UnresolvedType.read(s);
                        }
                }
-               
-               TypeVariable newVariable = new TypeVariable(name,ubound,ibounds);
-               return newVariable;             
-    }
+
+               TypeVariable newVariable = new TypeVariable(name, ubound, ibounds);
+               return newVariable;
+       }
 
        public String getGenericSignature() {
-               return "T"+name+";";
-//             return "T"+getSignature();
+               return "T" + name + ";";
+               // return "T"+getSignature();
        }
+
        public String getErasureSignature() {
                return getFirstBound().getErasureSignature();
        }
index b96611a0544d70e7c9326beec12ceb26480678ae..59d9bb3cf9a0bdbcd2d3e7e0e0b93dc096f6c737 100644 (file)
@@ -79,27 +79,11 @@ public class ReflectionBasedReferenceTypeDelegate implements ReferenceTypeDelega
        public ReferenceType buildGenericType() {
                throw new UnsupportedOperationException("Shouldn't be asking for generic type at 1.4 source level or lower");
        }
-
-       /*
-        * (non-Javadoc)
-        * 
-        * @see org.aspectj.weaver.ReferenceTypeDelegate#addAnnotation(org.aspectj.weaver .AnnotationX)
-        */
-       public void addAnnotation(AnnotationAJ annotationX) {
-               throw new UnsupportedOperationException("Cannot add an annotation to a reflection based delegate");
-       }
-
-       /*
-        * (non-Javadoc)
-        * 
-        * @see org.aspectj.weaver.ReferenceTypeDelegate#isAspect()
-        */
        public boolean isAspect() {
                // we could do better than this in Java 5 by looking at the annotations
                // on the type...
                return false;
        }
-
        /*
         * (non-Javadoc)
         * 
@@ -110,46 +94,27 @@ public class ReflectionBasedReferenceTypeDelegate implements ReferenceTypeDelega
                // on the type...
                return false;
        }
-
-       /*
-        * (non-Javadoc)
-        * 
-        * @see org.aspectj.weaver.ReferenceTypeDelegate#isInterface()
-        */
+       
        public boolean isInterface() {
                return this.myClass.isInterface();
        }
-
-       /*
-        * (non-Javadoc)
-        * 
-        * @see org.aspectj.weaver.ReferenceTypeDelegate#isEnum()
-        */
        public boolean isEnum() {
                // cant be an enum in Java 1.4 or prior
                return false;
        }
-
        /*
         * (non-Javadoc)
         * 
-        * @see org.aspectj.weaver.ReferenceTypeDelegate#isAnnotation()
+        * @see org.aspectj.weaver.ReferenceTypeDelegate#isAnnotationWithRuntimeRetention ()
         */
-       public boolean isAnnotation() {
+       public boolean isAnnotationWithRuntimeRetention() {
                // cant be an annotation in Java 1.4 or prior
                return false;
        }
-
-       /*
-        * (non-Javadoc)
-        * 
-        * @see org.aspectj.weaver.ReferenceTypeDelegate#isAnnotationWithRuntimeRetention ()
-        */
-       public boolean isAnnotationWithRuntimeRetention() {
+public boolean isAnnotation() {
                // cant be an annotation in Java 1.4 or prior
                return false;
        }
-
        public String getRetentionPolicy() {
                // cant be an annotation in Java 1.4 or prior
                return null;
@@ -162,12 +127,6 @@ public class ReflectionBasedReferenceTypeDelegate implements ReferenceTypeDelega
        public AnnotationTargetKind[] getAnnotationTargetKinds() {
                return null;
        }
-
-       /*
-        * (non-Javadoc)
-        * 
-        * @see org.aspectj.weaver.ReferenceTypeDelegate#isClass()
-        */
        public boolean isClass() {
                return !this.myClass.isInterface() && !this.myClass.isPrimitive() && !this.myClass.isArray();
        }
@@ -418,11 +377,6 @@ public class ReflectionBasedReferenceTypeDelegate implements ReferenceTypeDelega
                return null;
        }
 
-       public void ensureDelegateConsistent() {
-               // Nothing to do - a reflection based delegate can't become
-               // inconsistent...
-       }
-
        public ReflectionBasedResolvedMemberImpl createResolvedMemberFor(Member aMember) {
                return null;
        }