aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authoraclement <aclement>2006-06-19 10:17:28 +0000
committeraclement <aclement>2006-06-19 10:17:28 +0000
commitabe25b029852a8c8e1c682a9a59413896d18dd2b (patch)
tree04eada1bb3d2e225f1f2986f1b6c3a48a7240ea5 /tests
parentfdbae3fda3e572ea35ac4a73373896b9b5cff8f7 (diff)
downloadaspectj-abe25b029852a8c8e1c682a9a59413896d18dd2b.tar.gz
aspectj-abe25b029852a8c8e1c682a9a59413896d18dd2b.zip
testcode and patches for pr141730 comments #13,14: "new handleprovider"
Diffstat (limited to 'tests')
-rw-r--r--tests/bugs152/pr141730/aspectpath/MyBar.aj9
-rw-r--r--tests/bugs152/pr141730/aspectpath/MyFoo.java11
-rw-r--r--tests/bugs152/pr141730/aspectpath/aspectpath.jarbin0 -> 1377 bytes
-rw-r--r--tests/bugs152/pr141730/inpath/MyAnnotation.java5
-rw-r--r--tests/bugs152/pr141730/inpath/MyBar.aj18
-rw-r--r--tests/bugs152/pr141730/inpath/MyFoo.java25
-rw-r--r--tests/bugs152/pr141730/inpath/NewClass.java5
-rw-r--r--tests/bugs152/pr141730/inpath/inpath.jarbin0 -> 739 bytes
-rw-r--r--tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java102
-rw-r--r--tests/src/org/aspectj/systemtest/ajc152/ajc152.xml10
-rw-r--r--tests/src/org/aspectj/systemtest/incremental/tools/MultiProjectIncrementalTests.java37
11 files changed, 187 insertions, 35 deletions
diff --git a/tests/bugs152/pr141730/aspectpath/MyBar.aj b/tests/bugs152/pr141730/aspectpath/MyBar.aj
new file mode 100644
index 000000000..3a38885ce
--- /dev/null
+++ b/tests/bugs152/pr141730/aspectpath/MyBar.aj
@@ -0,0 +1,9 @@
+package bar;
+
+public aspect MyBar {
+
+ before() : call(* main(..)) {
+ System.out.println("about to call a main method");
+ }
+
+}
diff --git a/tests/bugs152/pr141730/aspectpath/MyFoo.java b/tests/bugs152/pr141730/aspectpath/MyFoo.java
new file mode 100644
index 000000000..d733097cf
--- /dev/null
+++ b/tests/bugs152/pr141730/aspectpath/MyFoo.java
@@ -0,0 +1,11 @@
+package foo;
+
+public class MyFoo {
+
+ public void callMain() {
+ new MyFoo().main();
+ }
+
+ public void main() {
+ }
+}
diff --git a/tests/bugs152/pr141730/aspectpath/aspectpath.jar b/tests/bugs152/pr141730/aspectpath/aspectpath.jar
new file mode 100644
index 000000000..27ccd5aa7
--- /dev/null
+++ b/tests/bugs152/pr141730/aspectpath/aspectpath.jar
Binary files differ
diff --git a/tests/bugs152/pr141730/inpath/MyAnnotation.java b/tests/bugs152/pr141730/inpath/MyAnnotation.java
new file mode 100644
index 000000000..16a690ce2
--- /dev/null
+++ b/tests/bugs152/pr141730/inpath/MyAnnotation.java
@@ -0,0 +1,5 @@
+package bar;
+
+public @interface MyAnnotation {
+
+}
diff --git a/tests/bugs152/pr141730/inpath/MyBar.aj b/tests/bugs152/pr141730/inpath/MyBar.aj
new file mode 100644
index 000000000..50ea6efd0
--- /dev/null
+++ b/tests/bugs152/pr141730/inpath/MyBar.aj
@@ -0,0 +1,18 @@
+package bar;
+
+import foo.*;
+
+public aspect MyBar {
+
+ before() : call(* main(..)) {}
+
+ declare warning: get( * System.out ) : "System.out should not be called";
+
+ declare parents : *Foo extends NewClass;
+
+ declare @type : *Foo* : @MyAnnotation;
+ declare @method : public * *Foo.anotMethod(..) : @MyAnnotation;
+ declare @constructor : *Foo.new(String) : @MyAnnotation;
+ declare @field : int *Foo.* : @MyAnnotation ;
+
+}
diff --git a/tests/bugs152/pr141730/inpath/MyFoo.java b/tests/bugs152/pr141730/inpath/MyFoo.java
new file mode 100644
index 000000000..d9aba23f4
--- /dev/null
+++ b/tests/bugs152/pr141730/inpath/MyFoo.java
@@ -0,0 +1,25 @@
+package foo;
+
+public class MyFoo {
+
+ public int i;
+
+ public MyFoo() {
+ super();
+ }
+
+ public MyFoo(String s) {
+ super();
+ }
+
+ public void callMain() {
+ new MyFoo().main();
+ }
+
+ public void main() {
+ System.out.println("blah");
+ }
+
+ public void anotMethod() {
+ }
+}
diff --git a/tests/bugs152/pr141730/inpath/NewClass.java b/tests/bugs152/pr141730/inpath/NewClass.java
new file mode 100644
index 000000000..cdbce29e5
--- /dev/null
+++ b/tests/bugs152/pr141730/inpath/NewClass.java
@@ -0,0 +1,5 @@
+package bar;
+
+public class NewClass {
+
+}
diff --git a/tests/bugs152/pr141730/inpath/inpath.jar b/tests/bugs152/pr141730/inpath/inpath.jar
new file mode 100644
index 000000000..ba262c555
--- /dev/null
+++ b/tests/bugs152/pr141730/inpath/inpath.jar
Binary files differ
diff --git a/tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java b/tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java
index 3b23af93a..c33abb8ab 100644
--- a/tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java
+++ b/tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java
@@ -12,6 +12,7 @@ package org.aspectj.systemtest.ajc152;
import java.io.File;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import junit.framework.Test;
@@ -19,9 +20,11 @@ import junit.framework.Test;
import org.aspectj.asm.AsmManager;
import org.aspectj.asm.IHierarchy;
import org.aspectj.asm.IProgramElement;
+import org.aspectj.asm.IRelationshipMap;
import org.aspectj.asm.internal.Relationship;
import org.aspectj.testing.XMLBasedAjcTestCase;
import org.aspectj.util.CharOperation;
+import org.aspectj.weaver.World;
public class Ajc152Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
@@ -185,8 +188,105 @@ public class Ajc152Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
checkSignatureOfIPE("MyClass.MyClass()",IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR);
}
-
+ // if not filling in the model for aspects contained in jar files then
+ // want to ensure that the relationship map is correct and has nodes
+ // which can be used in AJDT - ensure no NPE occurs for the end of
+ // the relationship with aspectpath
+ public void testAspectPathRelWhenNotFillingInModel_pr141730() {
+ World.createInjarHierarchy = false;
+ try {
+ runTest("ensure aspectpath injar relationships are correct when not filling in model");
+
+ // expecting:
+ // sourceOfRelationship main in MyFoo.java
+ // relationship advised by
+ // target MyBar.aj
+ //
+ // and
+ //
+ // sourceOfRelationship MyBar.aj
+ // relationship advises
+ // target main in MyFoo.java
+
+
+ IHierarchy top = AsmManager.getDefault().getHierarchy();
+ IRelationshipMap asmRelMap = AsmManager.getDefault().getRelationshipMap();
+ assertEquals("expected two sources of relationships but only found "
+ + asmRelMap.getEntries().size(),2,asmRelMap.getEntries().size());
+ for (Iterator iter = asmRelMap.getEntries().iterator(); iter.hasNext();) {
+ String sourceOfRelationship = (String) iter.next();
+ IProgramElement ipe = top.findElementForHandle(sourceOfRelationship);
+ List relationships = asmRelMap.get(ipe);
+ if (ipe.getName().equals("MyBar.aj")) {
+ assertEquals("expected MyBar.aj to have one relationships but found "
+ + relationships.size(),1,relationships.size());
+ Relationship rel = (Relationship)relationships.get(0);
+ assertEquals("expected relationship to be 'advises' but was "
+ + rel.getName(), "advises", rel.getName());
+ List targets = rel.getTargets();
+ assertEquals("expected one target but found " + targets.size(),1,targets.size());
+ IProgramElement link = top.findElementForHandle((String)targets.get(0));
+ assertEquals("expected target 'method-call(void foo.MyFoo.main())' but target " + link.getName(),
+ "method-call(void foo.MyFoo.main())",link.getName());
+ String fileName = link.getSourceLocation().getSourceFile().toString();
+ assertTrue("expected 'main' to be in class MyFoo.java but found it " +
+ "in " + fileName,fileName.indexOf("MyFoo.java") != -1);
+ } else if (ipe.getName().equals("method-call(void foo.MyFoo.main())")) {
+ String fileName = ipe.getSourceLocation().getSourceFile().toString();
+ assertTrue("expected 'method-call(void foo.MyFoo.main())' to be in " +
+ "class MyFoo.java but found it in"
+ + fileName,fileName.indexOf("MyFoo.java") != -1);
+ assertEquals("expected 'method-call(void foo.MyFoo.main())' " +
+ "to have one relationships but found "
+ + relationships.size(),1,relationships.size());
+ Relationship rel = (Relationship)relationships.get(0);
+ assertEquals("expected relationship to be 'advised by' but was "
+ + rel.getName(), "advised by", rel.getName());
+ List targets = rel.getTargets();
+ assertEquals("expected one target but found " + targets.size(),1,targets.size());
+ IProgramElement link = top.findElementForHandle((String)targets.get(0));
+ assertEquals("expected target 'MyBar.aj' but target " + link.getName(),
+ "MyBar.aj",link.getName());
+
+ } else {
+ fail("unexpected element " + ipe.getName() + " in the relationship map");
+ }
+ }
+ } finally {
+ World.createInjarHierarchy = true;
+ }
+ }
+ // if not filling in the model for classes contained in jar files then
+ // want to ensure that the relationship map is correct and has nodes
+ // which can be used in AJDT - ensure no NPE occurs for the end of
+ // the relationship with inpath
+ public void testNoNPEWithInpathWhenNotFillingInModel_pr141730() {
+ World.createInjarHierarchy = false;
+ try {
+ runTest("ensure inpath injar relationships are correct when not filling in model");
+ // the aspect used for this test has advice, declare parents, deow,
+ // and declare @type, @constructor, @field and @method. We only expect
+ // there to be relationships in the map for declare parents and declare @type
+ // (provided the model isn't being filled in) because the logic in the other
+ // addXXXRelationship methods use AspectJElementHierarchy.findElementForType().
+ // This method which returns null because there is no such ipe. The relationship is
+ // therefore not added to the model. Adding declare @type and declare parents
+ // uses AspectJElementHierarchy.findElementForHandle() which returns the file
+ // node ipe if it can't find one for the given handle. Therefore the relationships
+ // are added against the file node. Before change to using ipe's to create handles
+ // we also had the deow relationship, however, now we don't because this also
+ // uses findElementForType to find the targetNode which in the inpath case is null.
+
+ // just check that the number of entries is what we expect:
+ // We expect 3 (the declare @type and declare parents statements plus the filenode)
+ IRelationshipMap relMap = AsmManager.getDefault().getRelationshipMap();
+ assertEquals("expected 3 entries in the relationship map but found "
+ + relMap.getEntries().size(), 3, relMap.getEntries().size());
+ } finally {
+ World.createInjarHierarchy = true;
+ }
+ }
// public void testFunkyGenericErrorWithITDs_pr126355_2() {
// runTest("bizarre generic error with itds - 2");
diff --git a/tests/src/org/aspectj/systemtest/ajc152/ajc152.xml b/tests/src/org/aspectj/systemtest/ajc152/ajc152.xml
index b91caf7ea..77e80c794 100644
--- a/tests/src/org/aspectj/systemtest/ajc152/ajc152.xml
+++ b/tests/src/org/aspectj/systemtest/ajc152/ajc152.xml
@@ -667,6 +667,16 @@
</stderr>
</run>
</ajc-test>
+
+ <ajc-test dir="bugs152/pr141730/aspectpath" title="ensure aspectpath injar relationships are correct when not filling in model">
+ <compile files="MyFoo.java" aspectpath="aspectpath.jar" options="-emacssym"/>
+ </ajc-test>
+
+ <ajc-test dir="bugs152/pr141730/inpath" title="ensure inpath injar relationships are correct when not filling in model">
+ <compile files="MyBar.aj, MyAnnotation.java, NewClass.java" inpath="inpath.jar" options="-1.5 -emacssym">
+ <message kind="warning" line="20" text="System.out should not be called"/>
+ </compile>
+ </ajc-test>
<ajc-test dir="ltw" title="weaveinfo messages with include and exclude">
<compile files="EmptyTest1.java, EmptyTest2.java"/>
diff --git a/tests/src/org/aspectj/systemtest/incremental/tools/MultiProjectIncrementalTests.java b/tests/src/org/aspectj/systemtest/incremental/tools/MultiProjectIncrementalTests.java
index 1271a6bea..1f5793688 100644
--- a/tests/src/org/aspectj/systemtest/incremental/tools/MultiProjectIncrementalTests.java
+++ b/tests/src/org/aspectj/systemtest/incremental/tools/MultiProjectIncrementalTests.java
@@ -31,6 +31,7 @@ import org.aspectj.asm.IRelationship;
import org.aspectj.asm.IRelationshipMap;
import org.aspectj.asm.internal.Relationship;
import org.aspectj.bridge.IMessage;
+import org.aspectj.tools.ajc.Ajc;
import org.aspectj.weaver.World;
/**
@@ -79,14 +80,14 @@ public class MultiProjectIncrementalTests extends AbstractMultiProjectIncrementa
configureBuildStructureModel(true);
initialiseProject("P4");
build("P4");
- dumpAJDEStructureModel("after full build where advice is applying");
+ Ajc.dumpAJDEStructureModel("after full build where advice is applying");
// should be 4 relationship entries
// In inc1 the first advised line is 'commented out'
alter("P4","inc1");
build("P4");
checkWasntFullBuild();
- dumpAJDEStructureModel("after inc build where first advised line is gone");
+ Ajc.dumpAJDEStructureModel("after inc build where first advised line is gone");
// should now be 2 relationship entries
// This will be the line 6 entry in C.java
@@ -1440,38 +1441,6 @@ public class MultiProjectIncrementalTests extends AbstractMultiProjectIncrementa
" in the aop.xml file but found " + aspectCount + " occurrences");
}
}
-
-
- private void dumpAJDEStructureModel(String prefix) {
- System.out.println("======================================");//$NON-NLS-1$
- System.out.println("start of AJDE structure model:"+prefix); //$NON-NLS-1$
-
- IRelationshipMap asmRelMap = AsmManager.getDefault().getRelationshipMap();
- for (Iterator iter = asmRelMap.getEntries().iterator(); iter.hasNext();) {
- String sourceOfRelationship = (String) iter.next();
- IProgramElement ipe = AsmManager.getDefault().getHierarchy()
- .findElementForHandle(sourceOfRelationship);
- System.err.println("Examining source relationship handle: "+sourceOfRelationship);
- List relationships = asmRelMap.get(ipe);
- if (relationships != null) {
- for (Iterator iterator = relationships.iterator(); iterator.hasNext();) {
- Relationship rel = (Relationship) iterator.next();
- List targets = rel.getTargets();
- for (Iterator iterator2 = targets.iterator(); iterator2.hasNext();) {
- String t = (String) iterator2.next();
- IProgramElement link = AsmManager.getDefault().getHierarchy().findElementForHandle(t);
- System.out.println(""); //$NON-NLS-1$
- System.out.println(" sourceOfRelationship " + sourceOfRelationship); //$NON-NLS-1$
- System.out.println(" relationship " + rel.getName()); //$NON-NLS-1$
- System.out.println(" target " + link.getName()); //$NON-NLS-1$
- }
- }
-
- }
- }
- System.out.println("End of AJDE structure model"); //$NON-NLS-1$
- System.out.println("======================================");//$NON-NLS-1$
- }
private File getProjectRelativePath(String p,String filename) {
File projDir = new File(getWorkingDir(),p);