From: aclement Date: Sat, 7 Nov 2009 17:26:13 +0000 (+0000) Subject: more helpers X-Git-Tag: V1_6_7~135 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=18841492728279293ed715acf62f9197791899cf;p=aspectj.git more helpers --- diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/ResolvedType.java b/org.aspectj.matcher/src/org/aspectj/weaver/ResolvedType.java index 341740667..eb001983d 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/ResolvedType.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/ResolvedType.java @@ -204,6 +204,28 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl return Iterators.mapOver(Iterators.recur(this, typeGetter), fieldGetter); } + /** + * returns an iterator through all of the methods of this type, in order for checking from JVM spec 2ed 5.4.3.3. This means that + * the order is + *

+ *

+ *

+ * + * @param wantGenerics is true if the caller would like all generics information, otherwise those methods are collapsed to their + * erasure + */ + public Iterator getMethods(boolean wantGenerics) { + return Iterators.mapOver(getHierarchy(wantGenerics, false), MethodGetterInstance); + } + + public Iterator getMethodsIncludingIntertypeDeclarations(boolean wantGenerics) { + return Iterators.mapOver(getHierarchy(wantGenerics, false), MethodGetterWithItdsInstance); + } + /** * An Iterators.Getter that returns an iterator over all methods declared on some resolved type. */ @@ -478,6 +500,20 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl return methods; } + /** + * Return a list of the types in the hierarchy of this type, starting with this type. The order in the list is the superclasses + * followed by the super interfaces. + * + * @param genericsAware should the list include parameterized/generic types (if not, they will be collapsed to raw)? + * @return list of resolvedtypes in this types hierarchy, including this type first + */ + public List getHierarchyWithoutIterator(boolean includeITDs, boolean allowMissing, boolean genericsAware) { + List types = new ArrayList(); + Set visited = new HashSet(); + recurseHierarchy(visited, types, this, includeITDs, allowMissing, genericsAware); + return types; + } + private void addAndRecurse(Set knowninterfaces, List collector, ResolvedType resolvedType, boolean includeITDs, boolean allowMissing, boolean genericsAware) { // Add the methods declared on this type @@ -535,6 +571,56 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl } } + /** + * Recurse up a type hierarchy, first the superclasses then the super interfaces. + */ + private void recurseHierarchy(Set knowninterfaces, List collector, ResolvedType resolvedType, + boolean includeITDs, boolean allowMissing, boolean genericsAware) { + collector.add(resolvedType); + if (!resolvedType.isInterface() && !resolvedType.equals(ResolvedType.OBJECT)) { + ResolvedType superType = resolvedType.getSuperclass(); + if (superType != null && !superType.isMissing()) { + if (!genericsAware && (superType.isParameterizedType() || superType.isGenericType())) { + superType = superType.getRawType(); + } + // Recurse if we are not at the top + recurseHierarchy(knowninterfaces, collector, superType, includeITDs, allowMissing, genericsAware); + } + } + // Go through the interfaces on the way back down + ResolvedType[] interfaces = resolvedType.getDeclaredInterfaces(); + for (int i = 0; i < interfaces.length; i++) { + ResolvedType iface = interfaces[i]; + if (!genericsAware && (iface.isParameterizedType() || iface.isGenericType())) { + iface = iface.getRawType(); + } + // we need to know if it is an interface from Parent kind munger + // as those are used for @AJ ITD and we precisely want to skip those + boolean shouldSkip = false; + for (int j = 0; j < resolvedType.interTypeMungers.size(); j++) { + ConcreteTypeMunger munger = resolvedType.interTypeMungers.get(j); + if (munger.getMunger() != null && munger.getMunger().getKind() == ResolvedTypeMunger.Parent + && ((NewParentTypeMunger) munger.getMunger()).getNewParent().equals(iface) // pr171953 + ) { + shouldSkip = true; + break; + } + } + + // Do not do interfaces more than once + if (!shouldSkip && !knowninterfaces.contains(iface.getSignature())) { + knowninterfaces.add(iface.getSignature()); + if (allowMissing && iface.isMissing()) { + if (iface instanceof MissingResolvedTypeWithKnownSignature) { + ((MissingResolvedTypeWithKnownSignature) iface).raiseWarningOnMissingInterfaceWhilstFindingMethods(); + } + } else { + recurseHierarchy(knowninterfaces, collector, iface, includeITDs, allowMissing, genericsAware); + } + } + } + } + public ResolvedType[] getResolvedTypeParameters() { if (resolvedTypeParams == null) { resolvedTypeParams = world.resolve(typeParameters); @@ -1743,8 +1829,7 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl // generic type // is discovered and the tvar is collapsed to a bound? munger = fillInAnyTypeParameters(munger); - sig = munger.getSignature(); // possibly changed when type parms filled - // in + sig = munger.getSignature(); // possibly changed when type parms filled in // System.err.println("add: " + munger + " to " + this.getClassName() + // " with " + interTypeMungers);