From: aclement Date: Tue, 20 Jan 2009 22:41:35 +0000 (+0000) Subject: 258510: promoted additional annotation/class/interface storage from delegate to refer... X-Git-Tag: pre268419~216 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3be58b7ad73775ef09701436e4457637b42da460;p=aspectj.git 258510: promoted additional annotation/class/interface storage from delegate to referencetype --- diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/BoundedReferenceType.java b/org.aspectj.matcher/src/org/aspectj/weaver/BoundedReferenceType.java index 1839d2c73..e983c4aeb 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/BoundedReferenceType.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/BoundedReferenceType.java @@ -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(); - } - } } diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/GeneratedReferenceTypeDelegate.java b/org.aspectj.matcher/src/org/aspectj/weaver/GeneratedReferenceTypeDelegate.java index 88e8c8759..6461ef135 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/GeneratedReferenceTypeDelegate.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/GeneratedReferenceTypeDelegate.java @@ -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 diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/ReferenceType.java b/org.aspectj.matcher/src/org/aspectj/weaver/ReferenceType.java index 1eb06cc90..9757e441b 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/ReferenceType.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/ReferenceType.java @@ -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 diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/ReferenceTypeDelegate.java b/org.aspectj.matcher/src/org/aspectj/weaver/ReferenceTypeDelegate.java index ec9d83915..014e40b83 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/ReferenceTypeDelegate.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/ReferenceTypeDelegate.java @@ -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(); diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/ResolvedType.java b/org.aspectj.matcher/src/org/aspectj/weaver/ResolvedType.java index 118a1dc63..2b5fd8f4b 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/ResolvedType.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/ResolvedType.java @@ -335,39 +335,39 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl * described in JVM spec 2ed 5.4.3.3. Doesnt check ITDs. * *

- * 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=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