]> source.dussan.org Git - aspectj.git/commitdiff
test and fix for 132130
authoraclement <aclement>
Fri, 17 Mar 2006 16:47:06 +0000 (16:47 +0000)
committeraclement <aclement>
Fri, 17 Mar 2006 16:47:06 +0000 (16:47 +0000)
ajde/testsrc/org/aspectj/ajde/AsmDeclarationsTest.java
ajde/testsrc/org/aspectj/ajde/AsmRelationshipsTest.java
ajdoc/testsrc/org/aspectj/tools/ajdoc/CoverageTestCase.java
asm/src/org/aspectj/asm/internal/ProgramElement.java
tests/bugs151/pr132130.aj [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java
tests/src/org/aspectj/systemtest/ajc151/ajc151.xml

index 1925ea02b02fbce82b174c82b5c2f5af666349dd..9411c433de32954ba484c6dfb9b03abdeb7116d8 100644 (file)
@@ -111,7 +111,7 @@ public class AsmDeclarationsTest extends AjdeTestCase {
                assertNotNull(fieldNode);               
                assertEquals(fieldNode.toLabelString(), fieldMsg);
 
-               String methodMsg = "Point.check(int, Line)";
+               String methodMsg = "Point.check(int,Line)";
                IProgramElement methodNode = model.findElementForLabel(aspect, IProgramElement.Kind.INTER_TYPE_METHOD, methodMsg);
                assertNotNull(methodNode);              
                assertEquals(methodNode.toLabelString(), methodMsg);
@@ -135,7 +135,7 @@ public class AsmDeclarationsTest extends AjdeTestCase {
                assertNotNull(ptctNode);                
                assertEquals(ptctNode.toLabelString(), ptct);           
 
-               String params = "namedWithArgs(int, int)";
+               String params = "namedWithArgs(int,int)";
                IProgramElement paramsNode = model.findElementForSignature(aspect, IProgramElement.Kind.POINTCUT, params);
                assertNotNull(paramsNode);              
                assertEquals(paramsNode.toLabelString(), params);       
@@ -176,7 +176,7 @@ public class AsmDeclarationsTest extends AjdeTestCase {
                assertNotNull(namedWithOneArgNode);             
                assertEquals(namedWithOneArgNode.toLabelString(), namedWithOneArg);             
 
-               String afterReturning = "afterReturning(int, int): namedWithArgs..";
+               String afterReturning = "afterReturning(int,int): namedWithArgs..";
                IProgramElement afterReturningNode = model.findElementForLabel(aspect, IProgramElement.Kind.ADVICE, afterReturning);
                assertNotNull(afterReturningNode);              
                assertEquals(afterReturningNode.toLabelString(), afterReturning);
index ce89a6c6a47f13e2a684b6ad77c689f01f2798d0..1b674dc1564778b587d6f26eaa20417629270b47 100644 (file)
@@ -82,7 +82,7 @@ public class AsmRelationshipsTest extends AjdeTestCase {
        public void testInterTypeDeclarations() {               
                checkInterTypeMapping("InterTypeDecCoverage", "Point", "Point.xxx", "Point", 
                        "declared on", "aspect declarations", IProgramElement.Kind.INTER_TYPE_FIELD);   
-               checkInterTypeMapping("InterTypeDecCoverage", "Point", "Point.check(int, Line)", 
+               checkInterTypeMapping("InterTypeDecCoverage", "Point", "Point.check(int,Line)", 
                        "Point", "declared on", "aspect declarations", IProgramElement.Kind.INTER_TYPE_METHOD); 
        }
 
index f0d86072d97e6be52cd3092c8938f9c1e1619d13..09d6ede30006d4eb0742e46f23ea2a4312cca66c 100644 (file)
@@ -170,7 +170,7 @@ public class CoverageTestCase extends AjdocTestCase {
         
                String[] strings = { 
                                "after(): named..",
-                               "afterReturning(int, int): namedWithArgs..",
+                               "afterReturning(int,int): namedWithArgs..",
                                "afterThrowing(): named..",
                                "before(): named..",
                                "around(int): namedWithOneArg..",
index e153c1624570ada597e9ac0f5a16460828b348a9..b78b3bbdabed6bcd0dc8cb2fe13fda5b12e9c745 100644 (file)
@@ -427,7 +427,7 @@ public class ProgramElement implements IProgramElement {
                                                sb.append(arg);
                                        }
                                }
-                               if (it.hasNext()) sb.append(", ");
+                               if (it.hasNext()) sb.append(",");
                        }
                        sb.append(')');
                }
diff --git a/tests/bugs151/pr132130.aj b/tests/bugs151/pr132130.aj
new file mode 100644 (file)
index 0000000..3259d72
--- /dev/null
@@ -0,0 +1,17 @@
+ aspect basic {
+
+    declare @method : * debit(..) : @Secured(role="supervisor");
+    declare @constructor : BankAccount+.new(..) : @Secured(role="supervisor");
+}
+
+class BankAccount {
+       
+       public BankAccount(String s, int i) {
+       }
+    public void debit(long accId,long amount) {
+    }
+}
+
+@interface Secured {
+    String role();
+}
index 93ea088935660f6c9a7c0099822b2f828d62b469..2c33e7bb674d71c44bbbf4bc8792122c85df84a8 100644 (file)
@@ -75,13 +75,13 @@ public class Ajc151Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
          IProgramElement pe = top.findElementForType("pkg","foo");
          assertNotNull("Couldn't find 'foo' element in the tree",pe);
          // check that the defaults return the fully qualified arg
-         assertEquals("foo(int, java.lang.Object)",pe.toLabelString());
-         assertEquals("C.foo(int, java.lang.Object)",pe.toLinkLabelString());
-         assertEquals("foo(int, java.lang.Object)",pe.toSignatureString());
+         assertEquals("foo(int,java.lang.Object)",pe.toLabelString());
+         assertEquals("C.foo(int,java.lang.Object)",pe.toLinkLabelString());
+         assertEquals("foo(int,java.lang.Object)",pe.toSignatureString());
          // check that can get hold of the non qualified args
-         assertEquals("foo(int, Object)",pe.toLabelString(false));
-         assertEquals("C.foo(int, Object)",pe.toLinkLabelString(false));
-         assertEquals("foo(int, Object)",pe.toSignatureString(false));
+         assertEquals("foo(int,Object)",pe.toLabelString(false));
+         assertEquals("C.foo(int,Object)",pe.toLinkLabelString(false));
+         assertEquals("foo(int,Object)",pe.toSignatureString(false));
 
          IProgramElement pe2 = top.findElementForType("pkg","printParameters");
          assertNotNull("Couldn't find 'printParameters' element in the tree",pe2);
@@ -192,6 +192,70 @@ public class Ajc151Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
                          + target.toLabelString(),constructor,target);
   }
   
+  
+  public void testDeclareAnnotationAppearsInStructureModel_pr132130() {
+         //AsmManager.setReporting("c:/debug.txt",true,true,true,true);
+         runTest("declare annotation appears in structure model when in same file");
+         IHierarchy top = AsmManager.getDefault().getHierarchy();
+         
+         // get the IProgramElements corresponding to the different code entries
+         IProgramElement decam = top.findElementForLabel(top.getRoot(),
+                         IProgramElement.Kind.DECLARE_ANNOTATION_AT_METHOD,"declare @method: * debit(..) : @Secured(role = \"supervisor\")");                   
+         assertNotNull("Couldn't find 'declare @method' element in the tree",decam);
+         IProgramElement method = top.findElementForLabel(top.getRoot(),
+                         IProgramElement.Kind.METHOD,"debit(long,long)");
+         assertNotNull("Couldn't find the 'debit(long,long)' method element in the tree",method);
+         IProgramElement decac = top.findElementForLabel(top.getRoot(),
+                         IProgramElement.Kind.DECLARE_ANNOTATION_AT_CONSTRUCTOR,"declare @constructor: BankAccount+.new(..) : @Secured(role = \"supervisor\")");                
+         assertNotNull("Couldn't find 'declare @constructor' element in the tree",decac);
+         IProgramElement ctr = top.findElementForLabel(top.getRoot(),
+                         IProgramElement.Kind.CONSTRUCTOR,"BankAccount(String,int)");
+         assertNotNull("Couldn't find the 'BankAccount(String,int)' constructor element in the tree",ctr);
+
+         
+         // check that decam has a annotates relationship with the debit method
+         List matches = AsmManager.getDefault().getRelationshipMap().get(decam);       
+         assertNotNull("'declare @method' should have some relationships but does not",matches);
+         assertTrue("'declare @method' should have one relationships but has " + matches.size(),matches.size()==1);
+         List matchesTargets = ((Relationship)matches.get(0)).getTargets();
+         assertTrue("'declare @method' should have one targets but has" + matchesTargets.size(),matchesTargets.size()==1);
+         IProgramElement target = AsmManager.getDefault().getHierarchy().findElementForHandle((String)matchesTargets.get(0));
+         assertEquals("target of relationship should be the 'debit(long,long)' method but is IPE with label "
+                         + target.toLabelString(),method,target);
+         
+         // check that the debit method has an annotated by relationship with the declare @method
+         matches = AsmManager.getDefault().getRelationshipMap().get(method);   
+         assertNotNull("'debit(long,long)' should have some relationships but does not",matches);
+         assertTrue("'debit(long,long)' should have one relationships but has " + matches.size(),matches.size()==1);
+         matchesTargets = ((Relationship)matches.get(0)).getTargets();
+         assertTrue("'debit(long,long)' should have one targets but has" + matchesTargets.size(),matchesTargets.size()==1);
+         target = AsmManager.getDefault().getHierarchy().findElementForHandle((String)matchesTargets.get(0));
+         assertEquals("target of relationship should be the 'declare @method' ipe but is IPE with label "
+                         + target.toLabelString(),decam,target);
+
+         // check that decac has a annotates relationship with the constructor
+         matches = AsmManager.getDefault().getRelationshipMap().get(decac);    
+         assertNotNull("'declare @method' should have some relationships but does not",matches);
+         assertTrue("'declare @method' should have one relationships but has " + matches.size(),matches.size()==1);
+         matchesTargets = ((Relationship)matches.get(0)).getTargets();
+         assertTrue("'declare @method' should have one targets but has" + matchesTargets.size(),matchesTargets.size()==1);
+         target = AsmManager.getDefault().getHierarchy().findElementForHandle((String)matchesTargets.get(0));
+         assertEquals("target of relationship should be the 'debit(long, long)' method but is IPE with label "
+                         + target.toLabelString(),ctr,target);
+         
+         // check that the constructor has an annotated by relationship with the declare @constructor
+         matches = AsmManager.getDefault().getRelationshipMap().get(ctr);      
+         assertNotNull("'debit(long, long)' should have some relationships but does not",matches);
+         assertTrue("'debit(long, long)' should have one relationships but has " + matches.size(),matches.size()==1);
+         matchesTargets = ((Relationship)matches.get(0)).getTargets();
+         assertTrue("'debit(long, long)' should have one targets but has" + matchesTargets.size(),matchesTargets.size()==1);
+         target = AsmManager.getDefault().getHierarchy().findElementForHandle((String)matchesTargets.get(0));
+         assertEquals("target of relationship should be the 'declare @method' ipe but is IPE with label "
+                         + target.toLabelString(),decac,target);
+
+
+  }
+  
   /*
    * @AspectJ bugs and enhancements
    */
index 0c03c2b0b767223c18303c98fce363c6451caacc..5d83c75f5bfd57730591a5d7583b3be51f60b365 100644 (file)
         <compile files="pr131932.aj" options="-1.5 -emacssym"/>
     </ajc-test>
 
+    <ajc-test dir="bugs151" title="declare annotation appears in structure model when in same file">
+        <compile files="pr132130.aj" options="-1.5 -emacssym"/>
+    </ajc-test>
+
     <!-- New features down here... when they arent big enough to have their own test file -->
     
     <ajc-test dir="features151/ptw" title="exposing withintype">