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)
*/
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) {
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;
}
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() {
}
public boolean isExtends() {
- return (isExtends && !getUpperBound().getSignature().equals(
- "Ljava/lang/Object;"));
+ return (isExtends && !getUpperBound().getSignature().equals("Ljava/lang/Object;"));
}
public boolean isSuper() {
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 '?'
}
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 {
}
} 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 {
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;
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();
}
return resolvedTypeX.getTypeVariables();
}
- public void ensureDelegateConsistent() {
- resolvedTypeX.getDelegate().ensureDelegateConsistent();
- }
-
}
}
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");
}
throw new UnsupportedOperationException("Not supported for GeneratedReferenceTypeDelegate");
}
- public void ensureDelegateConsistent() {
- throw new UnsupportedOperationException("Not supported for GeneratedReferenceTypeDelegate");
- }
-
}
\ No newline at end of file
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);
}
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++) {
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];
}
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++) {
}
return parameterizedInterfaces;
}
- return delegate.getDeclaredInterfaces();
+ return delegateInterfaces;
}
/**
}
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);
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
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();
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();
public boolean isNested();
- public boolean isExposedToWeaver();
-
public boolean hasAnnotation(UnresolvedType ofType);
public AnnotationAJ[] getAnnotations();
public TypeVariable[] getTypeVariables();
+ public int getModifiers();
+
+ // aspect declaration related members
+ /**
+ * @return for an aspect declaration, return the
+ */
public PerClause getPerClause();
public Collection getDeclares();
public Collection getPrivilegedAccesses();
- public int getModifiers();
+ // end of aspect declaration related members
public ResolvedType getSuperclass();
public ReferenceType getResolvedTypeX();
+ // needs renaming isWeavable or removing from here
+ public boolean isExposedToWeaver();
+
public boolean doesNotExposeShadowMungers();
public ISourceContext getSourceContext();
* 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)) {
return null;
}
-
/**
* return null if not found
*/
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;
}
}
return acc;
}
+ public void addParent(ResolvedType newParent) {
+ // Nothing to do for anything except a ReferenceType
+ }
+
protected boolean doesNotExposeShadowMungers() {
return false;
}
// 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()),
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
+ }
+
}
* 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;
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);
}
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);
}
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;
}
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);
}
}
}
-
+
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();
}
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)
*
// 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;
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();
}
return null;
}
- public void ensureDelegateConsistent() {
- // Nothing to do - a reflection based delegate can't become
- // inconsistent...
- }
-
public ReflectionBasedResolvedMemberImpl createResolvedMemberFor(Member aMember) {
return null;
}