]> source.dussan.org Git - aspectj.git/commitdiff
FIXED: Bugzilla Bug 32463
authorjhugunin <jhugunin>
Thu, 6 Mar 2003 00:24:39 +0000 (00:24 +0000)
committerjhugunin <jhugunin>
Thu, 6 Mar 2003 00:24:39 +0000 (00:24 +0000)
   ajc reports error when encountering static declaration of nested classes

tests/ajcTests.xml
tests/bugs/WeaveLocal.java [new file with mode: 0644]
tests/jimTests.xml
weaver/src/org/aspectj/weaver/NameMangler.java
weaver/src/org/aspectj/weaver/ResolvedTypeX.java
weaver/src/org/aspectj/weaver/TypeX.java
weaver/src/org/aspectj/weaver/patterns/WithinPointcut.java
weaver/testsrc/org/aspectj/weaver/TypeXTestCase.java

index df307d751d3f8b76546f24cdb8b162d2ab24b793..a432861313959eae0c6c1a815b002daa6b153830 100644 (file)
             <message kind="error" line="22"/>
         </compile>
     </ajc-test>
+    
+    <ajc-test dir="bugs" pr="33635" 
+               title="Negation of if pointcut does not work">
+        <compile files="NotIf.java"/>
+        <run class="NotIf"/>
+    </ajc-test>
+    
+    
+    <ajc-test dir="bugs" pr="32463" 
+               title="ajc reports error when encountering static declaration of nested classes">
+        <compile files="WeaveLocal.java"/>
+        <run class="WeaveLocal"/>
+    </ajc-test>
+    
 
 </suite>
diff --git a/tests/bugs/WeaveLocal.java b/tests/bugs/WeaveLocal.java
new file mode 100644 (file)
index 0000000..25c882a
--- /dev/null
@@ -0,0 +1,37 @@
+// for Bug#:  32463  
+import org.aspectj.testing.Tester;
+
+
+public class WeaveLocal
+{
+    // Commenting out the static declaration makes everything work OK
+    static
+    {
+        class StaticNestedClass
+        {
+        }
+    }
+    
+    public static void main(String[] args)
+    {
+      System.out.println(new WeaveLocal().handleOrder("test"));
+    }
+
+    private String handleOrder(String t)
+    {
+      return t;
+    }
+
+}
+
+aspect A  {
+
+    pointcut withinTest(): within(WeaveLocal);
+    pointcut callToHandleOrder() : (withinTest() &&
+                             call(* handleOrder(..)));
+
+    Object around(): callToHandleOrder() {
+
+      return "DUMMY inserted by ASPECT" ;
+   }
+}
index 6306ec843a79d56a676d3b942f82100799aa7da3..b8771ef2a2d66ff388462387dc824de774e1c913 100644 (file)
@@ -1,12 +1,7 @@
 <!DOCTYPE suite SYSTEM "../tests/ajcTestSuite.dtd">
 <suite>
 
-    <ajc-test dir="bugs" pr="33635" 
-               title="Negation of if pointcut does not work">
-        <compile files="NotIf.java"/>
-        <run class="NotIf"/>
-    </ajc-test>
-    
+
     
     <!--
     
index d554fc43d71fe285fd02cf318613809b0a28e4a3..823eaf21558f391667ec3a3a1cbffe8fdeb9adb2 100644 (file)
@@ -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)) {
index cfce3b03cf401e7afc5e6b82d221dfd10745927b..2123acf8e12db502e94f16f32b5717afafcd829f 100644 (file)
@@ -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
index 6b1443be06ef880529da18d36bf3ce927fbe3532..f5bab0db3dc55efb51e2c3b56221acc76e3125a6 100644 (file)
@@ -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;
                }
     }
 
index 3a6db4becebe98177a17c855f258caef59db320f..c3ddb5f191dbea98d7672c894acae6752795df20 100644 (file)
@@ -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();
index cc1af29c61a3cf84fc1863b9116698be32fa7991..19b3647928d7e7dcfdb1defdcc49176ba304d93b 100644 (file)
@@ -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) {