]> source.dussan.org Git - aspectj.git/commitdiff
329111
authoraclement <aclement>
Fri, 29 Oct 2010 22:48:45 +0000 (22:48 +0000)
committeraclement <aclement>
Fri, 29 Oct 2010 22:48:45 +0000 (22:48 +0000)
asm/src/org/aspectj/asm/IProgramElement.java
asm/src/org/aspectj/asm/internal/JDTLikeHandleProvider.java

index eedffc3a2add3414eb3943bc39fb5b31dbe11d76..46d4f9ad832138c4871c0c479a09dcc98ac9e0a7 100644 (file)
@@ -389,6 +389,10 @@ public interface IProgramElement extends Serializable {
                        return name.startsWith("declare parents");
                }
 
+               public boolean isDeclareSoft() {
+                       return name.startsWith("declare soft");
+               }
+
                // The 4 declarations below are necessary for serialization
                private static int nextOrdinal = 0;
                private final int ordinal = nextOrdinal++;
@@ -400,6 +404,7 @@ public interface IProgramElement extends Serializable {
                public boolean isPackageDeclaration() {
                        return this == PACKAGE_DECLARATION;
                }
+
        }
 
        public void setAnnotationStyleDeclaration(boolean b);
index 7a38eafb577216a604f66ee75bd06347a16981f6..2499b5159662f72b209332d990bda0a3f7d71341 100644 (file)
@@ -187,26 +187,13 @@ public class JDTLikeHandleProvider implements IElementHandleProvider {
                                return CharOperation.concat(countDelim, new Integer(count).toString().toCharArray());
                        }
                } else if (ipe.getKind().isDeclareAnnotation()) {
-                       // look at peer declares
-                       int count = 1;
-                       for (IProgramElement object : ipe.getParent().getChildren()) {
-                               if (object.equals(ipe)) {
-                                       break;
-                               }
-                               if (object.getKind() == ipe.getKind()) {
-                                       if (object.getKind().toString().equals(ipe.getKind().toString())) {
-                                               String existingHandle = object.getHandleIdentifier();
-                                               int suffixPosition = existingHandle.indexOf('!');
-                                               if (suffixPosition != -1) {
-                                                       count = new Integer(existingHandle.substring(suffixPosition + 1)).intValue() + 1;
-                                               } else {
-                                                       if (count == 1) {
-                                                               count = 2;
-                                                       }
-                                               }
-                                       }
-                               }
+                       int count = computeCountBasedOnPeers(ipe);
+                       if (count > 1) {
+                               return CharOperation.concat(countDelim, new Integer(count).toString().toCharArray());
                        }
+               } else if (ipe.getKind().isDeclareSoft()) {
+                       // look at peer declares
+                       int count = computeCountBasedOnPeers(ipe);
                        if (count > 1) {
                                return CharOperation.concat(countDelim, new Integer(count).toString().toCharArray());
                        }
@@ -222,22 +209,7 @@ public class JDTLikeHandleProvider implements IElementHandleProvider {
                        String ipeSig = ipe.getBytecodeSignature();
                        // remove return type from the signature - it should not be included in the comparison
                        int idx = 0;
-                       if (ipeSig != null && ((idx = ipeSig.indexOf(")")) != -1)) {
-                               ipeSig = ipeSig.substring(0, idx);
-                       }
-                       if (ipeSig != null) {
-                               if (ipeSig.indexOf("Lorg/aspectj/lang") != -1) {
-                                       if (ipeSig.endsWith("Lorg/aspectj/lang/JoinPoint$StaticPart;")) {
-                                               ipeSig = ipeSig.substring(0, ipeSig.lastIndexOf("Lorg/aspectj/lang/JoinPoint$StaticPart;"));
-                                       }
-                                       if (ipeSig.endsWith("Lorg/aspectj/lang/JoinPoint;")) {
-                                               ipeSig = ipeSig.substring(0, ipeSig.lastIndexOf("Lorg/aspectj/lang/JoinPoint;"));
-                                       }
-                                       if (ipeSig.endsWith("Lorg/aspectj/lang/JoinPoint$StaticPart;")) {
-                                               ipeSig = ipeSig.substring(0, ipeSig.lastIndexOf("Lorg/aspectj/lang/JoinPoint$StaticPart;"));
-                                       }
-                               }
-                       }
+                       ipeSig = shortenIpeSig(ipeSig);
                        for (IProgramElement object : kids) {
                                if (object.equals(ipe)) {
                                        break;
@@ -289,22 +261,7 @@ public class JDTLikeHandleProvider implements IElementHandleProvider {
                        String ipeSig = ipe.getBytecodeSignature();
                        // remove return type from the signature - it should not be included in the comparison
                        int idx = 0;
-                       if (ipeSig != null && ((idx = ipeSig.indexOf(")")) != -1)) {
-                               ipeSig = ipeSig.substring(0, idx);
-                       }
-                       if (ipeSig != null) {
-                               if (ipeSig.indexOf("Lorg/aspectj/lang") != -1) {
-                                       if (ipeSig.endsWith("Lorg/aspectj/lang/JoinPoint$StaticPart;")) {
-                                               ipeSig = ipeSig.substring(0, ipeSig.lastIndexOf("Lorg/aspectj/lang/JoinPoint$StaticPart;"));
-                                       }
-                                       if (ipeSig.endsWith("Lorg/aspectj/lang/JoinPoint;")) {
-                                               ipeSig = ipeSig.substring(0, ipeSig.lastIndexOf("Lorg/aspectj/lang/JoinPoint;"));
-                                       }
-                                       if (ipeSig.endsWith("Lorg/aspectj/lang/JoinPoint$StaticPart;")) {
-                                               ipeSig = ipeSig.substring(0, ipeSig.lastIndexOf("Lorg/aspectj/lang/JoinPoint$StaticPart;"));
-                                       }
-                               }
-                       }
+                       ipeSig = shortenIpeSig(ipeSig);
                        for (IProgramElement object : kids) {
                                if (object.equals(ipe)) {
                                        break;
@@ -407,6 +364,50 @@ public class JDTLikeHandleProvider implements IElementHandleProvider {
                return empty;
        }
 
+       private String shortenIpeSig(String ipeSig) {
+               int idx;
+               if (ipeSig != null && ((idx = ipeSig.indexOf(")")) != -1)) {
+                       ipeSig = ipeSig.substring(0, idx);
+               }
+               if (ipeSig != null) {
+                       if (ipeSig.indexOf("Lorg/aspectj/lang") != -1) {
+                               if (ipeSig.endsWith("Lorg/aspectj/lang/JoinPoint$StaticPart;")) {
+                                       ipeSig = ipeSig.substring(0, ipeSig.lastIndexOf("Lorg/aspectj/lang/JoinPoint$StaticPart;"));
+                               }
+                               if (ipeSig.endsWith("Lorg/aspectj/lang/JoinPoint;")) {
+                                       ipeSig = ipeSig.substring(0, ipeSig.lastIndexOf("Lorg/aspectj/lang/JoinPoint;"));
+                               }
+                               if (ipeSig.endsWith("Lorg/aspectj/lang/JoinPoint$StaticPart;")) {
+                                       ipeSig = ipeSig.substring(0, ipeSig.lastIndexOf("Lorg/aspectj/lang/JoinPoint$StaticPart;"));
+                               }
+                       }
+               }
+               return ipeSig;
+       }
+
+       private int computeCountBasedOnPeers(IProgramElement ipe) {
+               int count = 1;
+               for (IProgramElement object : ipe.getParent().getChildren()) {
+                       if (object.equals(ipe)) {
+                               break;
+                       }
+                       if (object.getKind() == ipe.getKind()) {
+                               if (object.getKind().toString().equals(ipe.getKind().toString())) {
+                                       String existingHandle = object.getHandleIdentifier();
+                                       int suffixPosition = existingHandle.indexOf('!');
+                                       if (suffixPosition != -1) {
+                                               count = new Integer(existingHandle.substring(suffixPosition + 1)).intValue() + 1;
+                                       } else {
+                                               if (count == 1) {
+                                                       count = 2;
+                                               }
+                                       }
+                               }
+                       }
+               }
+               return count;
+       }
+
        /**
         * Only returns the count if it's not equal to 1
         */