]> source.dussan.org Git - aspectj.git/commitdiff
129163: more bits...: equals in the type munger hierarchy
authoraclement <aclement>
Tue, 7 Mar 2006 16:08:34 +0000 (16:08 +0000)
committeraclement <aclement>
Tue, 7 Mar 2006 16:08:34 +0000 (16:08 +0000)
12 files changed:
weaver/src/org/aspectj/weaver/Advice.java
weaver/src/org/aspectj/weaver/AnnotationOnTypeMunger.java
weaver/src/org/aspectj/weaver/MemberImpl.java
weaver/src/org/aspectj/weaver/MethodDelegateTypeMunger.java
weaver/src/org/aspectj/weaver/NewConstructorTypeMunger.java
weaver/src/org/aspectj/weaver/NewFieldTypeMunger.java
weaver/src/org/aspectj/weaver/NewMethodTypeMunger.java
weaver/src/org/aspectj/weaver/NewParentTypeMunger.java
weaver/src/org/aspectj/weaver/PerObjectInterfaceTypeMunger.java
weaver/src/org/aspectj/weaver/PerTypeWithinTargetTypeMunger.java
weaver/src/org/aspectj/weaver/PrivilegedAccessMunger.java
weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java

index 4f663de6a9247f2f1d2efd880891734d8fbab8cc..38e0d9c8848cb6c9f8513e687b093ed61ec7f338 100644 (file)
@@ -240,6 +240,8 @@ public abstract class Advice extends ShadowMunger {
        // only called as part of parameterization....
        public void setSignature(Member signature) {
                this.signature = signature;
+               // reset hashCode value so it can be recalculated next time
+               hashCode = 0;
        }
        
        public boolean hasExtraParameter() {
@@ -366,22 +368,26 @@ public abstract class Advice extends ShadowMunger {
 //                     + signature
 //                     + ")";
        }
+       
+       // XXX this perhaps ought to take account of the other fields in advice ...
     public boolean equals(Object other) {
         if (! (other instanceof Advice)) return false;
         Advice o = (Advice) other;
-        return o.attribute.equals(attribute) 
-               && o.pointcut.equals(pointcut) 
-               && o.signature.equals(signature);
+        return o.kind.equals(kind) 
+               && ((o.pointcut == null) ? (pointcut == null) : o.pointcut.equals(pointcut))
+               && ((o.signature == null) ? (signature == null) : o.signature.equals(signature));
+
     }
-    private volatile int hashCode = 0;
+
+       private volatile int hashCode = 0;
     public int hashCode() {
-        if (hashCode == 0) {
+       if (hashCode == 0) {
             int result = 17;
             result = 37*result + kind.hashCode();
-            result = 37*result + pointcut.hashCode();
-            if (signature != null) result = 37*result + signature.hashCode();
-            hashCode = result;
-        }
+            result = 37*result + ((pointcut == null) ? 0 : pointcut.hashCode());
+            result = 37*result + ((signature == null) ? 0 : signature.hashCode());
+            hashCode = result;                 
+               }
         return hashCode;
     }
  
index f12e98d6351b0c7d84f42c5471ef8517a55ac1ef..2860810ac783edafc7c87b7550a9418449842d13 100644 (file)
@@ -35,4 +35,21 @@ public class AnnotationOnTypeMunger extends ResolvedTypeMunger {
        public AnnotationX getNewAnnotation() {
                return newAnnotation;
        }
+
+    public boolean equals(Object other) {
+       if (!(other instanceof AnnotationOnTypeMunger)) return false;
+       AnnotationOnTypeMunger o = (AnnotationOnTypeMunger)other;
+       return newAnnotation.getSignature().equals(o.newAnnotation.getSignature());
+    }
+
+    private volatile int hashCode = 0;
+    public int hashCode() {
+       if (hashCode == 0) {
+               int result = 17;
+           result = 37*result + newAnnotation.getSignature().hashCode();
+           hashCode = result;
+               }
+           return hashCode;
+    }
+       
 }
index 039210378c35c794fe119e3d8d10b7c7437bba37..fc118f42c3bcbd433d2487e6ea84cd739fc1abce 100644 (file)
@@ -365,22 +365,10 @@ public class MemberImpl implements Comparable, AnnotatedElement,Member {
     public boolean equals(Object other) {
         if (! (other instanceof Member)) return false;
         Member o = (Member) other;
-
-        return (kind == o.getKind() 
-            && name.equals(o.getName()) 
-            && signature.equals(o.getSignature())
-            && declaringType.equals(o.getDeclaringType()));
-    }
-    
-    /* (non-Javadoc)
-        * @see org.aspectj.weaver.Member#compareTo(java.lang.Object)
-        */
-    public int compareTo(Object other) {
-       Member o = (Member) other;
-       
-       int i = getName().compareTo(o.getName());
-       if (i != 0) return i;
-       return getSignature().compareTo(o.getSignature());
+        return (getKind() == o.getKind() 
+            && getName().equals(o.getName()) 
+            && getSignature().equals(o.getSignature())
+            && getDeclaringType().equals(o.getDeclaringType()));
     }
     
     /** 
@@ -392,15 +380,26 @@ public class MemberImpl implements Comparable, AnnotatedElement,Member {
     public int hashCode() {
         if (hashCode == 0) {
             int result = 17;
-            result = 37*result + kind.hashCode();
-            result = 37*result + name.hashCode();
-            result = 37*result + signature.hashCode();
-            result = 37*result + declaringType.hashCode();
+            result = 37*result + getKind().hashCode();
+            result = 37*result + getName().hashCode();
+            result = 37*result + getSignature().hashCode();
+            result = 37*result + getDeclaringType().hashCode();
             hashCode = result;
         } 
         return hashCode;
     }
 
+    /* (non-Javadoc)
+        * @see org.aspectj.weaver.Member#compareTo(java.lang.Object)
+        */
+    public int compareTo(Object other) {
+       Member o = (Member) other;
+       
+       int i = getName().compareTo(o.getName());
+       if (i != 0) return i;
+       return getSignature().compareTo(o.getSignature());
+    }
+    
     public String toString() {
        StringBuffer buf = new StringBuffer();
        buf.append(returnType.getName());
index fbfccd6062b8fa02c5c68d104ba1b14354353e5e..3ecac98820f493bcf680f9ffa8f0ec5c9510c48a 100644 (file)
@@ -55,6 +55,26 @@ public class MethodDelegateTypeMunger extends ResolvedTypeMunger {
         this.implClassName = implClassName;
     }
 
+    public boolean equals(Object other) {
+       if (!(other instanceof MethodDelegateTypeMunger)) return false;
+       MethodDelegateTypeMunger o = (MethodDelegateTypeMunger)other;
+       return ((o.aspect == null) ? (aspect == null ) : aspect.equals(o.aspect))
+                       && ((o.typePattern == null) ? (typePattern == null ) : typePattern.equals(o.typePattern))
+                       && ((o.implClassName == null) ? (implClassName == null) : implClassName.equals(o.implClassName));
+    }
+
+    private volatile int hashCode = 0;
+    public int hashCode() {
+       if (hashCode == 0) {
+               int result = 17;
+           result = 37*result + ((aspect == null) ? 0 : aspect.hashCode());
+           result = 37*result + ((typePattern == null) ? 0 : typePattern.hashCode());
+           result = 37*result + ((implClassName == null) ? 0 : implClassName.hashCode());
+           hashCode = result;
+               }
+           return hashCode;
+    }
+    
     public ResolvedMember getDelegate(ResolvedType targetType) {
         return AjcMemberMaker.itdAtDeclareParentsField(
                 targetType,
@@ -130,6 +150,20 @@ public class MethodDelegateTypeMunger extends ResolvedTypeMunger {
             this.typePattern = typePattern;
         }
 
+        public boolean equals(Object other) {
+               if (!(other instanceof FieldHostTypeMunger)) return false;
+               FieldHostTypeMunger o = (FieldHostTypeMunger)other;
+               return ((o.aspect == null) ? (aspect == null ) : aspect.equals(o.aspect))
+                               && ((o.typePattern == null) ? (typePattern == null ) : typePattern.equals(o.typePattern));
+        }
+
+        public int hashCode() {
+               int result = 17;
+           result = 37*result + ((aspect == null) ? 0 : aspect.hashCode());
+           result = 37*result + ((typePattern == null) ? 0 : typePattern.hashCode());
+           return result;
+        }
+        
         public void write(DataOutputStream s) throws IOException {
             kind.write(s);
             signature.write(s);
index e1ed8fbe1b815715ebb87d516d2ba97f4576c6dd..411b4d1f2feb4b530c64b214c58da6a073e8a8a9 100644 (file)
@@ -40,6 +40,26 @@ public class NewConstructorTypeMunger extends ResolvedTypeMunger {
 
        }
        
+    public boolean equals(Object other) {
+       if (!(other instanceof NewConstructorTypeMunger)) return false;
+       NewConstructorTypeMunger o = (NewConstructorTypeMunger)other;   
+       return ((o.syntheticConstructor == null) ? (syntheticConstructor == null ) 
+                               : syntheticConstructor.equals(o.syntheticConstructor))
+                       & ((o.explicitConstructor == null) ? (explicitConstructor == null ) 
+                               : explicitConstructor.equals(o.explicitConstructor));
+    }
+
+    private volatile int hashCode = 0;
+    public int hashCode() {
+       if (hashCode == 0) {
+               int result = 17;
+           result = 37*result + ((syntheticConstructor == null) ? 0 : syntheticConstructor.hashCode());
+           result = 37*result + ((explicitConstructor == null) ? 0 : explicitConstructor.hashCode());
+           hashCode = result;
+               }
+           return hashCode;
+    }
+       
        // doesnt seem required....
 //     public ResolvedMember getDispatchMethod(UnresolvedType aspectType) {
 //             return AjcMemberMaker.interMethodBody(signature, aspectType);
@@ -78,6 +98,8 @@ public class NewConstructorTypeMunger extends ResolvedTypeMunger {
 
        public void setExplicitConstructor(ResolvedMember explicitConstructor) {
                this.explicitConstructor = explicitConstructor;
+               // reset hashCode so that its recalculated with new value
+               hashCode = 0;
        }
        
        public ResolvedMember getMatchingSyntheticMember(Member member, ResolvedType aspectType) {
index c58493312258d2a0bb724f213d606c71e12b2939..989fa476f140daf19df3a16b5cf3ce7672282478 100644 (file)
@@ -93,4 +93,22 @@ public class NewFieldTypeMunger extends ResolvedTypeMunger {
            return nftm;
        }
 
+    public boolean equals(Object other) {
+        if (! (other instanceof NewFieldTypeMunger)) return false;
+        NewFieldTypeMunger o = (NewFieldTypeMunger) other;
+        return kind.equals(o.kind)
+                       && ((o.signature == null) ? (signature == null ) : signature.equals(o.signature))
+                       && ((o.declaredSignature == null) ? (declaredSignature == null ) : declaredSignature.equals(o.declaredSignature))
+                       && ((o.typeVariableAliases == null) ? (typeVariableAliases == null ) : typeVariableAliases.equals(o.typeVariableAliases));
+    }
+          
+    public int hashCode() {
+       int result = 17;
+        result = 37*result + kind.hashCode();
+        result = 37*result + ((signature == null) ? 0 : signature.hashCode());
+        result = 37*result + ((declaredSignature == null) ? 0 : declaredSignature.hashCode());
+        result = 37*result + ((typeVariableAliases == null) ? 0 : typeVariableAliases.hashCode());
+        return result;
+    }
+       
 }
index b08b70bb9306ecde20637d4a05d69ccb4c95b08d..4febb7c95fbcf9c99537b1ce7fe6b9cb84346387 100644 (file)
@@ -110,5 +110,22 @@ public class NewMethodTypeMunger extends ResolvedTypeMunger {
                return nmtm;
        }
        
+    public boolean equals(Object other) {
+        if (! (other instanceof NewMethodTypeMunger)) return false;
+        NewMethodTypeMunger o = (NewMethodTypeMunger) other;
+        return kind.equals(o.kind)
+                       && ((o.signature == null) ? (signature == null ) : signature.equals(o.signature))
+                       && ((o.declaredSignature == null) ? (declaredSignature == null ) : declaredSignature.equals(o.declaredSignature))
+                       && ((o.typeVariableAliases == null) ? (typeVariableAliases == null ) : typeVariableAliases.equals(o.typeVariableAliases));
+    }
+          
+    public int hashCode() {
+       int result = 17;
+        result = 37*result + kind.hashCode();
+        result = 37*result + ((signature == null) ? 0 : signature.hashCode());
+        result = 37*result + ((declaredSignature == null) ? 0 : declaredSignature.hashCode());
+        result = 37*result + ((typeVariableAliases == null) ? 0 : typeVariableAliases.hashCode());
+        return result;
+    }
        
 }
index 312a7538dc80ad72438a410404df6113885ab036..8e76e2245e463a7bc3902a7272f70903f3457e49 100644 (file)
@@ -33,5 +33,19 @@ public class NewParentTypeMunger extends ResolvedTypeMunger {
                return newParent;
        }
 
-
+    public boolean equals(Object other) {
+        if (! (other instanceof NewParentTypeMunger)) return false;
+        NewParentTypeMunger o = (NewParentTypeMunger) other;
+        return newParent.equals(o.newParent);
+    }
+          
+    private volatile int hashCode = 0;
+    public int hashCode() {
+           if (hashCode == 0) {
+               int result = 17;
+               result = 37*result + newParent.hashCode();
+               hashCode = result;
+           }
+        return hashCode;
+    }
 }
index 3c3e315090de35224ecdc693ad9a691668dcaefe..6f473c749dde9b09266d16d9af423de447683303 100644 (file)
@@ -26,7 +26,25 @@ public class PerObjectInterfaceTypeMunger extends ResolvedTypeMunger {
     private final UnresolvedType interfaceType;
     private final Pointcut testPointcut;
     private TypePattern lazyTestTypePattern;
+    
+    public boolean equals(Object other) {
+       if (!(other instanceof PerObjectInterfaceTypeMunger)) return false;
+               PerObjectInterfaceTypeMunger o = (PerObjectInterfaceTypeMunger)other;
+       return ((o.testPointcut == null) ? (testPointcut == null ) : testPointcut.equals(o.testPointcut))
+                       && ((o.lazyTestTypePattern == null) ? (lazyTestTypePattern == null ) : lazyTestTypePattern.equals(o.lazyTestTypePattern));
+    }
 
+    private volatile int hashCode = 0;
+    public int hashCode() {
+       if (hashCode == 0) {
+               int result = 17;
+           result = 37*result + ((testPointcut == null) ? 0 : testPointcut.hashCode());
+           result = 37*result + ((lazyTestTypePattern == null) ? 0 : lazyTestTypePattern.hashCode());
+           hashCode = result;
+               }
+           return hashCode;
+    }
+    
     public PerObjectInterfaceTypeMunger(UnresolvedType aspectType, Pointcut testPointcut) {
         super(PerObjectInterface, null);
         this.testPointcut = testPointcut;
@@ -44,6 +62,8 @@ public class PerObjectInterfaceTypeMunger extends ResolvedTypeMunger {
             }
             PerThisOrTargetPointcutVisitor v = new PerThisOrTargetPointcutVisitor(!isPerThis, aspectType);
             lazyTestTypePattern = v.getPerTypePointcut(testPointcut);
+            // reset hashCode so that its recalculated with the new lazyTestTypePattern
+            hashCode = 0;
         }
         return lazyTestTypePattern;
     }
index 6fc52000a4e9777a93f47f8705176c6dae06304d..04e3a3132996d2f84bd5c3ab067b51d41739cb7a 100644 (file)
@@ -30,6 +30,24 @@ public class PerTypeWithinTargetTypeMunger extends ResolvedTypeMunger {
                this.testPointcut  = testPointcut;
        }
 
+       public boolean equals(Object other) {
+               if (!(other instanceof PerTypeWithinTargetTypeMunger)) return false;
+               PerTypeWithinTargetTypeMunger o = (PerTypeWithinTargetTypeMunger)other;
+               return ((o.testPointcut == null) ? (testPointcut == null ) : testPointcut.equals(o.testPointcut))
+                               && ((o.aspectType == null) ? (aspectType == null ) : aspectType.equals(o.aspectType));
+       }
+
+       private volatile int hashCode = 0;
+       public int hashCode() {
+               if (hashCode == 0) {
+                       int result = 17;
+                   result = 37*result + ((testPointcut == null) ? 0 : testPointcut.hashCode());
+                   result = 37*result + ((aspectType == null) ? 0 : aspectType.hashCode());
+                   hashCode = result;
+               }
+           return hashCode;
+       }
+       
        public void write(DataOutputStream s) throws IOException {
                throw new RuntimeException("shouldn't be serialized");
        }
index b1785024927ca4f4f3abfeb01bfa83115a75e5de..21c7a1fc2f895850121edd8a5c7439ea3338d2ad 100644 (file)
@@ -45,4 +45,22 @@ public class PrivilegedAccessMunger extends ResolvedTypeMunger {
                return null;
        }
 
+    public boolean equals(Object other) {
+        if (! (other instanceof PrivilegedAccessMunger)) return false;
+        PrivilegedAccessMunger o = (PrivilegedAccessMunger) other;
+        return kind.equals(o.kind)
+                       && ((o.signature == null) ? (signature == null ) : signature.equals(o.signature))
+                       && ((o.declaredSignature == null) ? (declaredSignature == null ) : declaredSignature.equals(o.declaredSignature))
+                       && ((o.typeVariableAliases == null) ? (typeVariableAliases == null ) : typeVariableAliases.equals(o.typeVariableAliases));
+    }
+          
+    public int hashCode() {
+       int result = 17;
+        result = 37*result + kind.hashCode();
+        result = 37*result + ((signature == null) ? 0 : signature.hashCode());
+        result = 37*result + ((declaredSignature == null) ? 0 : declaredSignature.hashCode());
+        result = 37*result + ((typeVariableAliases == null) ? 0 : typeVariableAliases.hashCode());
+        return result;
+    }
+       
 }
index 1565259938045d93108f4082ea6f72f0d327fe1c..5c4e918d85d8c1ae8a4085bd10cf2bfe045e4737 100644 (file)
@@ -1645,6 +1645,25 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                return munger.getTypeVariableAliases();
        }
        
+       public boolean equals(Object other) {
+        if (! (other instanceof BcelTypeMunger))  return false;
+        BcelTypeMunger o = (BcelTypeMunger) other;
+        return ((o.getMunger() == null) ? (getMunger() == null) : o.getMunger().equals(getMunger()))
+               && ((o.getAspectType() == null) ? (getAspectType() == null) : o.getAspectType().equals(getAspectType()));
+    }
+          
+    private volatile int hashCode = 0;
+    public int hashCode() {
+       if (hashCode == 0) {
+            int result = 17;
+               result = 37*result + ((getMunger() == null) ? 0 : getMunger().hashCode());
+               result = 37*result + ((getAspectType() == null) ? 0 : getAspectType().hashCode());
+            hashCode = result;
+       }
+       return hashCode;
+    }
+       
+       
        /**
         * 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