diff options
author | aclement <aclement> | 2006-09-13 07:43:09 +0000 |
---|---|---|
committer | aclement <aclement> | 2006-09-13 07:43:09 +0000 |
commit | b49e8cae5b2473c7285c29f3ff33a621513ebbd5 (patch) | |
tree | 0e731f76002faf2ad889b7376b519ab19ff57cbe /weaver | |
parent | 8e14546e33d64d086865b8224806fce52f75f866 (diff) | |
download | aspectj-b49e8cae5b2473c7285c29f3ff33a621513ebbd5.tar.gz aspectj-b49e8cae5b2473c7285c29f3ff33a621513ebbd5.zip |
fixes for 153490: mixing delegates. Refactored a *lot* of stuff - promoting duplicate code up from AsmDelegate/BcelObjectType up to AbstractReferenceTypeDelegate and higher.
Diffstat (limited to 'weaver')
7 files changed, 66 insertions, 77 deletions
diff --git a/weaver/src/org/aspectj/weaver/AbstractReferenceTypeDelegate.java b/weaver/src/org/aspectj/weaver/AbstractReferenceTypeDelegate.java index d0a2d0451..305dad5d0 100644 --- a/weaver/src/org/aspectj/weaver/AbstractReferenceTypeDelegate.java +++ b/weaver/src/org/aspectj/weaver/AbstractReferenceTypeDelegate.java @@ -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 diff --git a/weaver/src/org/aspectj/weaver/BoundedReferenceType.java b/weaver/src/org/aspectj/weaver/BoundedReferenceType.java index 2d0016d63..b1dbfe00f 100644 --- a/weaver/src/org/aspectj/weaver/BoundedReferenceType.java +++ b/weaver/src/org/aspectj/weaver/BoundedReferenceType.java @@ -185,6 +185,10 @@ public class BoundedReferenceType extends ReferenceType { return resolvedTypeX.isNested(); } + public ResolvedType getOuterClass() { + return resolvedTypeX.getOuterClass(); + } + public String getRetentionPolicy() { return resolvedTypeX.getRetentionPolicy(); } diff --git a/weaver/src/org/aspectj/weaver/ReferenceType.java b/weaver/src/org/aspectj/weaver/ReferenceType.java index c8a9ecef0..812ac2786 100644 --- a/weaver/src/org/aspectj/weaver/ReferenceType.java +++ b/weaver/src/org/aspectj/weaver/ReferenceType.java @@ -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() { diff --git a/weaver/src/org/aspectj/weaver/ReferenceTypeDelegate.java b/weaver/src/org/aspectj/weaver/ReferenceTypeDelegate.java index c332f2eca..e0853f1e5 100644 --- a/weaver/src/org/aspectj/weaver/ReferenceTypeDelegate.java +++ b/weaver/src/org/aspectj/weaver/ReferenceTypeDelegate.java @@ -66,5 +66,6 @@ public interface ReferenceTypeDelegate { public String getSourcefilename(); public String getDeclaredGenericSignature(); + public ResolvedType getOuterClass(); }
\ No newline at end of file diff --git a/weaver/src/org/aspectj/weaver/asm/AsmDelegate.java b/weaver/src/org/aspectj/weaver/asm/AsmDelegate.java index d73edc012..4403cd36c 100644 --- a/weaver/src/org/aspectj/weaver/asm/AsmDelegate.java +++ b/weaver/src/org/aspectj/weaver/asm/AsmDelegate.java @@ -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; diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java b/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java index 6eefa5685..694333967 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java @@ -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; diff --git a/weaver/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegate.java b/weaver/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegate.java index bc0ca7bfd..9a500a173 100644 --- a/weaver/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegate.java +++ b/weaver/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegate.java @@ -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() |