*/
public class JoinPointSignature implements ResolvedMember {
+ public static final JoinPointSignature[] EMPTY_ARRAY = new JoinPointSignature[0];
+
private ResolvedMember realMember;
private ResolvedType substituteDeclaringType;
}
public ResolvedMemberImpl parameterizedWith(UnresolvedType[] typeParameters, ResolvedType newDeclaringType,
- boolean isParameterized, List aliases) {
+ boolean isParameterized, List<String> aliases) {
return realMember.parameterizedWith(typeParameters, newDeclaringType, isParameterized, aliases);
}
return realMember.resolve(world);
}
- public int compareTo(Object other) {
+ public int compareTo(Member other) {
return realMember.compareTo(other);
}
/* *******************************************************************
- * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
- * 2005 Contributors
+ * Copyright (c) 2002-2010
* All rights reserved.
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * PARC initial implementation
- * AMC extracted as interface
* ******************************************************************/
package org.aspectj.weaver;
import java.util.Collection;
/**
- * Abstract representation of a member within a type.
+ * Abstract representation of a member (field/constructor/method) within a type.
+ *
+ * @author PARC
+ * @author Adrian Colyer
+ * @author Andy Clement
*/
-public interface Member extends Comparable {
+public interface Member extends Comparable<Member> {
public static final Member[] NONE = new Member[0];
-
+
public static final MemberKind METHOD = new MemberKind("METHOD", 1);
public static final MemberKind FIELD = new MemberKind("FIELD", 2);
public static final MemberKind CONSTRUCTOR = new MemberKind("CONSTRUCTOR", 3);
public UnresolvedType getDeclaringType();
public UnresolvedType[] getParameterTypes();
+
public UnresolvedType[] getGenericParameterTypes();
public UnresolvedType getType();
+
public UnresolvedType getReturnType();
+
public UnresolvedType getGenericReturnType();
/**
public ResolvedMember resolve(World world);
- public int compareTo(Object other);
+ public int compareTo(Member other);
}
\ No newline at end of file
private static Object[] signatureToTypes(String sig) {
boolean hasParameters = sig.charAt(1) != ')';
if (hasParameters) {
- List l = new ArrayList();
+ List<UnresolvedType> l = new ArrayList<UnresolvedType>();
int i = 1;
boolean hasAnyAnglies = sig.indexOf('<') != -1;
while (true) {
l.add(UnresolvedType.forSignature(sig.substring(start, i)));
}
}
- UnresolvedType[] paramTypes = (UnresolvedType[]) l.toArray(new UnresolvedType[l.size()]);
+ UnresolvedType[] paramTypes = l.toArray(new UnresolvedType[l.size()]);
UnresolvedType returnType = UnresolvedType.forSignature(sig.substring(i + 1, sig.length()));
return new Object[] { returnType, paramTypes };
} else {
return hashCode;
}
- public int compareTo(Object other) {
- Member o = (Member) other;
+ public int compareTo(Member other) {
+ Member o = other;
int i = getName().compareTo(o.getName());
if (i != 0) {
return i;
return b;
}
- private boolean walkUpStatic(Collection acc, ResolvedType curr) {
+ private boolean walkUpStatic(Collection<ResolvedType> acc, ResolvedType curr) {
if (curr.lookupMemberNoSupers(this) != null) {
acc.add(curr);
return true;
} else {
boolean b = false;
- for (Iterator i = curr.getDirectSupertypes(); i.hasNext();) {
- b |= walkUpStatic(acc, (ResolvedType) i.next());
+ for (Iterator<ResolvedType> i = curr.getDirectSupertypes(); i.hasNext();) {
+ b |= walkUpStatic(acc, i.next());
}
if (!b && curr.isParameterizedType()) {
b = walkUpStatic(acc, curr.getGenericType());
public boolean equalsApartFromDeclaringType(Object other);
// return a resolved member in which all type variables in the signature of
- // this
- // member have been replaced with the given bindings.
- // the isParameterized flag tells us whether we are creating a raw type
+ // this member have been replaced with the given bindings. the isParameterized flag tells us whether we are creating a raw type
// version or not
// if isParameterized List<T> will turn into List<String> (for example),
// but if !isParameterized List<T> will turn into List.
// this is used for processing ITDs that share type variables with their
// target generic type
public ResolvedMemberImpl parameterizedWith(UnresolvedType[] typeParameters, ResolvedType newDeclaringType,
- boolean isParameterized, List aliases);
+ boolean isParameterized, List<String> aliases);
public void setTypeVariables(TypeVariable[] types);
public void evictWeavingState();
- public ResolvedMember parameterizedWith(Map m, World w);
+ public ResolvedMember parameterizedWith(Map<String, UnresolvedType> m, World w);
public boolean isDefaultConstructor();
/* *******************************************************************
- * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
+ * Copyright (c) 2002-2010 Contributors
* All rights reserved.
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * PARC initial implementation
* ******************************************************************/
-
package org.aspectj.weaver;
import java.io.DataOutputStream;
import org.aspectj.bridge.ISourceLocation;
/**
- * This is the declared member, i.e. it will always correspond to an actual method/... declaration
+ * Represent a resolved member. Components of it are expected to exist. This member will correspond to a real member *unless* it is
+ * being used to represent the effect of an ITD.
+ *
+ * @author PARC
+ * @author Andy Clement
*/
public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, AnnotatedElement, TypeVariableDeclaringElement,
ResolvedMember {
private String[] parameterNames = null;
protected UnresolvedType[] checkedExceptions = UnresolvedType.NONE;
+
/**
* if this member is a parameterized version of a member in a generic type, then this field holds a reference to the member we
* parameterize.
*/
protected ResolvedMember backingGenericMember = null;
- protected Set<ResolvedType> annotationTypes = null;
+ protected AnnotationAJ[] annotations = null;
+ protected ResolvedType[] annotationTypes = null;
+ protected AnnotationAJ[][] parameterAnnotations = null;
protected ResolvedType[][] parameterAnnotationTypes = null;
// Some members are 'created' to represent other things (for example ITDs).
- // These
- // members have their annotations stored elsewhere, and this flag indicates
- // that is
- // the case. It is up to the caller to work out where that is!
+ // These members have their annotations stored elsewhere, and this flag indicates
+ // that is the case. It is up to the caller to work out where that is!
// Once determined the caller may choose to stash the annotations in this
// member...
- private boolean isAnnotatedElsewhere = false; // this field is not
- // serialized.
+ private boolean isAnnotatedElsewhere = false;
private boolean isAjSynthetic = false;
// generic methods have type variables
ResolvedType originalDeclaringType = joinPointSignature.getDeclaringType().resolve(inAWorld);
ResolvedMemberImpl firstDefiningMember = (ResolvedMemberImpl) joinPointSignature.resolve(inAWorld);
if (firstDefiningMember == null) {
- return new JoinPointSignature[0];
+ return JoinPointSignature.EMPTY_ARRAY;
}
// declaringType can be unresolved if we matched a synthetic member
// generated by Aj...
ResolvedType firstDefiningType = firstDefiningMember.getDeclaringType().resolve(inAWorld);
if (firstDefiningType != originalDeclaringType) {
if (joinPointSignature.getKind() == Member.CONSTRUCTOR) {
- return new JoinPointSignature[0];
+ return JoinPointSignature.EMPTY_ARRAY;
}
// else if (shadowMember.isStatic()) {
// return new ResolvedMember[] {firstDefiningMember};
}
return backingGenericMember.hasAnnotation(ofType);
}
- if (annotationTypes == null) {
- return false;
+ if (annotationTypes != null) {
+ for (int i = 0, max = annotationTypes.length; i < max; i++) {
+ if (annotationTypes[i].equals(ofType)) {
+ return true;
+ }
+ }
}
- return annotationTypes.contains(ofType);
+ return false;
}
public ResolvedType[] getAnnotationTypes() {
}
return backingGenericMember.getAnnotationTypes();
}
- if (annotationTypes == null) {
- return null;
- }
- return annotationTypes.toArray(new ResolvedType[] {});
+ return annotationTypes;
}
public String getAnnotationDefaultValue() {
return super.getAnnotations();
}
- public void setAnnotationTypes(ResolvedType[] annotationtypes) {
- if (annotationTypes == null) {
- annotationTypes = new HashSet<ResolvedType>();
- }
- for (int i = 0; i < annotationtypes.length; i++) {
- ResolvedType typeX = annotationtypes[i];
- annotationTypes.add(typeX);
- }
+ public void setAnnotationTypes(ResolvedType[] annotationTypes) {
+ this.annotationTypes = annotationTypes;
}
public ResolvedType[][] getParameterAnnotationTypes() {
- if (parameterAnnotationTypes == null) {
- return null;
- }
return parameterAnnotationTypes;
}
}
public void addAnnotation(AnnotationAJ annotation) {
- // FIXME asc only allows for annotation types, not instances - should
- // it?
if (annotationTypes == null) {
- annotationTypes = new HashSet<ResolvedType>();
+ annotationTypes = new ResolvedType[1];
+ annotationTypes[0] = annotation.getType();
+ annotations = new AnnotationAJ[1];
+ annotations[0] = annotation;
+ } else {
+ int len = annotations.length;
+ AnnotationAJ[] ret = new AnnotationAJ[len + 1];
+ System.arraycopy(annotations, 0, ret, 0, len);
+ ret[len] = annotation;
+ annotations = ret;
+
+ ResolvedType[] newAnnotationTypes = new ResolvedType[len + 1];
+ System.arraycopy(annotationTypes, 0, newAnnotationTypes, 0, len);
+ newAnnotationTypes[len] = annotation.getType();
+ annotationTypes = newAnnotationTypes;
}
- annotationTypes.add(annotation.getType());
}
public boolean isBridgeMethod() {
* turn into List<String> (for example) - if (!isParameterized) then List<T> will turn into List.
*/
public ResolvedMemberImpl parameterizedWith(UnresolvedType[] typeParameters, ResolvedType newDeclaringType,
- boolean isParameterized, List aliases) {
+ boolean isParameterized, List<String> aliases) {
// PR308773
// this check had problems for the inner type of a generic type because the inner type can be represented
- // by a 'simple type' if it is only sharing type variables with the outer and has none of its own. To avoid the
+ // by a 'simple type' if it is only sharing type variables with the outer and has none of its own. To avoid the
// check going bang in this case we check for $ (crap...) - we can't check the outer because the declaring type
- // is considered unresolved...
+ // is considered unresolved...
if (// isParameterized && <-- might need this bit...
- !getDeclaringType().isGenericType() && getDeclaringType().getName().indexOf("$")==-1) {
+ !getDeclaringType().isGenericType() && getDeclaringType().getName().indexOf("$") == -1) {
throw new IllegalStateException("Can't ask to parameterize a member of non-generic type: " + getDeclaringType()
+ " kind(" + getDeclaringType().typeKind + ")");
}
// the same value as the type variables real name.
if (aliases != null) {
int posn = 0;
- for (Iterator iter = aliases.iterator(); iter.hasNext();) {
- String typeVariableAlias = (String) iter.next();
+ for (String typeVariableAlias : aliases) {
typeMap.put(typeVariableAlias, (!typeParametersSupplied ? typeVariables[posn].getFirstBound()
: typeParameters[posn]));
posn++;
* Replace occurrences of type variables in the signature with values contained in the map. The map is of the form
* A=String,B=Integer and so a signature List<A> Foo.m(B i) {} would become List<String> Foo.m(Integer i) {}
*/
- public ResolvedMember parameterizedWith(Map m, World w) {
+ public ResolvedMember parameterizedWith(Map<String, UnresolvedType> m, World w) {
// if (//isParameterized && <-- might need this bit...
// !getDeclaringType().isGenericType()) {
// throw new IllegalStateException(
return typeVariables;
}
- protected UnresolvedType parameterize(UnresolvedType aType, Map typeVariableMap, boolean inParameterizedType, World w) {
+ protected UnresolvedType parameterize(UnresolvedType aType, Map<String, UnresolvedType> typeVariableMap,
+ boolean inParameterizedType, World w) {
if (aType instanceof TypeVariableReference) {
String variableName = ((TypeVariableReference) aType).getTypeVariable().getName();
if (!typeVariableMap.containsKey(variableName)) {
return aType; // if the type variable comes from the method (and
// not the type) thats OK
}
- return (UnresolvedType) typeVariableMap.get(variableName);
+ return typeVariableMap.get(variableName);
} else if (aType.isParameterizedType()) {
if (inParameterizedType) {
if (w != null) {
StringBuffer sig = new StringBuffer();
UnresolvedType[] myParameterTypes = getGenericParameterTypes();
for (int i = 0; i < myParameterTypes.length; i++) {
- appendSigWithTypeVarBoundsRemoved(myParameterTypes[i], sig, new HashSet());
+ appendSigWithTypeVarBoundsRemoved(myParameterTypes[i], sig, new HashSet<UnresolvedType>());
}
myParameterSignatureWithBoundsRemoved = sig.toString();
return myParameterSignatureWithBoundsRemoved;
// does NOT produce a meaningful java signature, but does give a unique
// string suitable for
// comparison.
- public static void appendSigWithTypeVarBoundsRemoved(UnresolvedType aType, StringBuffer toBuffer, Set alreadyUsedTypeVars) {
+ public static void appendSigWithTypeVarBoundsRemoved(UnresolvedType aType, StringBuffer toBuffer,
+ Set<UnresolvedType> alreadyUsedTypeVars) {
if (aType.isTypeVariableReference()) {
TypeVariableReferenceType typeVariableRT = (TypeVariableReferenceType) aType;
// pr204505
// ---- fields
public static final ResolvedType[] NONE = new ResolvedType[0];
+ public static final ResolvedType[] EMPTY_ARRAY = NONE;
public static final Primitive BYTE = new Primitive("B", 1, 0);
public static final Primitive CHAR = new Primitive("C", 1, 1);
package org.aspectj.weaver.reflect;
import java.lang.reflect.Member;
-import java.util.Iterator;
+import java.util.Set;
import org.aspectj.weaver.AnnotationAJ;
import org.aspectj.weaver.MemberKind;
import org.aspectj.weaver.UnresolvedType;
/**
- * Subtype of ResolvedMemberImpl used in reflection world. Knows how to get
- * annotations from a java.lang.reflect.Member
+ * Subtype of ResolvedMemberImpl used in reflection world. Knows how to get annotations from a java.lang.reflect.Member
*
*/
public class ReflectionBasedResolvedMemberImpl extends ResolvedMemberImpl {
* @param name
* @param parameterTypes
*/
- public ReflectionBasedResolvedMemberImpl(MemberKind kind,
- UnresolvedType declaringType, int modifiers,
- UnresolvedType returnType, String name,
- UnresolvedType[] parameterTypes, Member reflectMember) {
+ public ReflectionBasedResolvedMemberImpl(MemberKind kind, UnresolvedType declaringType, int modifiers,
+ UnresolvedType returnType, String name, UnresolvedType[] parameterTypes, Member reflectMember) {
super(kind, declaringType, modifiers, returnType, name, parameterTypes);
this.reflectMember = reflectMember;
}
* @param parameterTypes
* @param checkedExceptions
*/
- public ReflectionBasedResolvedMemberImpl(MemberKind kind,
- UnresolvedType declaringType, int modifiers,
- UnresolvedType returnType, String name,
- UnresolvedType[] parameterTypes,
- UnresolvedType[] checkedExceptions, Member reflectMember) {
- super(kind, declaringType, modifiers, returnType, name, parameterTypes,
- checkedExceptions);
+ public ReflectionBasedResolvedMemberImpl(MemberKind kind, UnresolvedType declaringType, int modifiers,
+ UnresolvedType returnType, String name, UnresolvedType[] parameterTypes, UnresolvedType[] checkedExceptions,
+ Member reflectMember) {
+ super(kind, declaringType, modifiers, returnType, name, parameterTypes, checkedExceptions);
this.reflectMember = reflectMember;
}
* @param checkedExceptions
* @param backingGenericMember
*/
- public ReflectionBasedResolvedMemberImpl(MemberKind kind,
- UnresolvedType declaringType, int modifiers,
- UnresolvedType returnType, String name,
- UnresolvedType[] parameterTypes,
- UnresolvedType[] checkedExceptions,
+ public ReflectionBasedResolvedMemberImpl(MemberKind kind, UnresolvedType declaringType, int modifiers,
+ UnresolvedType returnType, String name, UnresolvedType[] parameterTypes, UnresolvedType[] checkedExceptions,
ResolvedMember backingGenericMember, Member reflectMember) {
- super(kind, declaringType, modifiers, returnType, name, parameterTypes,
- checkedExceptions, backingGenericMember);
+ super(kind, declaringType, modifiers, returnType, name, parameterTypes, checkedExceptions, backingGenericMember);
this.reflectMember = reflectMember;
}
* @param name
* @param signature
*/
- public ReflectionBasedResolvedMemberImpl(MemberKind kind,
- UnresolvedType declaringType, int modifiers, String name,
+ public ReflectionBasedResolvedMemberImpl(MemberKind kind, UnresolvedType declaringType, int modifiers, String name,
String signature, Member reflectMember) {
super(kind, declaringType, modifiers, name, signature);
this.reflectMember = reflectMember;
// generic signature support
- public void setGenericSignatureInformationProvider(
- GenericSignatureInformationProvider gsigProvider) {
+ public void setGenericSignatureInformationProvider(GenericSignatureInformationProvider gsigProvider) {
this.gsigInfoProvider = gsigProvider;
}
*
* @see org.aspectj.weaver.ResolvedMemberImpl#getGenericParameterTypes()
*/
+ @Override
public UnresolvedType[] getGenericParameterTypes() {
return this.gsigInfoProvider.getGenericParameterTypes(this);
}
*
* @see org.aspectj.weaver.ResolvedMemberImpl#getGenericReturnType()
*/
+ @Override
public UnresolvedType getGenericReturnType() {
return this.gsigInfoProvider.getGenericReturnType(this);
}
*
* @see org.aspectj.weaver.ResolvedMemberImpl#isSynthetic()
*/
+ @Override
public boolean isSynthetic() {
return this.gsigInfoProvider.isSynthetic(this);
}
*
* @see org.aspectj.weaver.ResolvedMemberImpl#isVarargsMethod()
*/
+ @Override
public boolean isVarargsMethod() {
return this.gsigInfoProvider.isVarArgs(this);
}
*
* @see org.aspectj.weaver.ResolvedMemberImpl#isBridgeMethod()
*/
+ @Override
public boolean isBridgeMethod() {
return this.gsigInfoProvider.isBridge(this);
}
this.annotationFinder = finder;
}
+ @Override
public boolean hasAnnotation(UnresolvedType ofType) {
unpackAnnotations();
return super.hasAnnotation(ofType);
}
+ @Override
public boolean hasAnnotations() {
unpackAnnotations();
return super.hasAnnotations();
}
+ @Override
public ResolvedType[] getAnnotationTypes() {
unpackAnnotations();
return super.getAnnotationTypes();
}
+ @Override
public AnnotationAJ getAnnotationOfType(UnresolvedType ofType) {
unpackAnnotations();
- if (annotationFinder == null)
+ if (annotationFinder == null || annotationTypes == null) {
return null;
- for (Iterator iterator = annotationTypes.iterator(); iterator.hasNext();) {
- ResolvedType type = (ResolvedType) iterator.next();
+ }
+ for (ResolvedType type : annotationTypes) {
if (type.getSignature().equals(ofType.getSignature())) {
- return annotationFinder.getAnnotationOfType(ofType,
- reflectMember);
+ return annotationFinder.getAnnotationOfType(ofType, reflectMember);
}
}
return null;
}
+ @Override
public String getAnnotationDefaultValue() {
- if (annotationFinder == null)
+ if (annotationFinder == null) {
return null;
+ }
return annotationFinder.getAnnotationDefaultValue(reflectMember);
}
+ @Override
public ResolvedType[][] getParameterAnnotationTypes() {
if (parameterAnnotationTypes == null && annotationFinder != null) {
- parameterAnnotationTypes = annotationFinder
- .getParameterAnnotationTypes(reflectMember);
+ parameterAnnotationTypes = annotationFinder.getParameterAnnotationTypes(reflectMember);
}
return parameterAnnotationTypes;
}
private void unpackAnnotations() {
if (annotationTypes == null && annotationFinder != null) {
- annotationTypes = annotationFinder.getAnnotations(reflectMember);
+ Set<?> s = annotationFinder.getAnnotations(reflectMember);
+ if (s.size() == 0) {
+ annotationTypes = ResolvedType.EMPTY_ARRAY;
+ } else {
+ annotationTypes = new ResolvedType[s.size()];
+ int i = 0;
+ for (Object o : s) {
+ annotationTypes[i++] = (ResolvedType) o;
+ }
+ }
}
}
}