/**
* A getter represents a mapping function from Object to Iterator
*/
- public interface Getter {
- Iterator get(Object target);
+ public interface Getter<A, B> {
+ Iterator<B> get(A target);
}
/**
* A filter represents a mapping function from Iterator to Iterator
*/
- public interface Filter {
- Iterator filter(Iterator in);
+ public interface Filter<T> {
+ Iterator<T> filter(Iterator<T> in);
}
/**
* Create a new filter F that, when wrapped around another iterator I, creates a new iterator I' that will return only those
* values of I that have not yet been returned by I', discarding duplicates.
*/
- public static Filter dupFilter() {
- return new Filter() {
- final Set seen = new HashSet(); // should have weak ptrs?
+ public static <T> Filter<T> dupFilter() {
+ return new Filter<T>() {
+ final Set<T> seen = new HashSet<T>(); // should have weak ptrs?
- public Iterator filter(final Iterator in) {
- return new Iterator() {
+ public Iterator<T> filter(final Iterator<T> in) {
+ return new Iterator<T>() {
boolean fresh = false;
- Object peek;
+ T peek;
public boolean hasNext() {
- if (fresh)
+ if (fresh) {
return true;
+ }
while (true) {
- if (!in.hasNext())
+ if (!in.hasNext()) {
return false;
+ }
peek = in.next();
if (!seen.contains(peek)) {
return fresh = true;
}
}
- public Object next() {
+ public T next() {
if (!hasNext())
throw new NoSuchElementException();
- Object ret = peek;
+ T ret = peek;
+ seen.add(peek);
peek = null;
fresh = false;
return ret;
* all that pesky safety.
*/
- public static Iterator array(final Object[] o) {
- return new Iterator() {
+ public static <T> Iterator<T> array(final T[] o) {
+ return new Iterator<T>() {
int i = 0;
int len = (o == null) ? 0 : o.length;
return i < len;
}
- public Object next() {
+ public T next() {
if (i < len) {
return o[i++];
} else {
/**
* creates an iterator I based on a base iterator A and a getter G. I returns, in order, forall (i in I), G(i).
*/
- public static Iterator mapOver(final Iterator a, final Getter g) {
- return new Iterator() {
- Iterator delegate = new Iterator() {
+ public static <A, B> Iterator<B> mapOver(final Iterator<A> a, final Getter<A, B> g) {
+ return new Iterator<B>() {
+ Iterator<B> delegate = new Iterator<B>() {
public boolean hasNext() {
if (!a.hasNext())
return false;
- Object o = a.next();
+ A o = a.next();
delegate = append1(g.get(o), this);
return delegate.hasNext();
}
- public Object next() {
+ public B next() {
if (!hasNext())
throw new UnsupportedOperationException();
return delegate.next();
return delegate.hasNext();
}
- public Object next() {
+ public B next() {
return delegate.next();
}
* creates an iterator I based on a base iterator A and a getter G. I returns, in order, forall (i in I) i :: forall (i' in
* g(i)) recur(i', g)
*/
- public static Iterator recur(final Object a, final Getter g) {
- return new Iterator() {
- Iterator delegate = one(a);
+ public static <A> Iterator<A> recur(final A a, final Getter<A, A> g) {
+ return new Iterator<A>() {
+ Iterator<A> delegate = one(a);
public boolean hasNext() {
return delegate.hasNext();
}
- public Object next() {
- Object next = delegate.next();
+ public A next() {
+ A next = delegate.next();
delegate = append(g.get(next), delegate);
return next;
}
* creates an iterator I based on base iterators A and B. Returns the elements returned by A followed by those returned by B. If
* B is empty, simply returns A, and if A is empty, simply returns B. Do NOT USE if b.hasNext() is not idempotent.
*/
- public static Iterator append(final Iterator a, final Iterator b) {
+ public static <T> Iterator<T> append(final Iterator<T> a, final Iterator<T> b) {
if (!b.hasNext())
return a;
return append1(a, b);
* creates an iterator I based on base iterators A and B. Returns the elements returned by A followed by those returned by B. If
* A is empty, simply returns B. Guaranteed not to call B.hasNext() until A is empty.
*/
- public static Iterator append1(final Iterator a, final Iterator b) {
+ public static <T> Iterator<T> append1(final Iterator<T> a, final Iterator<T> b) {
if (!a.hasNext())
return b;
- return new Iterator() {
+ return new Iterator<T>() {
public boolean hasNext() {
return a.hasNext() || b.hasNext();
}
- public Object next() {
+ public T next() {
if (a.hasNext())
return a.next();
if (b.hasNext())
/**
* creates an iterator I based on a base iterator A and an object O. Returns the elements returned by A, followed by O.
*/
- public static Iterator snoc(final Iterator first, final Object last) {
- return new Iterator() {
- Object last1 = last;
+ public static <T> Iterator<T> snoc(final Iterator<T> first, final T last) {
+ return new Iterator<T>() {
+ T last1 = last;
public boolean hasNext() {
return first.hasNext() || last1 != null;
}
- public Object next() {
+ public T next() {
if (first.hasNext())
return first.next();
else if (last1 == null)
throw new NoSuchElementException();
- Object ret = last1;
+ T ret = last1;
last1 = null;
return ret;
}
/**
* creates an iterator I based on an object O. Returns O, once.
*/
- public static Iterator one(final Object it) {
- return new Iterator() {
+ public static <T> Iterator<T> one(final T it) {
+ return new Iterator<T>() {
boolean avail = true;
public boolean hasNext() {
return avail;
}
- public Object next() {
- if (!avail)
+ public T next() {
+ if (!avail) {
throw new NoSuchElementException();
+ }
avail = false;
return it;
}
return realMember.getAnnotationOfType(ofType);
}
- public void setAnnotationTypes(UnresolvedType[] annotationtypes) {
+ public void setAnnotationTypes(ResolvedType[] annotationtypes) {
realMember.setAnnotationTypes(annotationtypes);
}
return realMember.getJoinPointSignatures(world);
}
+ @Override
public String toString() {
StringBuffer buf = new StringBuffer();
buf.append(getReturnType().getName());
realMember.resetReturnTypeToObjectArray();
}
+ @Override
public boolean equals(Object obj) {
if (!(obj instanceof JoinPointSignature))
return false;
return true;
}
+ @Override
public int hashCode() {
return 17 + (37 * realMember.hashCode()) + (37 * substituteDeclaringType.hashCode());
}
this.derivativeTypes.add(dependent);
}
+ @Override
public String getSignatureForAttribute() {
if (genericType == null || typeParameters == null)
return getSignature();
typeKind = TypeKind.GENERIC;
}
+ @Override
public boolean isClass() {
return delegate.isClass();
}
+ @Override
public boolean isGenericType() {
return !isParameterizedType() && !isRawType() && delegate.isGeneric();
}
return (sig == null) ? "" : sig;
}
+ @Override
public AnnotationAJ[] getAnnotations() {
return delegate.getAnnotations();
}
+ @Override
public void addAnnotation(AnnotationAJ annotationX) {
if (annotations == null) {
annotations = new AnnotationAJ[1];
}
}
+ @Override
public ResolvedType[] getAnnotationTypes() {
if (delegate == null) {
throw new BCException("Unexpected null delegate for type " + this.getName());
}
}
+ @Override
public AnnotationAJ getAnnotationOfType(UnresolvedType ofType) {
AnnotationAJ[] axs = delegate.getAnnotations();
if (axs == null) {
return null;
}
+ @Override
public boolean isAspect() {
return delegate.isAspect();
}
+ @Override
public boolean isAnnotationStyleAspect() {
return delegate.isAnnotationStyleAspect();
}
+ @Override
public boolean isEnum() {
return delegate.isEnum();
}
+ @Override
public boolean isAnnotation() {
return delegate.isAnnotation();
}
+ @Override
public boolean isAnonymous() {
return delegate.isAnonymous();
}
+ @Override
public boolean isNested() {
return delegate.isNested();
}
return delegate.getRetentionPolicy();
}
+ @Override
public boolean isAnnotationWithRuntimeRetention() {
return delegate.isAnnotationWithRuntimeRetention();
}
+ @Override
public boolean canAnnotationTargetType() {
return delegate.canAnnotationTargetType();
}
+ @Override
public AnnotationTargetKind[] getAnnotationTargetKinds() {
return delegate.getAnnotationTargetKinds();
}
// true iff the statement "this = (ThisType) other" would compile
+ @Override
public boolean isCoerceableFrom(ResolvedType o) {
ResolvedType other = o.resolve(world);
return false;
}
+ @Override
public boolean isAssignableFrom(ResolvedType other) {
return isAssignableFrom(other, false);
}
// TODO rewrite this method - it is a terrible mess
// true iff the statement "this = other" would compile.
+ @Override
public boolean isAssignableFrom(ResolvedType other, boolean allowMissing) {
if (other.isPrimitiveType()) {
if (!world.isInJava5Mode())
return false;
}
+ @Override
public ISourceContext getSourceContext() {
return delegate.getSourceContext();
}
+ @Override
public ISourceLocation getSourceLocation() {
ISourceContext isc = delegate.getSourceContext();
return isc.makeSourceLocation(new Position(startPos, endPos));
}
+ @Override
public boolean isExposedToWeaver() {
return (delegate == null) || delegate.isExposedToWeaver(); // ??? where
// does this
// belong
}
+ @Override
public WeaverStateInfo getWeaverState() {
return delegate.getWeaverState();
}
+ @Override
public ResolvedMember[] getDeclaredFields() {
if (parameterizedFields != null)
return parameterizedFields;
* Find out from the generic signature the true signature of any interfaces I implement. If I am parameterized, these may then
* need to be parameterized before returning.
*/
+ @Override
public ResolvedType[] getDeclaredInterfaces() {
if (parameterizedInterfaces != null)
return parameterizedInterfaces;
return -1;
}
+ @Override
public ResolvedMember[] getDeclaredMethods() {
if (parameterizedMethods != null)
return parameterizedMethods;
}
}
+ @Override
public ResolvedMember[] getDeclaredPointcuts() {
if (parameterizedPointcuts != null)
return parameterizedPointcuts;
return parameters;
}
+ @Override
public UnresolvedType getRawType() {
return super.getRawType().resolve(world);
}
+ @Override
public TypeVariable[] getTypeVariables() {
if (this.typeVariables == null) {
this.typeVariables = delegate.getTypeVariables();
return this.typeVariables;
}
+ @Override
public PerClause getPerClause() {
PerClause pclause = delegate.getPerClause();
if (isParameterizedType()) { // could cache the result here...
return pclause;
}
- public Collection getDeclares() {
+ @Override
+ public Collection<Declare> getDeclares() {
if (parameterizedDeclares != null)
return parameterizedDeclares;
- Collection declares = null;
+ Collection<Declare> declares = null;
if (ajMembersNeedParameterization()) {
Collection genericDeclares = delegate.getDeclares();
parameterizedDeclares = new ArrayList();
} else {
declares = delegate.getDeclares();
}
- for (Iterator iter = declares.iterator(); iter.hasNext();) {
- Declare d = (Declare) iter.next();
+ for (Declare d : declares) {
d.setDeclaringType(this);
}
return declares;
}
+ @Override
public Collection getTypeMungers() {
return delegate.getTypeMungers();
}
// return ret;
// }
+ @Override
public Collection getPrivilegedAccesses() {
return delegate.getPrivilegedAccesses();
}
+ @Override
public int getModifiers() {
return delegate.getModifiers();
}
+ @Override
public ResolvedType getSuperclass() {
if (newSuperclass != null) {
if (this.isParameterizedType() && newSuperclass.isParameterizedType()) {
this.startPos = startPos;
}
+ @Override
public boolean doesNotExposeShadowMungers() {
return delegate.doesNotExposeShadowMungers();
}
signatureErasure = null;
}
+ @Override
public ResolvedType getGenericType() {
if (isGenericType())
return this;
return ret.toString();
}
+ @Override
public void ensureConsistent() {
annotations = null;
annotationTypes = null;
newInterfaces = null;
}
+ @Override
public void addParent(ResolvedType newParent) {
if (newParent.isClass()) {
newSuperclass = newParent;
import java.util.Collection;
+import org.aspectj.weaver.patterns.Declare;
import org.aspectj.weaver.patterns.PerClause;
/**
public interface ReferenceTypeDelegate {
public boolean isAspect();
-
+
/**
* @return true if the type is an annotation style aspect (a type marked @Aspect)
*/
*/
public PerClause getPerClause();
- public Collection getDeclares();
+ public Collection<Declare> getDeclares();
public Collection getTypeMungers();
public ResolvedType[] getAnnotationTypes();
- public void setAnnotationTypes(UnresolvedType[] annotationtypes);
+ public void setAnnotationTypes(ResolvedType[] annotationtypes);
public void addAnnotation(AnnotationAJ annotation);
*/
protected ResolvedMember backingGenericMember = null;
- protected Set<UnresolvedType> annotationTypes = null;
+ protected Set<ResolvedType> annotationTypes = null;
protected ResolvedType[][] parameterAnnotationTypes = null;
// Some members are 'created' to represent other things (for example ITDs).
// }
}
- List declaringTypes = new ArrayList();
+ List<ResolvedType> declaringTypes = new ArrayList<ResolvedType>();
accumulateTypesInBetween(originalDeclaringType, firstDefiningType, declaringTypes);
- Set memberSignatures = new HashSet();
- for (Iterator iter = declaringTypes.iterator(); iter.hasNext();) {
- ResolvedType declaringType = (ResolvedType) iter.next();
+ Set<ResolvedMember> memberSignatures = new HashSet<ResolvedMember>();
+ for (ResolvedType declaringType : declaringTypes) {
ResolvedMember member = firstDefiningMember.withSubstituteDeclaringType(declaringType);
memberSignatures.add(member);
}
// include the signature for
// every type between the firstDefiningMember and the root defining
// member.
- Iterator superTypeIterator = firstDefiningType.getDirectSupertypes();
+ Iterator<ResolvedType> superTypeIterator = firstDefiningType.getDirectSupertypes();
List typesAlreadyVisited = new ArrayList();
accumulateMembersMatching(firstDefiningMember, superTypeIterator, typesAlreadyVisited, memberSignatures, false);
}
/**
* Build a list containing every type between subtype and supertype, inclusively.
*/
- private static void accumulateTypesInBetween(ResolvedType subType, ResolvedType superType, List types) {
+ private static void accumulateTypesInBetween(ResolvedType subType, ResolvedType superType, List<ResolvedType> types) {
types.add(subType);
if (subType == superType) {
return;
} else {
- for (Iterator iter = subType.getDirectSupertypes(); iter.hasNext();) {
- ResolvedType parent = (ResolvedType) iter.next();
+ for (Iterator<ResolvedType> iter = subType.getDirectSupertypes(); iter.hasNext();) {
+ ResolvedType parent = iter.next();
if (superType.isAssignableFrom(parent)) {
accumulateTypesInBetween(parent, superType, types);
}
* We have a resolved member, possibly with type parameter references as parameters or return type. We need to find all its
* ancestor members. When doing this, a type parameter matches regardless of bounds (bounds can be narrowed down the hierarchy).
*/
- private static void accumulateMembersMatching(ResolvedMemberImpl memberToMatch, Iterator typesToLookIn,
- List typesAlreadyVisited, Set foundMembers, boolean ignoreGenerics) {
+ private static void accumulateMembersMatching(ResolvedMemberImpl memberToMatch, Iterator<ResolvedType> typesToLookIn,
+ List<ResolvedType> typesAlreadyVisited, Set<ResolvedMember> foundMembers, boolean ignoreGenerics) {
while (typesToLookIn.hasNext()) {
- ResolvedType toLookIn = (ResolvedType) typesToLookIn.next();
+ ResolvedType toLookIn = typesToLookIn.next();
if (!typesAlreadyVisited.contains(toLookIn)) {
typesAlreadyVisited.add(toLookIn);
ResolvedMemberImpl foundMember = (ResolvedMemberImpl) toLookIn.lookupResolvedMember(memberToMatch, true,
ignoreGenerics);
if (foundMember != null && isVisibleTo(memberToMatch, foundMember)) {
- List declaringTypes = new ArrayList();
+ List<ResolvedType> declaringTypes = new ArrayList<ResolvedType>();
// declaring type can be unresolved if the member can from
// an ITD...
ResolvedType resolvedDeclaringType = foundMember.getDeclaringType().resolve(toLookIn.getWorld());
accumulateTypesInBetween(toLookIn, resolvedDeclaringType, declaringTypes);
- for (Iterator iter = declaringTypes.iterator(); iter.hasNext();) {
- ResolvedType declaringType = (ResolvedType) iter.next();
+ for (ResolvedType declaringType : declaringTypes) {
// typesAlreadyVisited.add(declaringType);
ResolvedMember member = foundMember.withSubstituteDeclaringType(declaringType);
foundMembers.add(member);
return super.getAnnotations();
}
- public void setAnnotationTypes(UnresolvedType[] annotationtypes) {
+ public void setAnnotationTypes(ResolvedType[] annotationtypes) {
if (annotationTypes == null) {
- annotationTypes = new HashSet<UnresolvedType>();
+ annotationTypes = new HashSet<ResolvedType>();
}
for (int i = 0; i < annotationtypes.length; i++) {
- UnresolvedType typeX = annotationtypes[i];
+ ResolvedType typeX = annotationtypes[i];
annotationTypes.add(typeX);
}
}
// FIXME asc only allows for annotation types, not instances - should
// it?
if (annotationTypes == null) {
- annotationTypes = new HashSet<UnresolvedType>();
+ annotationTypes = new HashSet<ResolvedType>();
}
annotationTypes.add(annotation.getType());
}
}
}
world.setTypeVariableLookupScope(this);
- if (annotationTypes != null) {
- Set<UnresolvedType> r = new HashSet<UnresolvedType>();
- for (UnresolvedType element : annotationTypes) {
- // for (Iterator iter = annotationTypes.iterator(); iter.hasNext();) {
- // UnresolvedType element = (UnresolvedType) iter.next();
- r.add(world.resolve(element));
- }
- annotationTypes = r;
- }
+ // if (annotationTypes != null) {
+ // Set<ResolvedType> r = new HashSet<ResolvedType>();
+ // for (UnresolvedType element : annotationTypes) {
+ // // for (Iterator iter = annotationTypes.iterator(); iter.hasNext();) {
+ // // UnresolvedType element = (UnresolvedType) iter.next();
+ // r.add(world.resolve(element));
+ // }
+ // annotationTypes = r;
+ // }
declaringType = declaringType.resolve(world);
if (declaringType.isRawType())
declaringType = ((ReferenceType) declaringType).getGenericType();
if (isParameterized && (typeVariables.length != typeParameters.length)) {
throw new IllegalStateException("Wrong number of type parameters supplied");
}
- Map typeMap = new HashMap();
+ Map<String, UnresolvedType> typeMap = new HashMap<String, UnresolvedType>();
boolean typeParametersSupplied = typeParameters != null && typeParameters.length > 0;
if (typeVariables != null) {
// If no 'replacements' were supplied in the typeParameters array
* Returns an iterator through ResolvedType objects representing all the direct supertypes of this type. That is, through the
* superclass, if any, and all declared interfaces.
*/
- public final Iterator getDirectSupertypes() {
- Iterator ifacesIterator = Iterators.array(getDeclaredInterfaces());
+ public final Iterator<ResolvedType> getDirectSupertypes() {
+ Iterator<ResolvedType> ifacesIterator = Iterators.array(getDeclaredInterfaces());
ResolvedType superclass = getSuperclass();
if (superclass == null) {
return ifacesIterator;
}
/**
- * Returns a ResolvedType object representing the superclass of this type, or null. If this represents a java.lang.Object, a
- * primitive type, or void, this method returns null.
+ * @return the superclass of this type, or null (if this represents a jlObject, primitive, or void)
*/
public abstract ResolvedType getSuperclass();
- /**
- * Returns the modifiers for this type.
- * <p/>
- * See {@link Class#getModifiers()} for a description of the weirdness of this methods on primitives and arrays.
- *
- * @param world the {@link World} in which the lookup is made.
- * @return an int representing the modifiers for this type
- * @see java.lang.reflect.Modifier
- */
public abstract int getModifiers();
// return true if this resolved type couldn't be found (but we know it's
// This set contains pairs of types whose signatures are concatenated
// together, this means with a fast lookup we can tell if two types
// are equivalent.
- protected static Set validBoxing = new HashSet();
+ protected static Set<String> validBoxing = new HashSet<String>();
static {
validBoxing.add("Ljava/lang/Byte;B");
* <p/>
* We keep a hashSet of interfaces that we've visited so we don't spiral out into 2^n land.
*/
- public Iterator getFields() {
- final Iterators.Filter dupFilter = Iterators.dupFilter();
- Iterators.Getter typeGetter = new Iterators.Getter() {
- public Iterator get(Object o) {
- return dupFilter.filter(((ResolvedType) o).getDirectSupertypes());
+ public Iterator<ResolvedMember> getFields() {
+ final Iterators.Filter<ResolvedType> dupFilter = Iterators.dupFilter();
+ Iterators.Getter<ResolvedType, ResolvedType> typeGetter = new Iterators.Getter<ResolvedType, ResolvedType>() {
+ public Iterator<ResolvedType> get(ResolvedType o) {
+ return dupFilter.filter((o).getDirectSupertypes());
}
};
- Iterators.Getter fieldGetter = new Iterators.Getter() {
- public Iterator get(Object o) {
- return Iterators.array(((ResolvedType) o).getDeclaredFields());
+ Iterators.Getter<ResolvedType, ResolvedMember> fieldGetter = new Iterators.Getter<ResolvedType, ResolvedMember>() {
+ public Iterator<ResolvedMember> get(ResolvedType o) {
+ return Iterators.array((o).getDeclaredFields());
}
};
return Iterators.mapOver(Iterators.recur(this, typeGetter), fieldGetter);
* We keep a hashSet of interfaces that we've visited so we don't spiral out into 2^n land. NOTE: Take a look at the javadoc on
* getMethodsWithoutIterator() to see if you are sensitive to a quirk in getMethods()
*/
- public Iterator getMethods() {
- final Iterators.Filter dupFilter = Iterators.dupFilter();
- Iterators.Getter ifaceGetter = new Iterators.Getter() {
- public Iterator get(Object o) {
- return dupFilter.filter(Iterators.array(((ResolvedType) o).getDeclaredInterfaces()));
+ public Iterator<ResolvedMember> getMethods() {
+ final Iterators.Filter<ResolvedType> dupFilter = Iterators.dupFilter();
+ Iterators.Getter<ResolvedType, ResolvedType> ifaceGetter = new Iterators.Getter<ResolvedType, ResolvedType>() {
+ public Iterator<ResolvedType> get(ResolvedType o) {
+ return dupFilter.filter(Iterators.array(o.getDeclaredInterfaces()));
}
};
- Iterators.Getter methodGetter = new Iterators.Getter() {
- public Iterator get(Object o) {
- return Iterators.array(((ResolvedType) o).getDeclaredMethods());
+ Iterators.Getter<ResolvedType, ResolvedMember> methodGetter = new Iterators.Getter<ResolvedType, ResolvedMember>() {
+ public Iterator<ResolvedMember> get(ResolvedType o) {
+ return Iterators.array((o).getDeclaredMethods());
}
};
- return Iterators.mapOver(Iterators.append(new Iterator() {
+ return Iterators.mapOver(Iterators.append(new Iterator<ResolvedType>() {
ResolvedType curr = ResolvedType.this;
public boolean hasNext() {
return curr != null;
}
- public Object next() {
+ public ResolvedType next() {
ResolvedType ret = curr;
curr = curr.getSuperclass();
return ret;
* return methods declared on *this* class twice, once at the start and once at the end - I couldn't debug that problem, so
* created this alternative.
*/
- public List getMethodsWithoutIterator(boolean includeITDs, boolean allowMissing) {
- List methods = new ArrayList();
- Set knowninterfaces = new HashSet();
+ public List<ResolvedMember> getMethodsWithoutIterator(boolean includeITDs, boolean allowMissing) {
+ List<ResolvedMember> methods = new ArrayList<ResolvedMember>();
+ Set<ResolvedType> knowninterfaces = new HashSet<ResolvedType>();
addAndRecurse(knowninterfaces, methods, this, includeITDs, allowMissing, false);
return methods;
}
- public List getMethodsWithoutIterator(boolean includeITDs, boolean allowMissing, boolean genericsAware) {
- List methods = new ArrayList();
- Set knowninterfaces = new HashSet();
+ public List<ResolvedMember> getMethodsWithoutIterator(boolean includeITDs, boolean allowMissing, boolean genericsAware) {
+ List<ResolvedMember> methods = new ArrayList<ResolvedMember>();
+ Set<ResolvedType> knowninterfaces = new HashSet<ResolvedType>();
addAndRecurse(knowninterfaces, methods, this, includeITDs, allowMissing, genericsAware);
return methods;
}
- private void addAndRecurse(Set knowninterfaces, List collector, ResolvedType resolvedType, boolean includeITDs,
- boolean allowMissing, boolean genericsAware) {
+ private void addAndRecurse(Set<ResolvedType> knowninterfaces, List<ResolvedMember> collector, ResolvedType resolvedType,
+ boolean includeITDs, boolean allowMissing, boolean genericsAware) {
// Add the methods declared on this type
collector.addAll(Arrays.asList(resolvedType.getDeclaredMethods()));
// now add all the inter-typed members too
if (includeITDs && resolvedType.interTypeMungers != null) {
- for (Iterator i = interTypeMungers.iterator(); i.hasNext();) {
- ConcreteTypeMunger tm = (ConcreteTypeMunger) i.next();
- ResolvedMember rm = tm.getSignature();
+ for (ConcreteTypeMunger typeTransformer : interTypeMungers) {
+ ResolvedMember rm = typeTransformer.getSignature();
if (rm != null) { // new parent type munger can have null signature
- collector.add(tm.getSignature());
+ collector.add(typeTransformer.getSignature());
}
}
}
/**
* described in JVM spec 2ed 5.4.3.2
*/
- public ResolvedMember lookupField(Member m) {
- return lookupMember(m, getFields());
+ public ResolvedMember lookupField(Member field) {
+ Iterator<ResolvedMember> i = getFields();
+ while (i.hasNext()) {
+ ResolvedMember resolvedMember = i.next();
+ if (matches(resolvedMember, field)) {
+ return resolvedMember;
+ }
+ if (resolvedMember.hasBackingGenericMember() && field.getName().equals(resolvedMember.getName())) {
+ // might be worth checking the member behind the parameterized member (see pr137496)
+ if (matches(resolvedMember.getBackingGenericMember(), field)) {
+ return resolvedMember;
+ }
+ }
+ }
+ return null;
}
/**
return null;
}
- /**
- * return null if not found
- */
- private ResolvedMember lookupMember(Member m, Iterator i) {
- while (i.hasNext()) {
- ResolvedMember f = (ResolvedMember) i.next();
- if (matches(f, m))
- return f;
- if (f.hasBackingGenericMember() && m.getName().equals(f.getName())) { // might
- // be
- // worth
- // checking
- // the
- // method
- // behind
- // the
- // parameterized method (see pr137496)
- if (matches(f.getBackingGenericMember(), m))
- return f;
- }
- }
- return null; // ResolvedMember.Missing;
- // throw new BCException("can't find " + m);
- }
-
/**
* return null if not found
*/
toSearch = getFields();
}
while (toSearch.hasNext()) {
- ResolvedMember candidate = (ResolvedMemberImpl) toSearch.next();
+ ResolvedMember candidate = (ResolvedMember) toSearch.next();
if (ignoreGenerics) {
if (candidate.hasBackingGenericMember()) {
candidate = candidate.getBackingGenericMember();
* <p/>
* We keep a hashSet of interfaces that we've visited so we don't spiral out into 2^n land.
*/
- public Iterator getPointcuts() {
- final Iterators.Filter dupFilter = Iterators.dupFilter();
+ public Iterator<ResolvedMember> getPointcuts() {
+ final Iterators.Filter<ResolvedType> dupFilter = Iterators.dupFilter();
// same order as fields
- Iterators.Getter typeGetter = new Iterators.Getter() {
- public Iterator get(Object o) {
- return dupFilter.filter(((ResolvedType) o).getDirectSupertypes());
+ Iterators.Getter<ResolvedType, ResolvedType> typeGetter = new Iterators.Getter<ResolvedType, ResolvedType>() {
+ public Iterator<ResolvedType> get(ResolvedType o) {
+ return dupFilter.filter(o.getDirectSupertypes());
}
};
- Iterators.Getter pointcutGetter = new Iterators.Getter() {
- public Iterator get(Object o) {
+ Iterators.Getter<ResolvedType, ResolvedMember> pointcutGetter = new Iterators.Getter<ResolvedType, ResolvedMember>() {
+ public Iterator<ResolvedMember> get(ResolvedType o) {
// System.err.println("getting for " + o);
- return Iterators.array(((ResolvedType) o).getDeclaredPointcuts());
+ return Iterators.array(o.getDeclaredPointcuts());
}
};
return Iterators.mapOver(Iterators.recur(this, typeGetter), pointcutGetter);
return crosscuttingMembers;
}
- public final Collection collectDeclares(boolean includeAdviceLike) {
+ public final List<Declare> collectDeclares(boolean includeAdviceLike) {
if (!this.isAspect()) {
- return Collections.EMPTY_LIST;
+ return Collections.emptyList();
}
- ArrayList ret = new ArrayList();
+ List<Declare> ret = new ArrayList<Declare>();
// if (this.isAbstract()) {
// for (Iterator i = getDeclares().iterator(); i.hasNext();) {
// Declare dec = (Declare) i.next();
if (!this.isAbstract()) {
// ret.addAll(getDeclares());
- final Iterators.Filter dupFilter = Iterators.dupFilter();
- Iterators.Getter typeGetter = new Iterators.Getter() {
- public Iterator get(Object o) {
- return dupFilter.filter(((ResolvedType) o).getDirectSupertypes());
+ final Iterators.Filter<ResolvedType> dupFilter = Iterators.dupFilter();
+ Iterators.Getter<ResolvedType, ResolvedType> typeGetter = new Iterators.Getter<ResolvedType, ResolvedType>() {
+ public Iterator<ResolvedType> get(ResolvedType o) {
+ return dupFilter.filter((o).getDirectSupertypes());
}
};
- Iterator typeIterator = Iterators.recur(this, typeGetter);
+ Iterator<ResolvedType> typeIterator = Iterators.recur(this, typeGetter);
while (typeIterator.hasNext()) {
- ResolvedType ty = (ResolvedType) typeIterator.next();
+ ResolvedType ty = typeIterator.next();
// System.out.println("super: " + ty + ", " + );
for (Iterator i = ty.getDeclares().iterator(); i.hasNext();) {
Declare dec = (Declare) i.next();
return ret;
}
- private final Collection collectShadowMungers() {
- if (!this.isAspect() || this.isAbstract() || this.doesNotExposeShadowMungers())
- return Collections.EMPTY_LIST;
+ private final List<ShadowMunger> collectShadowMungers() {
+ if (!this.isAspect() || this.isAbstract() || this.doesNotExposeShadowMungers()) {
+ return Collections.emptyList();
+ }
- ArrayList acc = new ArrayList();
- final Iterators.Filter dupFilter = Iterators.dupFilter();
- Iterators.Getter typeGetter = new Iterators.Getter() {
- public Iterator get(Object o) {
- return dupFilter.filter(((ResolvedType) o).getDirectSupertypes());
+ List<ShadowMunger> acc = new ArrayList<ShadowMunger>();
+ final Iterators.Filter<ResolvedType> dupFilter = Iterators.dupFilter();
+ Iterators.Getter<ResolvedType, ResolvedType> typeGetter = new Iterators.Getter<ResolvedType, ResolvedType>() {
+ public Iterator<ResolvedType> get(ResolvedType o) {
+ return dupFilter.filter((o).getDirectSupertypes());
}
};
- Iterator typeIterator = Iterators.recur(this, typeGetter);
+ Iterator<ResolvedType> typeIterator = Iterators.recur(this, typeGetter);
while (typeIterator.hasNext()) {
- ResolvedType ty = (ResolvedType) typeIterator.next();
+ ResolvedType ty = typeIterator.next();
acc.addAll(ty.getDeclaredShadowMungers());
}
return Modifier.isFinal(getModifiers());
}
- protected Map /* Type variable name -> UnresolvedType */getMemberParameterizationMap() {
- if (!isParameterizedType())
- return Collections.EMPTY_MAP;
+ protected Map<String, UnresolvedType> getMemberParameterizationMap() {
+ if (!isParameterizedType()) {
+ return Collections.emptyMap();
+ }
TypeVariable[] tvs = getGenericType().getTypeVariables();
- Map parameterizationMap = new HashMap();
+ Map<String, UnresolvedType> parameterizationMap = new HashMap<String, UnresolvedType>();
for (int i = 0; i < tvs.length; i++) {
parameterizationMap.put(tvs[i].getName(), typeParameters[i]);
}
return parameterizationMap;
}
- public Collection getDeclaredAdvice() {
- List l = new ArrayList();
+ public List<ShadowMunger> getDeclaredAdvice() {
+ List<ShadowMunger> l = new ArrayList<ShadowMunger>();
ResolvedMember[] methods = getDeclaredMethods();
- if (isParameterizedType())
+ if (isParameterizedType()) {
methods = getGenericType().getDeclaredMethods();
+ }
Map typeVariableMap = getAjMemberParameterizationMap();
for (int i = 0, len = methods.length; i < len; i++) {
ShadowMunger munger = methods[i].getAssociatedShadowMunger();
return l;
}
- public Collection getDeclaredShadowMungers() {
- Collection c = getDeclaredAdvice();
- return c;
+ public List<ShadowMunger> getDeclaredShadowMungers() {
+ return getDeclaredAdvice();
}
// ---- only for testing!
return filterInJavaVisible(getDeclaredMethods());
}
- public ShadowMunger[] getDeclaredShadowMungersArray() {
- List l = (List) getDeclaredShadowMungers();
- return (ShadowMunger[]) l.toArray(new ShadowMunger[l.size()]);
- }
-
private ResolvedMember[] filterInJavaVisible(ResolvedMember[] ms) {
List l = new ArrayList();
for (int i = 0, len = ms.length; i < len; i++) {
return interTypeMungers;
}
- public List getInterTypeParentMungers() {
- List l = new ArrayList();
- for (Iterator iter = interTypeMungers.iterator(); iter.hasNext();) {
- ConcreteTypeMunger element = (ConcreteTypeMunger) iter.next();
- if (element.getMunger() instanceof NewParentTypeMunger)
+ public List<ConcreteTypeMunger> getInterTypeParentMungers() {
+ List<ConcreteTypeMunger> l = new ArrayList<ConcreteTypeMunger>();
+ for (ConcreteTypeMunger element : interTypeMungers) {
+ if (element.getMunger() instanceof NewParentTypeMunger) {
l.add(element);
+ }
}
return l;
}
/**
* ??? This method is O(N*M) where N = number of methods and M is number of inter-type declarations in my super
*/
- public List getInterTypeMungersIncludingSupers() {
- ArrayList ret = new ArrayList();
+ public List<ConcreteTypeMunger> getInterTypeMungersIncludingSupers() {
+ ArrayList<ConcreteTypeMunger> ret = new ArrayList<ConcreteTypeMunger>();
collectInterTypeMungers(ret);
return ret;
}
- public List getInterTypeParentMungersIncludingSupers() {
- ArrayList ret = new ArrayList();
+ public List<ConcreteTypeMunger> getInterTypeParentMungersIncludingSupers() {
+ ArrayList<ConcreteTypeMunger> ret = new ArrayList<ConcreteTypeMunger>();
collectInterTypeParentMungers(ret);
return ret;
}
- private void collectInterTypeParentMungers(List collector) {
- for (Iterator iter = getDirectSupertypes(); iter.hasNext();) {
- ResolvedType superType = (ResolvedType) iter.next();
+ private void collectInterTypeParentMungers(List<ConcreteTypeMunger> collector) {
+ for (Iterator<ResolvedType> iter = getDirectSupertypes(); iter.hasNext();) {
+ ResolvedType superType = iter.next();
superType.collectInterTypeParentMungers(collector);
}
collector.addAll(getInterTypeParentMungers());
}
- protected void collectInterTypeMungers(List collector) {
- for (Iterator iter = getDirectSupertypes(); iter.hasNext();) {
- ResolvedType superType = (ResolvedType) iter.next();
+ protected void collectInterTypeMungers(List<ConcreteTypeMunger> collector) {
+ for (Iterator<ResolvedType> iter = getDirectSupertypes(); iter.hasNext();) {
+ ResolvedType superType = iter.next();
if (superType == null) {
throw new BCException("UnexpectedProblem: a supertype in the hierarchy for " + this.getName() + " is null");
}
superType.collectInterTypeMungers(collector);
}
- outer: for (Iterator iter1 = collector.iterator(); iter1.hasNext();) {
- ConcreteTypeMunger superMunger = (ConcreteTypeMunger) iter1.next();
+ outer: for (Iterator<ConcreteTypeMunger> iter1 = collector.iterator(); iter1.hasNext();) {
+ ConcreteTypeMunger superMunger = iter1.next();
if (superMunger.getSignature() == null)
continue;
continue;
}
- for (Iterator iter = getMethods(); iter.hasNext();) {
- ResolvedMember method = (ResolvedMember) iter.next();
+ for (Iterator<ResolvedMember> iter = getMethods(); iter.hasNext();) {
+ ResolvedMember method = iter.next();
if (conflictingSignature(method, superMunger.getSignature())) {
iter1.remove();
continue outer;
// ??? horribly inefficient
// for (Iterator i =
// System.err.println("lookup " + member + " in " + interTypeMungers);
- for (Iterator i = interTypeMungers.iterator(); i.hasNext();) {
- ConcreteTypeMunger m = (ConcreteTypeMunger) i.next();
+ for (ConcreteTypeMunger m : interTypeMungers) {
ResolvedMember ret = m.getMatchingSyntheticMember(member);
if (ret != null) {
// System.err.println(" found: " + ret);
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
// across the intertype declaration to the right type variables in the generic
// type upon which the itd is being made.
// might need serializing the class file for binary weaving.
- protected List /* String */typeVariableAliases;
+ protected List<String> typeVariableAliases;
- private Set /* resolvedMembers */superMethodsCalled = Collections.EMPTY_SET;
+ private Set<ResolvedMember> superMethodsCalled = Collections.emptySet();
private ISourceLocation location; // Lost during serialize/deserialize !
// ----
+ @Override
public String toString() {
return "ResolvedTypeMunger(" + getKind() + ", " + getSignature() + ")";
// .superMethodsCalled + ")";
}
}
- protected static Set readSuperMethodsCalled(VersionedDataInputStream s) throws IOException {
-
- Set ret = new HashSet();
+ protected static Set<ResolvedMember> readSuperMethodsCalled(VersionedDataInputStream s) throws IOException {
+ Set<ResolvedMember> ret = new HashSet<ResolvedMember>();
int n = s.readInt();
if (n < 0)
throw new BCException("Problem deserializing type munger");
return;
}
- List ret = new ArrayList(superMethodsCalled);
+ List<ResolvedMember> ret = new ArrayList<ResolvedMember>(superMethodsCalled);
Collections.sort(ret);
int n = ret.size();
s.writeInt(n);
- for (Iterator i = ret.iterator(); i.hasNext();) {
- ResolvedMember m = (ResolvedMember) i.next();
+ for (ResolvedMember m : ret) {
m.write(s);
}
throw new BCException("bad kind: " + key);
}
+ @Override
public String toString() {
// we want MethodDelegate to appear as Method in WeaveInfo messages
// TODO we may want something for fieldhost ?
public static final String SUPER_DISPATCH_NAME = "superDispatch";
- public void setSuperMethodsCalled(Set c) {
+ public void setSuperMethodsCalled(Set<ResolvedMember> c) {
this.superMethodsCalled = c;
}
- public Set getSuperMethodsCalled() {
+ public Set<ResolvedMember> getSuperMethodsCalled() {
return superMethodsCalled;
}
}
}
- protected static List readInTypeAliases(VersionedDataInputStream s) throws IOException {
+ protected static List<String> readInTypeAliases(VersionedDataInputStream s) throws IOException {
if (s.getMajorVersion() >= AjAttribute.WeaverVersionInfo.WEAVER_VERSION_MAJOR_AJ150) {
int count = s.readInt();
if (count != 0) {
- List aliases = new ArrayList();
+ List<String> aliases = new ArrayList<String>();
for (int i = 0; i < count; i++) {
aliases.add(s.readUTF());
}
s.writeInt(0);
} else {
s.writeInt(typeVariableAliases.size());
- for (Iterator iter = typeVariableAliases.iterator(); iter.hasNext();) {
- String element = (String) iter.next();
+ for (String element : typeVariableAliases) {
s.writeUTF(element);
}
}
}
- public List getTypeVariableAliases() {
+ public List<String> getTypeVariableAliases() {
return typeVariableAliases;
}
return true;
}
+ @Override
public Object accept(PatternNodeVisitor visitor, Object data) {
return visitor.visit(this, data);
}
+ @Override
public Declare parameterizeWith(Map typeVariableBindingMap, World w) {
DeclareParents ret = new DeclareParents(child.parameterizeWith(typeVariableBindingMap, w), parents.parameterizeWith(
typeVariableBindingMap, w), isExtends);
return ret;
}
+ @Override
public String toString() {
StringBuffer buf = new StringBuffer();
buf.append("declare parents: ");
return buf.toString();
}
+ @Override
public boolean equals(Object other) {
if (!(other instanceof DeclareParents))
return false;
}
// ??? cache this
+ @Override
public int hashCode() {
int result = 23;
result = 37 * result + child.hashCode();
return result;
}
+ @Override
public void write(DataOutputStream s) throws IOException {
s.writeByte(Declare.PARENTS);
child.write(s);
return false;
}
+ @Override
public void resolve(IScope scope) {
// ScopeWithTypeVariables resolutionScope = new ScopeWithTypeVariables(typeVariablesInScope,scope);
child = child.resolveBindings(scope, Bindings.NONE, false, false);
return this.isExtends;
}
+ @Override
public boolean isAdviceLike() {
return false;
}
return true;
}
- public List/* <ResolvedType> */findMatchingNewParents(ResolvedType onType, boolean reportErrors) {
+ public List<ResolvedType> findMatchingNewParents(ResolvedType onType, boolean reportErrors) {
if (onType.isRawType())
onType = onType.getGenericType();
if (!match(onType))
- return Collections.EMPTY_LIST;
+ return Collections.emptyList();
- List ret = new ArrayList();
+ List<ResolvedType> ret = new ArrayList<ResolvedType>();
for (int i = 0; i < parents.size(); i++) {
ResolvedType t = maybeGetNewParent(onType, parents.get(i), onType.getWorld(), reportErrors);
if (t != null)
return ret;
}
+ @Override
public String getNameSuffix() {
return "parents";
}
private World world;
+ @Override
public void setUp() {
world = getWorld();
}
}
protected void mungersTest(ResolvedType ty, ShadowMunger[] x) {
- TestUtil.assertSetEquals(ty + " mungers:", x, ty.getDeclaredShadowMungersArray());
+ List l = (List) ty.getDeclaredShadowMungers();
+ ShadowMunger[] array = (ShadowMunger[]) l.toArray(new ShadowMunger[l.size()]);
+ TestUtil.assertSetEquals(ty + " mungers:", x, array);
}
protected void interfaceTest(ResolvedType type, ResolvedType[] expectedInterfaces) {