]> source.dussan.org Git - aspectj.git/commitdiff
fix and moved test for Bugzilla Bug 39711
authorjhugunin <jhugunin>
Thu, 24 Jul 2003 21:37:04 +0000 (21:37 +0000)
committerjhugunin <jhugunin>
Thu, 24 Jul 2003 21:37:04 +0000 (21:37 +0000)
   Class Literals as non final fields

tests/ajcTests.xml
tests/ajcTestsFailing.xml
weaver/src/org/aspectj/weaver/ResolvedMember.java
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
weaver/src/org/aspectj/weaver/bcel/BcelField.java
weaver/src/org/aspectj/weaver/bcel/BcelMethod.java

index a7c73d20dc93c0369b3eb60106a9ede2e6bd7a6a..5cccbc37b9d82b9f66ce2ac91796453ee4369b4c 100644 (file)
         <compile files="CloneMethod.java"/>
         <run class="CloneMethod"/>
     </ajc-test>
+    
+    <ajc-test dir="bugs" pr="39711"
+        title="Class Literals as non final fields (also assert, and this$0)">
+        <compile files="ClassLiteralField.java" options="-source14"/>
+        <run class="ClassLiteralField"/>
+    </ajc-test>
 </suite>
index cd8e52f6e1cf03fa8c87e16ddbc371cb14398124..ddc6cc1ddd704900dbb799d2e7a47a8a9e6696ea 100644 (file)
@@ -4,9 +4,5 @@
 <!-- contains valid tests that the compiler has never passed -->
 
 <suite>
-    <ajc-test dir="bugs" pr="39711"
-        title="Class Literals as non final fields (also assert, and this$0)">
-        <compile files="ClassLiteralField.java" options="-source14"/>
-        <run class="ClassLiteralField"/>
-    </ajc-test>
+
 </suite>
index b457db0b488cea29b5586f0d5e3eb23da6dd06cf..60164e167be27ae490f7d2fce5f643816f1fc2e0 100644 (file)
@@ -88,6 +88,10 @@ public class ResolvedMember extends Member implements IHasPosition {
        return true;
     }
     
+       public boolean isSynthetic() {
+               return false;
+       }
+    
     public void write(DataOutputStream s) throws IOException {
        getKind().write(s);
        getDeclaringType().write(s);
@@ -194,6 +198,5 @@ public class ResolvedMember extends Member implements IHasPosition {
        public void setCheckedExceptions(TypeX[] checkedExceptions) {
                this.checkedExceptions = checkedExceptions;
        }
-
 }
    
index 97c8fbdaed352e9e7d82a2e314659ca3e5eb46bd..5595b45db06c5c59f982d6728a4f9673302e4b3c 100644 (file)
@@ -833,9 +833,7 @@ class BcelClassWeaver implements IClassWeaver {
                Instruction i = ih.getInstruction();
                if (i instanceof FieldInstruction) {
                        FieldInstruction fi = (FieldInstruction) i;
-                       
-
-                       
+                                               
                        if (i instanceof PUTFIELD || i instanceof PUTSTATIC) {
                                // check for sets of constant fields.  We first check the previous 
                                // instruction.  If the previous instruction is a LD_WHATEVER (push
@@ -852,19 +850,13 @@ class BcelClassWeaver implements IClassWeaver {
                                                // it's final, so it's the set of a final constant, so it's
                                                // not a join point according to 1.0.6 and 1.1.
                                        } else {
-                                               match(
-                                                       BcelShadow.makeFieldSet(world, mg, ih, enclosingShadow),
-                                                       shadowAccumulator);
+                                               matchSetInstruction(mg, ih, enclosingShadow, shadowAccumulator);
                                        }                                               
                                } else {
-                                       match(
-                                               BcelShadow.makeFieldSet(world, mg, ih, enclosingShadow),
-                                               shadowAccumulator);
+                                       matchSetInstruction(mg, ih, enclosingShadow, shadowAccumulator);
                                }
                        } else {
-                               match(
-                                       BcelShadow.makeFieldGet(world, mg, ih, enclosingShadow),
-                                       shadowAccumulator);
+                               matchGetInstruction(mg, ih, enclosingShadow, shadowAccumulator);
                        }
                } else if (i instanceof InvokeInstruction) {
                        InvokeInstruction ii = (InvokeInstruction) i;
@@ -907,6 +899,43 @@ class BcelClassWeaver implements IClassWeaver {
                }
        }
 
+
+       private void matchSetInstruction(LazyMethodGen mg, InstructionHandle ih, BcelShadow enclosingShadow, List shadowAccumulator) {
+               FieldInstruction fi = (FieldInstruction) ih.getInstruction();
+               Member field = world.makeFieldSignature(clazz, fi);
+               ResolvedMember resolvedField = field.resolve(world);
+               if (resolvedField == null) {
+                       // we can't find the field, so it's not a join point.
+                       return;
+               } else if (Modifier.isFinal(resolvedField.getModifiers()) && 
+                                       Utility.isConstantPushInstruction(ih.getPrev().getInstruction()))
+               {
+                       // it's the set of a final constant, so it's
+                       // not a join point according to 1.0.6 and 1.1.
+                       return;
+               } else if (resolvedField.isSynthetic()) {
+                       // sets of synthetics aren't join points in 1.1
+                       return;
+               } else {
+                       match(BcelShadow.makeFieldSet(world, mg, ih, enclosingShadow), shadowAccumulator);
+               }
+       }
+
+       private void matchGetInstruction(LazyMethodGen mg, InstructionHandle ih, BcelShadow enclosingShadow, List shadowAccumulator) {
+               FieldInstruction fi = (FieldInstruction) ih.getInstruction();
+               Member field = world.makeFieldSignature(clazz, fi);
+               ResolvedMember resolvedField = field.resolve(world);
+               if (resolvedField == null) {
+                       // we can't find the field, so it's not a join point.
+                       return;
+               } else if (resolvedField.isSynthetic()) {
+                       // sets of synthetics aren't join points in 1.1
+                       return;
+               } else {
+                       match(BcelShadow.makeFieldGet(world, mg, ih, enclosingShadow), shadowAccumulator);
+               }
+       }
+
        private void matchInvokeInstruction(LazyMethodGen mg,
                InstructionHandle ih,
                InvokeInstruction invoke,
index 72cc5bd0f6d07c249a3d19c67b067722ff1b7371..f4b93d952c727acb214107ebcc7bf6675516d49b 100644 (file)
@@ -16,7 +16,9 @@ package org.aspectj.weaver.bcel;
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.bcel.classfile.Attribute;
 import org.apache.bcel.classfile.Field;
+import org.apache.bcel.classfile.Synthetic;
 import org.aspectj.weaver.AjAttribute;
 import org.aspectj.weaver.BCException;
 import org.aspectj.weaver.ResolvedMember;
@@ -27,6 +29,7 @@ final class BcelField extends ResolvedMember {
 
        private Field field;
        private boolean isAjSynthetic;
+       private boolean isSynthetic = false;
 
        BcelField(BcelObjectType declaringType, Field field) {
                super(
@@ -43,7 +46,8 @@ final class BcelField extends ResolvedMember {
        // ----
        
        private void unpackAttributes(World world) {
-               List as = BcelAttributes.readAjAttributes(field.getAttributes(), getSourceContext(world));
+               Attribute[] attrs = field.getAttributes();
+               List as = BcelAttributes.readAjAttributes(attrs, getSourceContext(world));
                for (Iterator iter = as.iterator(); iter.hasNext();) {
                        AjAttribute a = (AjAttribute) iter.next();
                        if (a instanceof AjAttribute.AjSynthetic) {
@@ -53,9 +57,20 @@ final class BcelField extends ResolvedMember {
                        }
                }
                isAjSynthetic = false;
+               
+               
+               for (int i = attrs.length - 1; i >= 0; i--) {
+                       if (attrs[i] instanceof Synthetic) isSynthetic = true;
+               }
        }
+       
+       
 
        public boolean isAjSynthetic() {
                return isAjSynthetic; // || getName().startsWith(NameMangler.PREFIX);
        }
+       
+       public boolean isSynthetic() {
+               return isSynthetic;
+       }
 }
index 788258010a500494d74d744b84a55169b984cbd2..a2a4a5fc28e8750b5cce038c36e65a794a077c4b 100644 (file)
@@ -103,6 +103,8 @@ final class BcelMethod extends ResolvedMember {
                return isAjSynthetic; // || getName().startsWith(NameMangler.PREFIX);
        }
        
+       //FIXME needs an isSynthetic method
+       
        public ShadowMunger getAssociatedShadowMunger() {
                return associatedShadowMunger;
        }