]> source.dussan.org Git - aspectj.git/commitdiff
129163: first part: changed comparison code to ignore ajc$/hasaspect/aspectof in...
authoraclement <aclement>
Mon, 6 Mar 2006 16:09:23 +0000 (16:09 +0000)
committeraclement <aclement>
Mon, 6 Mar 2006 16:09:23 +0000 (16:09 +0000)
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceType.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjState.java
weaver/src/org/aspectj/weaver/NameMangler.java
weaver/src/org/aspectj/weaver/ResolvedTypeMunger.java
weaver/src/org/aspectj/weaver/bcel/BcelCflowCounterFieldAdder.java
weaver/src/org/aspectj/weaver/bcel/BcelCflowStackFieldAdder.java
weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java

index 3f2aab4e95bde2d2d169b38b04a60c4e17a30ea0..18380cbe60be7299ed3505f4b5ea74b458a0cee6 100644 (file)
@@ -226,11 +226,21 @@ public class EclipseSourceType extends AbstractReferenceTypeDelegate {
                return resolvedPointcutDeclaration;
        }
 
+       /**
+        * This method may not return all fields, for example it may
+        * not include the ajc$initFailureCause or ajc$perSingletonInstance
+        * fields - see bug 129613
+        */
        public ResolvedMember[] getDeclaredFields() {
                if (declaredFields == null) fillDeclaredMembers();
                return declaredFields;
        }
 
+       /**
+        * This method may not return all methods, for example it may
+        * not include clinit, aspectOf, hasAspect or ajc$postClinit 
+        * methods - see bug 129613
+        */
        public ResolvedMember[] getDeclaredMethods() {
                if (declaredMethods == null) fillDeclaredMembers();
                return declaredMethods;
index 799130ba233088aec83d38a8cbcbd78d5cda6ee9..679d0c6bfd4c90af42c31f2a52191187bc084b0f 100644 (file)
@@ -34,6 +34,7 @@ import org.aspectj.asm.IRelationshipMap;
 import org.aspectj.bridge.IMessage;
 import org.aspectj.bridge.Message;
 import org.aspectj.bridge.SourceLocation;
+import org.aspectj.org.eclipse.jdt.core.compiler.CharOperation;
 import org.aspectj.org.eclipse.jdt.internal.compiler.CompilationResult;
 import org.aspectj.org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
 import org.aspectj.org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
@@ -44,6 +45,7 @@ import org.aspectj.org.eclipse.jdt.internal.core.builder.ReferenceCollection;
 import org.aspectj.org.eclipse.jdt.internal.core.builder.StringSet;
 import org.aspectj.util.FileUtil;
 import org.aspectj.weaver.IWeaver;
+import org.aspectj.weaver.NameMangler;
 import org.aspectj.weaver.ReferenceType;
 import org.aspectj.weaver.ResolvedMember;
 import org.aspectj.weaver.ResolvedType;
@@ -816,12 +818,12 @@ public class AjState {
                }
                
                // generic signature
-               if (!equal(reader.getGenericSignature(),existingType.genericSignature)) {
+               if (!CharOperation.equals(reader.getGenericSignature(),existingType.genericSignature)) {
                        return true;
                }
                
                // superclass name
-               if (!equal(reader.getSuperclassName(),existingType.superclassName)) {
+               if (!CharOperation.equals(reader.getSuperclassName(),existingType.superclassName)) {
                        return true;
                }
                
@@ -835,7 +837,7 @@ public class AjState {
                }
                new_interface_loop: for (int i = 0; i < newIfs.length; i++) {
                        for (int j = 0; j < existingIfs.length; j++) {
-                               if (equal(existingIfs[j],newIfs[i])) {
+                               if (CharOperation.equals(existingIfs[j],newIfs[i])) {
                                        continue new_interface_loop;
                                }
                        }
@@ -846,17 +848,27 @@ public class AjState {
                MemberStructure[] existingFields = existingType.fields;
                IBinaryField[] newFields = reader.getFields();
                if (newFields == null) { newFields = new IBinaryField[0]; }
-               if (newFields.length != existingFields.length) {
+               // remove any ajc$XXX fields from those we compare with
+               // the existing fields - bug 129163
+               List nonGenFields = new ArrayList();
+               for (int i = 0; i < newFields.length; i++) {
+                       IBinaryField field = newFields[i];
+                       if (!CharOperation.prefixEquals(NameMangler.AJC_DOLLAR_PREFIX,field.getName())) {
+                                       nonGenFields.add(field);
+                       }
+               }
+               if (nonGenFields.size() != existingFields.length) {
                        return true;
                }
-               new_field_loop: for (int i = 0; i < newFields.length; i++) {
-                       char[] fieldName = newFields[i].getName();
+               new_field_loop: for (Iterator iter = nonGenFields.iterator(); iter.hasNext();) {
+                       IBinaryField field = (IBinaryField) iter.next();
+                       char[] fieldName = field.getName();
                        for (int j = 0; j < existingFields.length; j++) {
-                               if (equal(existingFields[j].name,fieldName)) {
-                                       if (!modifiersEqual(newFields[i].getModifiers(),existingFields[j].modifiers)) {
+                               if (CharOperation.equals(existingFields[j].name,fieldName)) {
+                                       if (!modifiersEqual(field.getModifiers(),existingFields[j].modifiers)) {
                                                return true;
                                        }
-                                       if (!equal(existingFields[j].signature,newFields[i].getTypeName())) {
+                                       if (!CharOperation.equals(existingFields[j].signature,field.getTypeName())) {
                                                return true;
                                        }
                                        continue new_field_loop;
@@ -869,20 +881,34 @@ public class AjState {
                MemberStructure[] existingMethods = existingType.methods;
                IBinaryMethod[] newMethods = reader.getMethods();
                if (newMethods == null) { newMethods = new IBinaryMethod[0]; }
-               if (newMethods.length != existingMethods.length) {
+               // remove the aspectOf, hasAspect, clinit and ajc$XXX methods 
+               // from those we compare with the existing methods - bug 129163
+               List nonGenMethods = new ArrayList();
+               for (int i = 0; i < newMethods.length; i++) {
+                       IBinaryMethod method = newMethods[i];
+                       char[] methodName = method.getSelector();
+                       if (!CharOperation.equals(methodName,NameMangler.METHOD_ASPECTOF) && 
+                               !CharOperation.equals(methodName,NameMangler.METHOD_HASASPECT) &&
+                               !CharOperation.equals(methodName,NameMangler.STATIC_INITIALIZER) && 
+                               !CharOperation.prefixEquals(NameMangler.AJC_DOLLAR_PREFIX,methodName)) {
+                               nonGenMethods.add(method);
+                       }
+               }
+               if (nonGenMethods.size() != existingMethods.length) {
                        return true;
                }
-               new_method_loop: for (int i = 0; i < newMethods.length; i++) {
-                       char[] methodName = newMethods[i].getSelector();
+               new_method_loop: for (Iterator iter = nonGenMethods.iterator(); iter.hasNext();) {
+                       IBinaryMethod method = (IBinaryMethod) iter.next();
+                       char[] methodName = method.getSelector();
                        for (int j = 0; j < existingMethods.length; j++) {
-                               if (equal(existingMethods[j].name,methodName)) {
+                               if (CharOperation.equals(existingMethods[j].name,methodName)) {
                                        // candidate match
-                                       if (!equal(newMethods[i].getMethodDescriptor(),existingMethods[j].signature)) {
+                                       if (!CharOperation.equals(method.getMethodDescriptor(),existingMethods[j].signature)) {
                                                continue; // might be overloading
                                        } 
                                        else {
                                                // matching sigs
-                                               if (!modifiersEqual(newMethods[i].getModifiers(),existingMethods[j].modifiers)) {
+                                               if (!modifiersEqual(method.getModifiers(),existingMethods[j].modifiers)) {
                                                        return true;
                                                }
                                                continue new_method_loop;
@@ -904,22 +930,6 @@ public class AjState {
                return (eclipseModifiers == resolvedTypeModifiers);
        }
        
-       private boolean equal(char[] c1, char[] c2) {
-               if (c1 == null && c2 == null) {
-                       return true;
-               }
-               if (c1 == null || c2 == null) {
-                       return false;
-               }
-               if (c1.length != c2.length) {
-                       return false;
-               }
-               for (int i = 0; i < c1.length; i++) {
-                       if (c1[i] != c2[i]) return false;
-               }
-               return true;
-       }
-       
        private static StringSet makeStringSet(List strings) {
                StringSet ret = new StringSet(strings.size());
                for (Iterator iter = strings.iterator(); iter.hasNext();) {
index 4dfd751b9577f40bf5c4ead1364aa25972f88ea9..7337305bcbac12cd852b7df7cfda4cfb98907dbd 100644 (file)
@@ -20,9 +20,12 @@ public class NameMangler {
        private NameMangler() {
                throw new RuntimeException("static");
        }
-       
+       public static final char[] AJC_DOLLAR_PREFIX = {'a', 'j', 'c','$'};
        public static final String PREFIX = "ajc$";
        public static final String ITD_PREFIX = PREFIX + "interType$";
+       public static final char[] METHOD_ASPECTOF = {'a', 's', 'p','e','c','t','O','f'};
+       public static final char[] METHOD_HASASPECT = {'h', 'a', 's','A','s','p','e','c','t'};
+       public static final char[] STATIC_INITIALIZER = {'<', 'c', 'l','i','n','i','t','>'};
        
        public static final String CFLOW_STACK_TYPE = "org.aspectj.runtime.internal.CFlowStack";
        public static final String CFLOW_COUNTER_TYPE="org.aspectj.runtime.internal.CFlowCounter";
index 5891b9bc84fed3ffc71acadc8707d1c7c7c8b905..927b174be4f012627db81487709e06ee3ffbbd94 100644 (file)
@@ -406,4 +406,6 @@ public abstract class ResolvedTypeMunger {
        public boolean isLateMunger() {
                return false;
        }
+       
+       
 }
index 08bb03e87ab6c88be460f25e7f048d994f6956c6..671e10faa96c69a13549145d8820fc96042ad7de 100644 (file)
@@ -85,5 +85,8 @@ public class BcelCflowCounterFieldAdder extends BcelTypeMunger {
        public boolean matches(ResolvedType onType) {
                return onType.equals(cflowCounterField.getDeclaringType());
        }
+       public boolean existsToSupportShadowMunging() {
+               return true;
+       }
 
 }
index 2ed447ac44df1bad5e4b9f6b1f97c83d9cf587fb..df9725ac2131b71d7c653914b0e4e47fbacb56f1 100644 (file)
@@ -74,5 +74,8 @@ public class BcelCflowStackFieldAdder extends BcelTypeMunger {
        public boolean matches(ResolvedType onType) {
                return onType.equals(cflowStackField.getDeclaringType());
        }
+       public boolean existsToSupportShadowMunging() {
+               return true;
+       }
 
 }
index e291cc3e3b05ec9d76cdb50d66f9f5d0815e5760..1565259938045d93108f4082ea6f72f0d327fe1c 100644 (file)
@@ -1644,5 +1644,21 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
        public List /*String*/ getTypeVariableAliases() {
                return munger.getTypeVariableAliases();
        }
+       
+       /**
+        * Some type mungers are created purely to help with the implementation of shadow mungers.  
+        * For example to support the cflow() pointcut we create a new cflow field in the aspect, and
+        * that is added via a BcelCflowCounterFieldAdder.
+        * 
+        * During compilation we need to compare sets of type mungers, and if some only come into
+        * existence after the 'shadowy' type things have been processed, we need to ignore
+        * them during the comparison.
+        * 
+        * Returning true from this method indicates the type munger exists to support 'shadowy' stuff -
+        * and so can be ignored in some comparison.
+        */
+       public boolean existsToSupportShadowMunging() {
+               return false; // Does this need to delegate to the ResolvedTypeMunger field held in the BcelTypeMunger?
+       }
 }
                
\ No newline at end of file