]> source.dussan.org Git - aspectj.git/commitdiff
test and fixes for 143930, 143924
authoraclement <aclement>
Tue, 30 May 2006 09:59:53 +0000 (09:59 +0000)
committeraclement <aclement>
Tue, 30 May 2006 09:59:53 +0000 (09:59 +0000)
ajdoc/testsrc/org/aspectj/tools/ajdoc/CoverageTestCase.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmElementFormatter.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmHierarchyBuilder.java
tests/bugs152/pr143924.aj [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java
tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java
tests/src/org/aspectj/systemtest/ajc152/ajc152.xml
weaver/src/org/aspectj/weaver/AsmRelationshipProvider.java

index 09d6ede30006d4eb0742e46f23ea2a4312cca66c..b76b0b11643cd0ff55a01f6f3876df6215b53b65 100644 (file)
@@ -211,7 +211,7 @@ public class CoverageTestCase extends AjdocTestCase {
                                "before(): getP..",
                                "HREF=\"../foo/Point.html#getX()\"",
                                "before(): setP..",
-                               "HREF=\"../foo/Point.html\"><tt>foo.Point</tt></A>, <A HREF=\"../foo/Point.html#Point()\"><tt>foo.Point.Point()</tt></A>, <A HREF=\"../foo/Point.html#setX(int)\"",
+                               "HREF=\"../foo/Point.html\"><tt>foo.Point</tt></A>, <A HREF=\"../foo/Point.html#Point()\"><tt>foo.Point.Point</tt></A>, <A HREF=\"../foo/Point.html#setX(int)\"",
                                "before(): initializationP..",
                                "HREF=\"../foo/Point.html#Point()\"",
                                "before(): staticinitializationP..",
index 0916356d7131ac22efc8887f3526ebaced3c97e0..ee303df18a727d666ca0e27ad1213e1536481b2c 100644 (file)
@@ -40,6 +40,7 @@ import org.aspectj.weaver.patterns.ReferencePointcut;
 import org.aspectj.weaver.patterns.TypePattern;
 import org.aspectj.weaver.patterns.TypePatternList;
 import org.aspectj.org.eclipse.jdt.core.compiler.CharOperation;
+import org.aspectj.org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
 import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Argument;
 import org.aspectj.org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
 import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation;
@@ -291,7 +292,7 @@ public class AsmElementFormatter {
 //             return args;
 //     }
 
-       private void setParameters(MethodDeclaration md, IProgramElement pe) {
+       public void setParameters(AbstractMethodDeclaration md, IProgramElement pe) {
                Argument[] argArray = md.arguments;
                if (argArray == null) {
                        pe.setParameterNames(Collections.EMPTY_LIST);
index 4b48ccff19225df904878f1b5b5e6e6b302d4042..2912e787c8ddf74720125da802f46ce9081e7d12 100644 (file)
@@ -711,12 +711,12 @@ public class AsmHierarchyBuilder extends ASTVisitor {
                }
                argumentsSignature.append(")");
                IProgramElement peNode = new ProgramElement(
-                       new String(constructorDeclaration.selector)+argumentsSignature,
+                       new String(constructorDeclaration.selector),
                        IProgramElement.Kind.CONSTRUCTOR,       
                        makeLocation(constructorDeclaration),
                        constructorDeclaration.modifiers,
                        null,null);
-               
+               formatter.setParameters(constructorDeclaration, peNode);
                peNode.setModifiers(constructorDeclaration.modifiers);
                peNode.setSourceSignature(genSourceSignature(constructorDeclaration));
                
diff --git a/tests/bugs152/pr143924.aj b/tests/bugs152/pr143924.aj
new file mode 100644 (file)
index 0000000..7ea1e8d
--- /dev/null
@@ -0,0 +1,13 @@
+aspect DeclareAnnotation {
+    declare @method : * debit(..) : @Secured(role="supervisor");
+}
+
+class BankAccount {
+
+    public void debit(String accId,long amount) {
+    }
+}
+
+@interface Secured {
+    String role();
+}
index 3a76b645c1d9fac93fcbb92d087e6180ecc42e9a..443418a78658cdd44acb2ec239749349a4333150 100644 (file)
@@ -232,7 +232,7 @@ public class Ajc151Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
                          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)");
+                         IProgramElement.Kind.CONSTRUCTOR,"BankAccount(java.lang.String,int)");
          assertNotNull("Couldn't find the 'BankAccount(String,int)' constructor element in the tree",ctr);
 
          
index 405f5625050ead7bbaec3c82b59d7f61342cfc4b..67cb7c1db4f92c0e78d8d71ad70232867d0be637 100644 (file)
 package org.aspectj.systemtest.ajc152;
 
 import java.io.File;
+import java.util.List;
+
 import junit.framework.Test;
 
 //import org.aspectj.systemtest.ajc150.GenericsTests;
+import org.aspectj.asm.AsmManager;
+import org.aspectj.asm.IHierarchy;
+import org.aspectj.asm.IProgramElement;
+import org.aspectj.asm.internal.Relationship;
 import org.aspectj.testing.XMLBasedAjcTestCase;
 
 public class Ajc152Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
@@ -68,6 +74,41 @@ public class Ajc152Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
   public void testSuperCallsInAtAspectJAdvice_pr139749() { runTest("Super calls in @AspectJ advice");}
   public void testNoClassCastExceptionWithPerThis_pr138286() { runTest("No ClassCastException with perThis");}
   
+  public void testDeclareAtMethodRelationship_pr143924() {
+         //AsmManager.setReporting("c:/debug.txt",true,true,true,true);
+         runTest("declare @method relationship");
+         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(java.lang.String,long)");
+         assertNotNull("Couldn't find the 'debit(String,long)' method element in the tree",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(java.lang.String,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(java.lang.String,long)' should have some relationships but does not",matches);
+         assertTrue("'debit(java.lang.String,long)' should have one relationships but has " + matches.size(),matches.size()==1);
+         matchesTargets = ((Relationship)matches.get(0)).getTargets();
+         assertTrue("'debit(java.lang.String,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);
+         
+  }
+  
 // this next one reported as a bug by Rob Harrop, but I can't reproduce the failure yet...
 //public void testAtAspectWithReferencePCPerClause_pr138220() { runTest("@Aspect with reference pointcut in perclause");}  
 
index 4230c07f98b6f371395af3aa3302231d8c520f79..5741576b1558de12979a60c04ea2b4278c3a9efc 100644 (file)
       <compile files="Covariance.java" options="-1.5"/>
     </ajc-test>
     
+    <ajc-test dir="bugs152" title="declare @method relationship">
+     <compile files="pr143924.aj" options="-1.5 -showWeaveInfo -emacssym">
+        <message kind="weave" text="'public void BankAccount.debit(String,long)' (pr143924.aj:7) is annotated with @Secured"/>
+     </compile>
+    </ajc-test>
+
     <!-- wont work whilst the compiler BuildArgParser.setDebugOptions is always switching debug on -->
     <ajc-test dir="bugs152/pr129408" title="long winded ataj messages">
       <compile files="AtAj.java" options="-XterminateAfterCompilation -g:none -1.5"/>
index 96db20473a9edbd572d15c4d8382a3ab90a997b9..636c9589821c13081b0dd64bd64e4953d8b5ae22 100644 (file)
@@ -369,8 +369,7 @@ public class AsmRelationshipProvider {
          Type[] args = method.getArgumentTypes();
          for (int i = 0; i < args.length; i++) {
                        Type type2 = args[i];
-                       String s = Utility.signatureToString(type2.getSignature());
-                       if (s.lastIndexOf(".")!=-1) s =s.substring(s.lastIndexOf(".")+1);
+                       String s = Utility.signatureToString(type2.getSignature(),false);
                        parmString.append(s);
                        if ((i+1)<args.length) parmString.append(",");
          }