summaryrefslogtreecommitdiffstats
path: root/org.aspectj.matcher/src/org/aspectj/weaver/ResolvedMemberImpl.java
diff options
context:
space:
mode:
authoraclement <aclement>2010-04-26 23:41:21 +0000
committeraclement <aclement>2010-04-26 23:41:21 +0000
commit4d4b30fc8865354bb1224167fa83108208ad2aae (patch)
treea90c96558cca8d24a589388eac1f6a9b91fd589f /org.aspectj.matcher/src/org/aspectj/weaver/ResolvedMemberImpl.java
parentf9a5f971f17179173889a0dc0be533a7d2180234 (diff)
downloadaspectj-4d4b30fc8865354bb1224167fa83108208ad2aae.tar.gz
aspectj-4d4b30fc8865354bb1224167fa83108208ad2aae.zip
improved annotation handling on ResolvedMemberImpl
Diffstat (limited to 'org.aspectj.matcher/src/org/aspectj/weaver/ResolvedMemberImpl.java')
-rw-r--r--org.aspectj.matcher/src/org/aspectj/weaver/ResolvedMemberImpl.java100
1 files changed, 52 insertions, 48 deletions
diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/ResolvedMemberImpl.java b/org.aspectj.matcher/src/org/aspectj/weaver/ResolvedMemberImpl.java
index 3890488d0..c63c8a09c 100644
--- a/org.aspectj.matcher/src/org/aspectj/weaver/ResolvedMemberImpl.java
+++ b/org.aspectj.matcher/src/org/aspectj/weaver/ResolvedMemberImpl.java
@@ -1,15 +1,11 @@
/* *******************************************************************
- * 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;
@@ -26,31 +22,35 @@ import java.util.Set;
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
@@ -106,7 +106,7 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
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...
@@ -116,7 +116,7 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
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};
@@ -288,10 +288,14 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
}
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() {
@@ -305,10 +309,7 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
}
return backingGenericMember.getAnnotationTypes();
}
- if (annotationTypes == null) {
- return null;
- }
- return annotationTypes.toArray(new ResolvedType[] {});
+ return annotationTypes;
}
public String getAnnotationDefaultValue() {
@@ -324,20 +325,11 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
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;
}
@@ -350,12 +342,23 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
}
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() {
@@ -670,14 +673,14 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
* 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 + ")");
}
@@ -703,8 +706,7 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
// 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++;
@@ -732,7 +734,7 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
* 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(
@@ -802,14 +804,15 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
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) {
@@ -982,7 +985,7 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
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;
@@ -1019,7 +1022,8 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
// 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