]> source.dussan.org Git - aspectj.git/commitdiff
fixes for 153490: mixing delegates. Refactored a *lot* of stuff - promoting duplicat...
authoraclement <aclement>
Wed, 13 Sep 2006 07:43:09 +0000 (07:43 +0000)
committeraclement <aclement>
Wed, 13 Sep 2006 07:43:09 +0000 (07:43 +0000)
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceType.java
weaver/src/org/aspectj/weaver/AbstractReferenceTypeDelegate.java
weaver/src/org/aspectj/weaver/BoundedReferenceType.java
weaver/src/org/aspectj/weaver/ReferenceType.java
weaver/src/org/aspectj/weaver/ReferenceTypeDelegate.java
weaver/src/org/aspectj/weaver/asm/AsmDelegate.java
weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java
weaver/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegate.java

index 8381f8834000e6c1b952df43e7ec3713bb96700e..179410bc4452ba75c78319fa91f1abe29ce6f571 100644 (file)
@@ -132,6 +132,11 @@ public class EclipseSourceType extends AbstractReferenceTypeDelegate {
        public boolean isNested() {
                return ((declaration.modifiers & ASTNode.IsMemberTypeMASK) != 0);
        }
+       
+       public ResolvedType getOuterClass() {
+               if (declaration.enclosingType==null) return null;
+               return eclipseWorld().fromEclipse(declaration.enclosingType.binding);
+       }
 
     public boolean isAnnotationStyleAspect() {
         if (declaration.annotations == null) {
index d0a2d0451278a731a04bde0b0ebb4290ae632225..305dad5d0fe05b401dc6ca3f7734d951cb29eb48 100644 (file)
@@ -19,6 +19,9 @@ import java.util.Comparator;
 import java.util.Iterator;
 import java.util.List;
 
+import org.aspectj.apache.bcel.classfile.GenericSignatureParser;
+import org.aspectj.apache.bcel.classfile.Signature;
+import org.aspectj.apache.bcel.classfile.Signature.ClassSignature;
 import org.aspectj.bridge.ISourceLocation;
 import org.aspectj.weaver.patterns.Declare;
 
@@ -30,6 +33,7 @@ public abstract class AbstractReferenceTypeDelegate implements ReferenceTypeDele
        protected boolean exposedToWeaver;
        protected ReferenceType resolvedTypeX;
        private ISourceContext sourceContext = SourceContextImpl.UNKNOWN_SOURCE_CONTEXT;
+       protected ClassSignature cachedGenericClassTypeSignature;
 
     public AbstractReferenceTypeDelegate(ReferenceType resolvedTypeX, boolean exposedToWeaver) {
         this.resolvedTypeX = resolvedTypeX;
@@ -268,5 +272,39 @@ public abstract class AbstractReferenceTypeDelegate implements ReferenceTypeDele
                this.sourceContext = isc;
        }
 
+       public Signature.ClassSignature getGenericClassTypeSignature() {
+               if (cachedGenericClassTypeSignature==null) {
+                       String sig = getDeclaredGenericSignature();
+                       if (sig!=null) {
+                               GenericSignatureParser parser = new GenericSignatureParser();
+                               cachedGenericClassTypeSignature = parser.parseAsClassSignature(sig);
+                       }
+               }
+               return cachedGenericClassTypeSignature;
+       }
+       
+       protected Signature.FormalTypeParameter[] getFormalTypeParametersFromOuterClass() {
+               List typeParameters = new ArrayList();
+               ReferenceType outer = (ReferenceType)getOuterClass();
+               ReferenceTypeDelegate outerDelegate = outer.getDelegate();
+               AbstractReferenceTypeDelegate outerObjectType = (AbstractReferenceTypeDelegate) outerDelegate;
+               if (outerObjectType.isNested()) {
+                       Signature.FormalTypeParameter[] parentParams = outerObjectType.getFormalTypeParametersFromOuterClass();
+                       for (int i = 0; i < parentParams.length; i++) {
+                               typeParameters.add(parentParams[i]);
+                       }
+               }
+               Signature.ClassSignature outerSig = outerObjectType.getGenericClassTypeSignature();
+               if (outerSig != null) {
+                       for (int i = 0; i < outerSig.formalTypeParameters .length; i++) {
+                               typeParameters.add(outerSig.formalTypeParameters[i]);
+                       }
+               } 
+               
+               Signature.FormalTypeParameter[] ret = new Signature.FormalTypeParameter[typeParameters.size()];
+               typeParameters.toArray(ret);
+               return ret;
+       }
+
 
 }
\ No newline at end of file
index 2d0016d631c7377fbafbefc51009e02c83f90bb6..b1dbfe00f7aef2a0a8b0f6020bf82869a52fa1cc 100644 (file)
@@ -185,6 +185,10 @@ public class BoundedReferenceType extends ReferenceType {
                        return resolvedTypeX.isNested();
                }
                
+               public ResolvedType getOuterClass() {
+                       return resolvedTypeX.getOuterClass();
+               }
+               
                public String getRetentionPolicy() {
                        return resolvedTypeX.getRetentionPolicy();
                }
index c8a9ecef0ee64d1cb210673d0f3a84d002b3e0e6..812ac27861ba39a6644de1d32a3e49fff151eb6f 100644 (file)
@@ -172,11 +172,15 @@ public class ReferenceType extends ResolvedType {
     }
     
     public boolean isAnonymous() {
-               return delegate.isAnonymous();
+       return delegate.isAnonymous();
     }
     
     public boolean isNested() {
-               return delegate.isNested();
+       return delegate.isNested();
+    }
+    
+    public ResolvedType getOuterClass() {
+       return delegate.getOuterClass();
     }
     
     public String getRetentionPolicy() {
index c332f2ecae156ad77d93398935908ed911fcb287..e0853f1e52f093e2d6628f85329b116d99e4c70a 100644 (file)
@@ -66,5 +66,6 @@ public interface ReferenceTypeDelegate {
        public String getSourcefilename();
        
        public String getDeclaredGenericSignature();
+       public ResolvedType getOuterClass();
        
 }
\ No newline at end of file
index d73edc012cbf7be962461992d6e4ba042ce7505f..4403cd36c140eba9d333b51a6def4489e62c05cb 100644 (file)
@@ -21,6 +21,9 @@ import java.util.List;
 
 import org.aspectj.apache.bcel.classfile.GenericSignatureParser;
 import org.aspectj.apache.bcel.classfile.Signature;
+import org.aspectj.org.objectweb.asm.Attribute;
+import org.aspectj.org.objectweb.asm.ClassReader;
+import org.aspectj.org.objectweb.asm.Opcodes;
 import org.aspectj.weaver.AbstractReferenceTypeDelegate;
 import org.aspectj.weaver.AjAttribute;
 import org.aspectj.weaver.AnnotationAJ;
@@ -28,7 +31,6 @@ import org.aspectj.weaver.AnnotationTargetKind;
 import org.aspectj.weaver.AnnotationX;
 import org.aspectj.weaver.ISourceContext;
 import org.aspectj.weaver.ReferenceType;
-import org.aspectj.weaver.ReferenceTypeDelegate;
 import org.aspectj.weaver.ResolvedMember;
 import org.aspectj.weaver.ResolvedMemberImpl;
 import org.aspectj.weaver.ResolvedPointcutDefinition;
@@ -48,9 +50,6 @@ import org.aspectj.weaver.AjAttribute.WeaverVersionInfo;
 import org.aspectj.weaver.bcel.BcelGenericSignatureToTypeXConverter;
 import org.aspectj.weaver.bcel.BcelGenericSignatureToTypeXConverter.GenericSignatureFormatException;
 import org.aspectj.weaver.patterns.PerClause;
-import org.aspectj.org.objectweb.asm.Attribute;
-import org.aspectj.org.objectweb.asm.ClassReader;
-import org.aspectj.org.objectweb.asm.Opcodes;
 
 /**
  * A lightweight fast delegate that is an alternative to a BCEL delegate.
@@ -315,6 +314,7 @@ public class AsmDelegate extends AbstractReferenceTypeDelegate {
        public String getDeclaredGenericSignature() {
                return declaredSignature;
        }
+
        
        public Collection getTypeMungers() {
                if ((bitflag&DISCOVERED_TYPEMUNGERS)==0) {
@@ -449,7 +449,7 @@ public class AsmDelegate extends AbstractReferenceTypeDelegate {
        }
 
 
-       private ReferenceType getOuterClass() {
+       public ResolvedType getOuterClass() {
                if (!isNested()) throw new IllegalStateException("Can't get the outer class of a non-nested type");
                int lastDollar = getResolvedTypeX().getName().lastIndexOf('$');
                String superClassName = getResolvedTypeX().getName().substring(0,lastDollar);
@@ -457,36 +457,7 @@ public class AsmDelegate extends AbstractReferenceTypeDelegate {
                return (ReferenceType) outer.resolve(getResolvedTypeX().getWorld());
        }
        
-       private Signature.FormalTypeParameter[] getFormalTypeParametersFromOuterClass() {
-               List typeParameters = new ArrayList();
-               ReferenceType outer = getOuterClass();
-               ReferenceTypeDelegate outerDelegate = outer.getDelegate();
-               if (!(outerDelegate instanceof AsmDelegate)) {
-                       throw new IllegalStateException("How come we're in AsmObjectType resolving an inner type of something that is NOT a AsmObjectType??");
-               }
-               AsmDelegate outerObjectType = (AsmDelegate) outerDelegate;
-               if (outerObjectType.isNested()) {
-                       Signature.FormalTypeParameter[] parentParams = outerObjectType.getFormalTypeParametersFromOuterClass();
-                       for (int i = 0; i < parentParams.length; i++) {
-                               typeParameters.add(parentParams[i]);
-                       }
-               }
-                 GenericSignatureParser parser = new GenericSignatureParser();
-                 String sig = outerObjectType.getDeclaredGenericSignature();
-                 if (sig!=null) {
-                 Signature.ClassSignature outerSig = parser.parseAsClassSignature(sig);
-               if (outerSig != null) {
-                       for (int i = 0; i < outerSig.formalTypeParameters .length; i++) {
-                               typeParameters.add(outerSig.formalTypeParameters[i]);
-                       }
-               } 
-         }
-               
-               Signature.FormalTypeParameter[] ret = new Signature.FormalTypeParameter[typeParameters.size()];
-               typeParameters.toArray(ret);
-               return ret;
-       }
-       // ---
+
 
        public boolean isInterface() {
                return (classModifiers & Opcodes.ACC_INTERFACE)!=0;
index 6eefa568591be96041eab0cf0701fb69754e156e..6943339679ca1895042d91c7bfc6340a47a6c601 100644 (file)
@@ -26,7 +26,6 @@ import org.aspectj.apache.bcel.classfile.Field;
 import org.aspectj.apache.bcel.classfile.JavaClass;
 import org.aspectj.apache.bcel.classfile.Method;
 import org.aspectj.apache.bcel.classfile.Signature;
-import org.aspectj.apache.bcel.classfile.Signature.ClassSignature;
 import org.aspectj.apache.bcel.classfile.annotation.Annotation;
 import org.aspectj.apache.bcel.classfile.annotation.ArrayElementValue;
 import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePair;
@@ -39,7 +38,6 @@ import org.aspectj.weaver.AnnotationTargetKind;
 import org.aspectj.weaver.AnnotationX;
 import org.aspectj.weaver.BCException;
 import org.aspectj.weaver.ReferenceType;
-import org.aspectj.weaver.ReferenceTypeDelegate;
 import org.aspectj.weaver.ResolvedMember;
 import org.aspectj.weaver.ResolvedPointcutDefinition;
 import org.aspectj.weaver.ResolvedType;
@@ -86,7 +84,6 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
        private List declares = Collections.EMPTY_LIST;
 
        private Signature.FormalTypeParameter[] formalsForResolution = null;
-       private ClassSignature cachedGenericClassTypeSignature;
        private String declaredSignature = null;
        
 
@@ -162,7 +159,7 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
                modifiers           = javaClass.getAccessFlags();
                superclassName      = javaClass.getSuperclassName();
                className           = javaClass.getClassName();
-               cachedGenericClassTypeSignature = javaClass.getGenericClassTypeSignature();
+               cachedGenericClassTypeSignature = null;
     }
 
 
@@ -250,7 +247,7 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
        if (!isGeneric()) return TypeVariable.NONE;
        
        if (typeVars == null) {
-               Signature.ClassSignature classSig = cachedGenericClassTypeSignature;//javaClass.getGenericClassTypeSignature();
+               Signature.ClassSignature classSig = getGenericClassTypeSignature();//cachedGenericClassTypeSignature;//javaClass.getGenericClassTypeSignature();
                typeVars = new TypeVariable[classSig.formalTypeParameters.length];
                for (int i = 0; i < typeVars.length; i++) {
                                Signature.FormalTypeParameter ftp = classSig.formalTypeParameters[i];
@@ -656,10 +653,6 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
                return declaredSignature;
        }
        
-       Signature.ClassSignature getGenericClassTypeSignature() {
-               return cachedGenericClassTypeSignature;
-       }
-       
                
        private void ensureGenericSignatureUnpacked() {
                if ((bitflag&UNPACKED_GENERIC_SIGNATURE)!=0) return;
@@ -668,7 +661,7 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
                Signature.ClassSignature cSig = getGenericClassTypeSignature();
                if (cSig != null) {
                        formalsForResolution = cSig.formalTypeParameters;
-                       if (isNestedClass()) {
+                       if (isNested()) {
                                // we have to find any type variables from the outer type before proceeding with resolution.
                                Signature.FormalTypeParameter[] extraFormals = getFormalTypeParametersFromOuterClass();
                                if (extraFormals.length > 0) {
@@ -743,43 +736,15 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
                }
        }
        
-       private boolean isNestedClass() {
-               return className.indexOf('$') != -1;
-       }
        
-       private ReferenceType getOuterClass() {
-               if (!isNestedClass()) throw new IllegalStateException("Can't get the outer class of a non-nested type");
+       public ResolvedType getOuterClass() {
+               if (!isNested()) throw new IllegalStateException("Can't get the outer class of a non-nested type");
                int lastDollar = className.lastIndexOf('$');
                String superClassName = className.substring(0,lastDollar);
                UnresolvedType outer = UnresolvedType.forName(superClassName);
                return (ReferenceType) outer.resolve(getResolvedTypeX().getWorld());
        }
        
-       private Signature.FormalTypeParameter[] getFormalTypeParametersFromOuterClass() {
-               List typeParameters = new ArrayList();
-               ReferenceType outer = getOuterClass();
-               ReferenceTypeDelegate outerDelegate = outer.getDelegate();
-               if (!(outerDelegate instanceof BcelObjectType)) {
-                       throw new IllegalStateException("How come we're in BcelObjectType resolving an inner type of something that is NOT a BcelObjectType??");
-               }
-               BcelObjectType outerObjectType = (BcelObjectType) outerDelegate;
-               if (outerObjectType.isNestedClass()) {
-                       Signature.FormalTypeParameter[] parentParams = outerObjectType.getFormalTypeParametersFromOuterClass();
-                       for (int i = 0; i < parentParams.length; i++) {
-                               typeParameters.add(parentParams[i]);
-                       }
-               }
-               Signature.ClassSignature outerSig = outerObjectType.getGenericClassTypeSignature();
-               if (outerSig != null) {
-                       for (int i = 0; i < outerSig.formalTypeParameters .length; i++) {
-                               typeParameters.add(outerSig.formalTypeParameters[i]);
-                       }
-               } 
-               
-               Signature.FormalTypeParameter[] ret = new Signature.FormalTypeParameter[typeParameters.size()];
-               typeParameters.toArray(ret);
-               return ret;
-       }
        
        private void ensureGenericInfoProcessed() { 
                if ((bitflag & DISCOVERED_DECLARED_SIGNATURE)!=0) return;
index bc0ca7bfd0ed5dff8fa79b9a7417338f24d9a322..9a500a17359c98fb9421e00059fddd0cad924f78 100644 (file)
@@ -170,6 +170,12 @@ public class ReflectionBasedReferenceTypeDelegate implements ReferenceTypeDelega
 //             boolean member = this.myClass.isMemberClass();
 //             return member;
        }
+       
+       public ResolvedType getOuterClass() {
+               // FIXME getEnclosingClass() is Java5 ... dammit
+//             return ReflectionBasedReferenceTypeDelegateFactory.resolveTypeInWorld(myClass.getEnclosingClass(),world);
+               return null;
+       }
 
        /* (non-Javadoc)
         * @see org.aspectj.weaver.ReferenceTypeDelegate#isExposedToWeaver()