From 65a862c8cad5b62b2b37a588f1c4db5e14340b84 Mon Sep 17 00:00:00 2001 From: aclement Date: Sat, 7 Nov 2009 18:29:27 +0000 Subject: [PATCH] more helpers --- .../src/org/aspectj/weaver/ResolvedType.java | 99 +++++++++---------- 1 file changed, 46 insertions(+), 53 deletions(-) diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/ResolvedType.java b/org.aspectj.matcher/src/org/aspectj/weaver/ResolvedType.java index eb001983d..20a22972b 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/ResolvedType.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/ResolvedType.java @@ -66,8 +66,6 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl this.world = world; } - // ---- things that don't require a world - /** * 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. @@ -193,15 +191,10 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl final Iterators.Filter dupFilter = Iterators.dupFilter(); Iterators.Getter typeGetter = new Iterators.Getter() { public Iterator get(ResolvedType o) { - return dupFilter.filter((o).getDirectSupertypes()); - } - }; - Iterators.Getter fieldGetter = new Iterators.Getter() { - public Iterator get(ResolvedType o) { - return Iterators.array((o).getDeclaredFields()); + return dupFilter.filter(o.getDirectSupertypes()); } }; - return Iterators.mapOver(Iterators.recur(this, typeGetter), fieldGetter); + return Iterators.mapOver(Iterators.recur(this, typeGetter), FieldGetterInstance); } /** @@ -287,50 +280,6 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl private final static PointcutGetter PointcutGetterInstance = new PointcutGetter(); private final static FieldGetter FieldGetterInstance = new 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 - *

- *

    - *
  • methods from current class
  • - *
  • recur into superclass, all the way up, not touching interfaces
  • - *
  • recur into all superinterfaces, in some unspecified order
  • - *
- *

- * 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(ResolvedType o) { - return dupFilter.filter(Iterators.array(o.getDeclaredInterfaces())); - } - }; - Iterators.Getter methodGetter = new Iterators.Getter() { - public Iterator get(ResolvedType o) { - return Iterators.array((o).getDeclaredMethods()); - } - }; - return Iterators.mapOver(Iterators.append(new Iterator() { - ResolvedType curr = ResolvedType.this; - - public boolean hasNext() { - return curr != null; - } - - public ResolvedType next() { - ResolvedType ret = curr; - curr = curr.getSuperclass(); - return ret; - } - - public void remove() { - throw new UnsupportedOperationException(); - } - }, Iterators.recur(this, ifaceGetter)), methodGetter); - } - /** * Return an iterator over the types in this types hierarchy - starting with this type first, then all superclasses up to Object * and then all interfaces (starting with those 'nearest' this type). @@ -480,6 +429,50 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl } } + /** + * 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 + *

+ *

    + *
  • methods from current class
  • + *
  • recur into superclass, all the way up, not touching interfaces
  • + *
  • recur into all superinterfaces, in some unspecified order
  • + *
+ *

+ * 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(ResolvedType o) { + return dupFilter.filter(Iterators.array(o.getDeclaredInterfaces())); + } + }; + Iterators.Getter methodGetter = new Iterators.Getter() { + public Iterator get(ResolvedType o) { + return Iterators.array((o).getDeclaredMethods()); + } + }; + return Iterators.mapOver(Iterators.append(new Iterator() { + ResolvedType curr = ResolvedType.this; + + public boolean hasNext() { + return curr != null; + } + + public ResolvedType next() { + ResolvedType ret = curr; + curr = curr.getSuperclass(); + return ret; + } + + public void remove() { + throw new UnsupportedOperationException(); + } + }, Iterators.recur(this, ifaceGetter)), methodGetter); + } + /** * Return a list of methods, first those declared on this class, then those declared on the superclass (recurse) and then those * declared on the superinterfaces. The getMethods() call above doesn't quite work the same as it will (through the iterator) -- 2.39.5