diff options
author | jhugunin <jhugunin> | 2003-03-06 00:24:39 +0000 |
---|---|---|
committer | jhugunin <jhugunin> | 2003-03-06 00:24:39 +0000 |
commit | d1e5c0a57c5da220b8f7357550db84f1009dbe2e (patch) | |
tree | 2d6477529a9b1783f66cd52010e0fd2ef0df43fc /weaver | |
parent | 3556a2a33100520c708c71b786e87f086234ddfa (diff) | |
download | aspectj-d1e5c0a57c5da220b8f7357550db84f1009dbe2e.tar.gz aspectj-d1e5c0a57c5da220b8f7357550db84f1009dbe2e.zip |
FIXED: Bugzilla Bug 32463
ajc reports error when encountering static declaration of nested classes
Diffstat (limited to 'weaver')
-rw-r--r-- | weaver/src/org/aspectj/weaver/NameMangler.java | 9 | ||||
-rw-r--r-- | weaver/src/org/aspectj/weaver/ResolvedTypeX.java | 30 | ||||
-rw-r--r-- | weaver/src/org/aspectj/weaver/TypeX.java | 29 | ||||
-rw-r--r-- | weaver/src/org/aspectj/weaver/patterns/WithinPointcut.java | 5 | ||||
-rw-r--r-- | weaver/testsrc/org/aspectj/weaver/TypeXTestCase.java | 4 |
5 files changed, 43 insertions, 34 deletions
diff --git a/weaver/src/org/aspectj/weaver/NameMangler.java b/weaver/src/org/aspectj/weaver/NameMangler.java index d554fc43d..823eaf215 100644 --- a/weaver/src/org/aspectj/weaver/NameMangler.java +++ b/weaver/src/org/aspectj/weaver/NameMangler.java @@ -268,16 +268,9 @@ public class NameMangler { // ---- - private static TypeX getOutermostType(TypeX type) { - TypeX outerType = type.getDeclaringType(); - if (outerType == null) return type; - return getOutermostType(outerType); - } - - private static String makeVisibilityName(int modifiers, TypeX aspectType) { if (Modifier.isPrivate(modifiers)) { - return getOutermostType(aspectType).getNameAsIdentifier(); + return aspectType.getOutermostType().getNameAsIdentifier(); } else if (Modifier.isProtected(modifiers)) { throw new RuntimeException("protected inter-types not allowed"); } else if (Modifier.isPublic(modifiers)) { diff --git a/weaver/src/org/aspectj/weaver/ResolvedTypeX.java b/weaver/src/org/aspectj/weaver/ResolvedTypeX.java index cfce3b03c..2123acf8e 100644 --- a/weaver/src/org/aspectj/weaver/ResolvedTypeX.java +++ b/weaver/src/org/aspectj/weaver/ResolvedTypeX.java @@ -792,11 +792,29 @@ public abstract class ResolvedTypeX extends TypeX { return interTypeMungers; } - private static ResolvedTypeX getOutermostType(ResolvedTypeX t) { - TypeX dec = t.getDeclaringType(); - if (dec == null) return t; - return getOutermostType(dec.resolve(t.getWorld())); - } + /** + * Returns a ResolvedTypeX object representing the declaring type of this type, or + * null if this type does not represent a non-package-level-type. + * + * <strong>Warning</strong>: This is guaranteed to work for all member types. + * For anonymous/local types, the only guarantee is given in JLS 13.1, where + * it guarantees that if you call getDeclaringType() repeatedly, you will eventually + * get the top-level class, but it does not say anything about classes in between. + * + * @return the declaring TypeX object, or null. + */ + public ResolvedTypeX getDeclaringType() { + if (isArray()) return null; + String name = getName(); + int lastDollar = name.lastIndexOf('$'); + while (lastDollar != -1) { + ResolvedTypeX ret = world.resolve(TypeX.forName(name.substring(0, lastDollar)), true); + if (ret != ResolvedTypeX.MISSING) return ret; + lastDollar = name.lastIndexOf('$', lastDollar-1); + } + return null; + } + public static boolean isVisible(int modifiers, ResolvedTypeX targetType, ResolvedTypeX fromType) { //System.err.println("mod: " + modifiers + ", " + targetType + " and " + fromType); @@ -804,7 +822,7 @@ public abstract class ResolvedTypeX extends TypeX { if (Modifier.isPublic(modifiers)) { return true; } else if (Modifier.isPrivate(modifiers)) { - return getOutermostType(targetType).equals(getOutermostType(fromType)); + return targetType.getOutermostType().equals(fromType.getOutermostType()); } else if (Modifier.isProtected(modifiers)) { return samePackage(targetType, fromType) || targetType.isAssignableFrom(fromType); } else { // package-visible diff --git a/weaver/src/org/aspectj/weaver/TypeX.java b/weaver/src/org/aspectj/weaver/TypeX.java index 6b1443be0..f5bab0db3 100644 --- a/weaver/src/org/aspectj/weaver/TypeX.java +++ b/weaver/src/org/aspectj/weaver/TypeX.java @@ -249,26 +249,23 @@ public class TypeX { public final boolean isArray() { return signature.startsWith("["); } - + /** - * Returns a TypeX object representing the declaring type of this type, or - * null if this type does not represent a non-package-level-type. + * Returns a TypeX object representing the effective outermost enclosing type + * for a name type. For all other types, this will return the type itself. * - * <strong>Warning</strong>: This is guaranteed to work for all member types. - * For anonymous/local types, the only guarantee is given in JLS 13.1, where - * it guarantees that if you call getDeclaringType() repeatedly, you will eventually - * get the top-level class, but it does not say anything about classes in between. - * - * @return the declaring TypeX object, or null. + * The only guarantee is given in JLS 13.1 where code generated according to + * those rules will have type names that can be split apart in this way. + * @return the outermost enclosing TypeX object or this. */ - public TypeX getDeclaringType() { - if (isArray()) return null; - String name = getName(); - int lastDollar = name.lastIndexOf('$'); - if (lastDollar != -1) { - return TypeX.forName(name.substring(0, lastDollar)); + public TypeX getOutermostType() { + if (isArray() || isPrimitive()) return this; + String sig = getSignature(); + int dollar = sig.indexOf('$'); + if (dollar != -1) { + return TypeX.forSignature(sig.substring(0, dollar) + ';'); } else { - return null; + return this; } } diff --git a/weaver/src/org/aspectj/weaver/patterns/WithinPointcut.java b/weaver/src/org/aspectj/weaver/patterns/WithinPointcut.java index 3a6db4bec..c3ddb5f19 100644 --- a/weaver/src/org/aspectj/weaver/patterns/WithinPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/WithinPointcut.java @@ -34,13 +34,14 @@ public class WithinPointcut extends Pointcut { } public FuzzyBoolean match(Shadow shadow) { - TypeX enclosingType = shadow.getEnclosingType(); + ResolvedTypeX enclosingType = shadow.getIWorld().resolve(shadow.getEnclosingType()); + //System.err.println("enclosingType: " + enclosingType); // if (shadow.getKind() == Shadow.FieldSet) { // System.err.println("within?" + type + " matches " + enclosingType + " on " + shadow); // } while (enclosingType != null) { - if (type.matchesStatically(shadow.getIWorld().resolve(enclosingType))) { + if (type.matchesStatically(enclosingType)) { return FuzzyBoolean.YES; } enclosingType = enclosingType.getDeclaringType(); diff --git a/weaver/testsrc/org/aspectj/weaver/TypeXTestCase.java b/weaver/testsrc/org/aspectj/weaver/TypeXTestCase.java index cc1af29c6..19b364792 100644 --- a/weaver/testsrc/org/aspectj/weaver/TypeXTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/TypeXTestCase.java @@ -58,8 +58,8 @@ public class TypeXTestCase extends TestCase { TypeX t = TypeX.forName("java.util.Map$Entry"); assertEquals(t.getName(), "java.util.Map$Entry"); assertEquals(t.getSignature(), "Ljava/util/Map$Entry;"); - assertEquals(t.getDeclaringType(), TypeX.forName("java.util.Map")); - assertNull(TypeX.forName("java.util.Map").getDeclaringType()); + assertEquals(t.getOutermostType(), TypeX.forName("java.util.Map")); + assertEquals(TypeX.forName("java.util.Map").getOutermostType(), TypeX.forName("java.util.Map")); } private void isPrimitiveTest(TypeX[] types, boolean[] isPrimitives) { |