diff options
-rw-r--r-- | bcel-builder/src/org/aspectj/apache/bcel/classfile/JavaClass.java | 38 | ||||
-rw-r--r-- | bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/AnonymousClassTest.java | 5 | ||||
-rw-r--r-- | lib/bcel/bcel-src.zip | bin | 865964 -> 871596 bytes | |||
-rw-r--r-- | lib/bcel/bcel.jar | bin | 594359 -> 594624 bytes |
4 files changed, 33 insertions, 10 deletions
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/JavaClass.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/JavaClass.java index 2a1bf1526..e019947f5 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/JavaClass.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/JavaClass.java @@ -77,7 +77,7 @@ import java.util.StringTokenizer; * class file. Those interested in programatically generating classes * should see the <a href="../generic/ClassGen.html">ClassGen</a> class. - * @version $Id: JavaClass.java,v 1.8 2005/11/04 13:06:27 acolyer Exp $ + * @version $Id: JavaClass.java,v 1.9 2005/12/02 06:56:14 acolyer Exp $ * @see org.aspectj.apache.bcel.generic.ClassGen * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> */ @@ -99,6 +99,9 @@ public class JavaClass extends AccessFlags implements Cloneable, Node { private Annotation[] annotations; // annotations defined on the class private byte source = HEAP; // Generated in memory private boolean isGeneric = false; + private boolean isAnonymous = false; + private boolean isNested = false; + private boolean computedNestedTypeStatus = false; public static final byte HEAP = 1; public static final byte FILE = 2; @@ -724,21 +727,38 @@ public class JavaClass extends AccessFlags implements Cloneable, Node { } public final boolean isAnonymous() { + computeNestedTypeStatus(); + return this.isAnonymous; + } + + public final boolean isNested() { + computeNestedTypeStatus(); + return this.isNested; + } + + private final void computeNestedTypeStatus() { + if (computedNestedTypeStatus) return; for (int i = 0; i < this.attributes.length; i++) { - if (this.attributes[i] instanceof InnerClasses) { - InnerClass[] innerClasses = ((InnerClasses) this.attributes[i]).getInnerClasses(); - for (int j = 0; j < innerClasses.length; j++) { - if (innerClasses[j].getInnerNameIndex() == 0) { - // this is an anonymous class, but is it me, or a class contained in me?? + if (this.attributes[i] instanceof InnerClasses) { + InnerClass[] innerClasses = ((InnerClasses) this.attributes[i]).getInnerClasses(); + for (int j = 0; j < innerClasses.length; j++) { + boolean innerClassAttributeRefersToMe = false; String inner_class_name = constant_pool.getConstantString(innerClasses[j].getInnerClassIndex(), Constants.CONSTANT_Class); inner_class_name = Utility.compactClassName(inner_class_name); - if (inner_class_name.equals(getClassName())) return true; + if (inner_class_name.equals(getClassName())) { + innerClassAttributeRefersToMe = true; + } + if (innerClassAttributeRefersToMe) { + this.isNested = true; + if (innerClasses[j].getInnerNameIndex() == 0) { + this.isAnonymous = true; + } + } } } - } } - return false; + this.computedNestedTypeStatus = true; } // J5SUPPORT: diff --git a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/AnonymousClassTest.java b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/AnonymousClassTest.java index 34cc01352..4a9bc0a3f 100644 --- a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/AnonymousClassTest.java +++ b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/AnonymousClassTest.java @@ -30,22 +30,25 @@ public class AnonymousClassTest extends TestCase { public void testRegularClassIsNotAnonymous() throws ClassNotFoundException { JavaClass clazz = repos.loadClass("AnonymousClassTest"); assertFalse("regular outer classes are not anonymous",clazz.isAnonymous()); + assertFalse("regular outer classes are not nested",clazz.isNested()); } public void testNamedInnerClassIsNotAnonymous() throws ClassNotFoundException { JavaClass clazz = repos.loadClass("AnonymousClassTest$X"); assertFalse("regular inner classes are not anonymous",clazz.isAnonymous()); + assertTrue("regular inner classes are nested",clazz.isNested()); } public void testStaticInnerClassIsNotAnonymous() throws ClassNotFoundException { JavaClass clazz = repos.loadClass("AnonymousClassTest$Y"); assertFalse("regular static inner classes are not anonymous",clazz.isAnonymous()); + assertTrue("regular static inner classes are nested",clazz.isNested()); } public void testAnonymousInnerClassIsAnonymous() throws ClassNotFoundException { JavaClass clazz = repos.loadClass("AnonymousClassTest$1"); assertTrue("anonymous inner classes are anonymous",clazz.isAnonymous()); - + assertTrue("anonymous inner classes are anonymous",clazz.isNested()); } protected void setUp() throws Exception { diff --git a/lib/bcel/bcel-src.zip b/lib/bcel/bcel-src.zip Binary files differindex 02a8ca37c..731fd2e0d 100644 --- a/lib/bcel/bcel-src.zip +++ b/lib/bcel/bcel-src.zip diff --git a/lib/bcel/bcel.jar b/lib/bcel/bcel.jar Binary files differindex fe3553cb2..bbce85087 100644 --- a/lib/bcel/bcel.jar +++ b/lib/bcel/bcel.jar |