]> source.dussan.org Git - aspectj.git/commitdiff
tests and fixes for jdtlikehandleprovider, bug 159896
authoraclement <aclement>
Fri, 6 Oct 2006 16:29:03 +0000 (16:29 +0000)
committeraclement <aclement>
Fri, 6 Oct 2006 16:29:03 +0000 (16:29 +0000)
12 files changed:
tests/features153/jdtlikehandleprovider/AdviceAndInjar.aj [new file with mode: 0644]
tests/features153/jdtlikehandleprovider/AspectOnAspectPath.aj [new file with mode: 0644]
tests/features153/jdtlikehandleprovider/ClassForAspectpath.java [new file with mode: 0644]
tests/features153/jdtlikehandleprovider/DeclareAndInjar.aj [new file with mode: 0644]
tests/features153/jdtlikehandleprovider/README.txt [new file with mode: 0644]
tests/features153/jdtlikehandleprovider/advice.jar [new file with mode: 0644]
tests/features153/jdtlikehandleprovider/declare.jar [new file with mode: 0644]
tests/features153/jdtlikehandleprovider/jarForAspectPath.jar [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc153/JDTLikeHandleProviderTests.java
tests/src/org/aspectj/systemtest/ajc153/jdtlikehandleprovider.xml
weaver/src/org/aspectj/weaver/ShadowMunger.java
weaver/src/org/aspectj/weaver/patterns/DeclareErrorOrWarning.java

diff --git a/tests/features153/jdtlikehandleprovider/AdviceAndInjar.aj b/tests/features153/jdtlikehandleprovider/AdviceAndInjar.aj
new file mode 100644 (file)
index 0000000..68a6ad5
--- /dev/null
@@ -0,0 +1,17 @@
+public aspect AdviceAndInjar {
+       
+       pointcut p() : call(* *.*(..)) && !within(AdviceAndInjar);
+
+       before() : p() {
+       }
+       
+       after() : p() {
+       }
+       
+       pointcut p1() : execution(* *.*(..)) && !within(AdviceAndInjar);
+       
+       Object around() : p1() {
+               return proceed();
+       }
+
+}
diff --git a/tests/features153/jdtlikehandleprovider/AspectOnAspectPath.aj b/tests/features153/jdtlikehandleprovider/AspectOnAspectPath.aj
new file mode 100644 (file)
index 0000000..d111fda
--- /dev/null
@@ -0,0 +1,17 @@
+package pkg;
+
+public aspect AspectOnAspectPath {
+
+       pointcut p() : call(* *.*(..)) && !within(AspectOnAspectPath);
+       declare warning: p() : "blah";
+       
+       before() : p() {
+       }
+       
+       pointcut exec() : execution(* *.*(..)) && !within(AspectOnAspectPath);
+       declare warning : exec() : "blah2";
+       before() : exec() {
+               
+       }
+       
+}
diff --git a/tests/features153/jdtlikehandleprovider/ClassForAspectpath.java b/tests/features153/jdtlikehandleprovider/ClassForAspectpath.java
new file mode 100644 (file)
index 0000000..c30da9b
--- /dev/null
@@ -0,0 +1,10 @@
+public class ClassForAspectpath {
+       
+       public void foo() {
+               bar();
+       }
+       
+       public void bar() {
+               
+       }
+}
diff --git a/tests/features153/jdtlikehandleprovider/DeclareAndInjar.aj b/tests/features153/jdtlikehandleprovider/DeclareAndInjar.aj
new file mode 100644 (file)
index 0000000..d1b94b9
--- /dev/null
@@ -0,0 +1,9 @@
+public aspect DeclareAndInjar {
+       
+       pointcut p() : call(* *.*(..)) && !within(DeclareAndInjar);
+       declare warning: p() : "warning";
+
+       pointcut exec() : execution(* *.*(..)) && !within(DeclareAndInjar);
+       declare error : exec() : "error";
+
+}
diff --git a/tests/features153/jdtlikehandleprovider/README.txt b/tests/features153/jdtlikehandleprovider/README.txt
new file mode 100644 (file)
index 0000000..cca1b52
--- /dev/null
@@ -0,0 +1,7 @@
+To regenerate the jars in this directory:
+
+1. ajc AspectOnAspectPath.aj -outjar jarForAspectPath.jar
+
+2. ajc DeclareAndInjar.aj -outjar declare.jar
+
+3. ajc AdviceAndInjar.aj -outjar advice.jar
diff --git a/tests/features153/jdtlikehandleprovider/advice.jar b/tests/features153/jdtlikehandleprovider/advice.jar
new file mode 100644 (file)
index 0000000..7e99367
Binary files /dev/null and b/tests/features153/jdtlikehandleprovider/advice.jar differ
diff --git a/tests/features153/jdtlikehandleprovider/declare.jar b/tests/features153/jdtlikehandleprovider/declare.jar
new file mode 100644 (file)
index 0000000..1278b4f
Binary files /dev/null and b/tests/features153/jdtlikehandleprovider/declare.jar differ
diff --git a/tests/features153/jdtlikehandleprovider/jarForAspectPath.jar b/tests/features153/jdtlikehandleprovider/jarForAspectPath.jar
new file mode 100644 (file)
index 0000000..bc12b8b
Binary files /dev/null and b/tests/features153/jdtlikehandleprovider/jarForAspectPath.jar differ
index 4dd33640e86055d175bb5b7bc7fd2900e6ec7caa..eba17ef8bd90a32b00fd374217889acc54b3ccc6 100644 (file)
@@ -316,6 +316,67 @@ public class JDTLikeHandleProviderTests extends XMLBasedAjcTestCase {
                                + ", but did not",top.getElement(handle2));
        }
        
+       public void testTwoPiecesOfBeforeAdviceInInjarAspectHaveUniqueHandles_pr159896() {
+               runTest("advice with same name in injar aspect should have unique handles");
+               IHierarchy top = AsmManager.getDefault().getHierarchy();
+               String handle1 = top.findElementForLabel(top.getRoot(),
+                               IProgramElement.Kind.ADVICE,"before(): p..").getHandleIdentifier();
+               String handle2 = top.findElementForLabel(top.getRoot(),
+                               IProgramElement.Kind.ADVICE,"before(): exec..").getHandleIdentifier();
+               assertFalse("expected the two advice nodes to have unique handles but" +
+                               " did not", handle1.equals(handle2));
+       }
+
+       public void testTwoDeclareWarningsInInjarAspectHaveUniqueHandles_pr159896() {
+               runTest("declare warnings in injar aspect should have unique handles");
+               IHierarchy top = AsmManager.getDefault().getHierarchy();
+               String handle1 = top.findElementForLabel(top.getRoot(),
+                               IProgramElement.Kind.DECLARE_WARNING,"declare warning: \"blah\"").getHandleIdentifier();
+               String handle2 = top.findElementForLabel(top.getRoot(),
+                               IProgramElement.Kind.DECLARE_WARNING,"declare warning: \"blah2\"").getHandleIdentifier();
+               assertFalse("expected the two declare warning nodes to have unique handles but" +
+                               " did not", handle1.equals(handle2));
+       }
+       
+       // if have one declare warning and one declare error statement within an injar
+       // aspect, neither of them should have a counter (i.e. "!2") at the end of 
+       // their handle
+       public void testOnlyIncrementSameDeclareTypeFromInjar_pr159896() {
+               runTest("dont increment counter for different declares");
+               IHierarchy top = AsmManager.getDefault().getHierarchy();
+               String warning = top.findElementForLabel(top.getRoot(), 
+                               IProgramElement.Kind.DECLARE_WARNING,"declare warning: \"warning\"").getHandleIdentifier();
+               assertTrue("shouldn't have incremented counter for declare warning handle " +
+                               "because only one declare warning statement", 
+                               warning.indexOf("!0") == -1 && warning.indexOf("!2") == -1);
+               String error = top.findElementForLabel(top.getRoot(), 
+                               IProgramElement.Kind.DECLARE_ERROR,"declare error: \"error\"").getHandleIdentifier();
+               assertTrue("shouldn't have incremented counter for declare error handle " +
+                               "because only one declare error statement", 
+                               error.indexOf("!0") == -1 && error.indexOf("!2") == -1);
+       }
+       
+       public void testOnlyIncrementSameAdviceKindFromInjar_pr159896() {
+               runTest("dont increment counter for different advice kinds");
+               IHierarchy top = AsmManager.getDefault().getHierarchy();
+               String before = top.findElementForLabel(top.getRoot(), 
+                               IProgramElement.Kind.ADVICE,"before(): p..").getHandleIdentifier();
+               assertTrue("shouldn't have incremented counter for before handle " +
+                               "because only one before advice", 
+                               before.indexOf("!0") == -1 && before.indexOf("!2") == -1 && before.indexOf("!3") == -1 );
+               String after = top.findElementForLabel(top.getRoot(), 
+                               IProgramElement.Kind.ADVICE,"after(): p..").getHandleIdentifier();
+               assertTrue("shouldn't have incremented counter for after handle " +
+                               "because only one after advice", 
+                               after.indexOf("!0") == -1 && after.indexOf("!2") == -1 && after.indexOf("!3") == -1 );
+               String around = top.findElementForLabel(top.getRoot(), 
+                               IProgramElement.Kind.ADVICE,"around(): p1..").getHandleIdentifier();
+               assertTrue("shouldn't have incremented counter for around handle " +
+                               "because only one around advice", 
+                               around.indexOf("!0") == -1 && around.indexOf("!2") == -1 && around.indexOf("!3") == -1 );
+               
+       }
+       
        //---------- following tests ensure we produce the same handles as jdt -----//
        //---------- (apart from the prefix)
        
index 3d0172e0ae85f89e1e28fb5859584575d12b38a1..fa4854194e32bddbb965e226abefb313523b71a9 100644 (file)
       <compile files="Set.aj" options="-emacssym"/>
     </ajc-test>
 
+    <ajc-test dir="features153/jdtlikehandleprovider" title="advice with same name in injar aspect should have unique handles">
+      <compile files="ClassForAspectpath.java" options="-emacssym" aspectpath="jarForAspectPath.jar">
+        <message kind="warning" text="blah"/>
+        <message kind="warning" text="blah2"/>
+      </compile>
+    </ajc-test>
+
+    <ajc-test dir="features153/jdtlikehandleprovider" title="declare warnings in injar aspect should have unique handles">
+      <compile files="ClassForAspectpath.java" options="-emacssym" aspectpath="jarForAspectPath.jar">
+        <message kind="warning" text="blah"/>
+        <message kind="warning" text="blah2"/>
+      </compile>
+    </ajc-test>
+
+    <ajc-test dir="features153/jdtlikehandleprovider" title="dont increment counter for different declares">
+      <compile files="ClassForAspectpath.java" options="-emacssym" aspectpath="declare.jar">
+        <message kind="warning" text="warning"/>
+        <message kind="error" text="error"/>
+      </compile>
+    </ajc-test>
+
+    <ajc-test dir="features153/jdtlikehandleprovider" title="dont increment counter for different advice kinds">
+      <compile files="ClassForAspectpath.java" options="-emacssym" aspectpath="advice.jar"/>
+    </ajc-test>
+
 </suite>
index a4ac3f8e15fd7722546f6dfe94e340e5f0ea9843..a376187a6df54d38f450325f06c4d94e8692688b 100644 (file)
@@ -273,31 +273,65 @@ public abstract class ShadowMunger implements PartialOrder.PartialComparable, IH
     }
     
     private void addChildNodes(IProgramElement parent, Collection children) {
+       int afterCtr = 1;
+       int aroundCtr = 1;
+       int beforeCtr = 1;
+       int deCtr = 1;
+       int dwCtr = 1;
        for (Iterator iter = children.iterator(); iter.hasNext();) {
                        Object element = (Object) iter.next();
                        if (element instanceof DeclareErrorOrWarning) {
                                DeclareErrorOrWarning decl = (DeclareErrorOrWarning)element;
-                               IProgramElement deowNode = new ProgramElement(
-                                       decl.isError() ? "declare error" : "declare warning",
-                                       decl.isError() ? IProgramElement.Kind.DECLARE_ERROR : IProgramElement.Kind.DECLARE_WARNING,
-                                       getBinarySourceLocation(decl.getSourceLocation()),
-                                       decl.getDeclaringType().getModifiers(),
-                                       null,null); 
-                       deowNode.setDetails("\"" + AsmRelationshipUtils.genDeclareMessage(decl.getMessage()) + "\"");
-                       parent.addChild(deowNode);
+                               int counter = 0;
+                               if (decl.isError()) {
+                                       counter = deCtr++;
+                               } else {
+                                       counter = dwCtr++;
+                               }
+                       parent.addChild(createDeclareErrorOrWarningChild(decl,counter));
                        } else if (element instanceof BcelAdvice) {
                                BcelAdvice advice = (BcelAdvice)element;
-                               IProgramElement adviceNode = new ProgramElement(
-                                       advice.kind.getName(),
-                                       IProgramElement.Kind.ADVICE,
-                                       getBinarySourceLocation(advice.getSourceLocation()),
-                                       advice.signature.getModifiers(),null,Collections.EMPTY_LIST);
-                       adviceNode.setDetails(AsmRelationshipUtils.genPointcutDetails(advice.getPointcut()));
-                       parent.addChild(adviceNode);
+                               int counter = 0;
+                               if (advice.getKind().equals(AdviceKind.Before)) {
+                                       counter = beforeCtr++;
+                               } else if (advice.getKind().equals(AdviceKind.Around)){
+                                       counter = aroundCtr++;
+                               } else {
+                                       counter = afterCtr++;
+                               }
+                       parent.addChild(createAdviceChild(advice,counter));
                        }
                }
     }
     
+    private IProgramElement createDeclareErrorOrWarningChild(
+               DeclareErrorOrWarning decl, int count) {
+               IProgramElement deowNode = new ProgramElement(
+                       decl.getName(),
+                       decl.isError() ? IProgramElement.Kind.DECLARE_ERROR : IProgramElement.Kind.DECLARE_WARNING,
+                       getBinarySourceLocation(decl.getSourceLocation()),
+                       decl.getDeclaringType().getModifiers(),
+                       null,null); 
+       deowNode.setDetails("\"" + AsmRelationshipUtils.genDeclareMessage(decl.getMessage()) + "\"");
+       if (count != -1) {
+               deowNode.setBytecodeName(decl.getName() + "_" + count);
+       }
+       return deowNode;
+    }
+    
+    private IProgramElement createAdviceChild(BcelAdvice advice, int counter ) {
+               IProgramElement adviceNode = new ProgramElement(
+                       advice.kind.getName(),
+                       IProgramElement.Kind.ADVICE,
+                       getBinarySourceLocation(advice.getSourceLocation()),
+                       advice.signature.getModifiers(),null,Collections.EMPTY_LIST);
+       adviceNode.setDetails(AsmRelationshipUtils.genPointcutDetails(advice.getPointcut()));
+       if (counter != 1) {
+                       adviceNode.setBytecodeName(advice.getKind().getName() + "$" + counter + "$");
+               }
+       return adviceNode;
+    }
+    
     /**
      * Returns the binarySourceLocation for the given sourcelocation. This
      * isn't cached because it's used when faulting in the binary nodes
index c4a3948ba531f3fac9836bebda86c46fe2aa4180..c9b6637284be58b19c76d8a62813c7e6cd0104c8 100644 (file)
@@ -31,6 +31,9 @@ public class DeclareErrorOrWarning extends Declare {
                this.message = message;
        }
        
+       /**
+        * returns "declare warning: <message>" or "declare error: <message>"
+        */
        public String toString() {
                StringBuffer buf = new StringBuffer();
                buf.append("declare ");
@@ -111,4 +114,15 @@ public class DeclareErrorOrWarning extends Declare {
        public String getNameSuffix() {
                return "eow";
        }
+       
+       /**
+        * returns "declare warning" or "declare error"
+        */
+       public String getName() {
+               StringBuffer buf = new StringBuffer();
+               buf.append("declare ");
+               if (isError) buf.append("error");
+               else buf.append("warning");     
+               return buf.toString();
+       }
 }