summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorhsestupin <stupin.sergey@gmail.com>2014-08-14 12:54:28 +0400
committerAndy Clement <aclement@gopivotal.com>2014-08-14 11:11:08 -0700
commit66469244e4aa352f0db6d91854541a85d68e7032 (patch)
treecd942afb3382dcfbbb831e4468db450168d3f4ec /tests
parentac48f780a46720f201ac893c8fbf9b1e17cc60d4 (diff)
downloadaspectj-66469244e4aa352f0db6d91854541a85d68e7032.tar.gz
aspectj-66469244e4aa352f0db6d91854541a85d68e7032.zip
add APT test generating Java files
Signed-off-by: hsestupin <stupin.sergey@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/apt/test1/Event.java (renamed from tests/apt/processor/Event.java)0
-rw-r--r--tests/apt/test1/SimpleProcessor.java (renamed from tests/apt/processor/SimpleProcessor.java)0
-rw-r--r--tests/apt/test1/Some.java (renamed from tests/apt/src/Some.java)0
-rw-r--r--tests/apt/test1/apt_service_description.jar (renamed from tests/apt/apt_service_description.jar)bin542 -> 542 bytes
-rw-r--r--tests/apt/test2/Code.java12
-rw-r--r--tests/apt/test2/DemoProcessor.java46
-rw-r--r--tests/apt/test2/Marker.java8
-rw-r--r--tests/src/org/aspectj/systemtest/apt/AptTests.java50
-rw-r--r--tests/src/org/aspectj/systemtest/apt/apt-spec.xml32
9 files changed, 115 insertions, 33 deletions
diff --git a/tests/apt/processor/Event.java b/tests/apt/test1/Event.java
index 9ac973f45..9ac973f45 100644
--- a/tests/apt/processor/Event.java
+++ b/tests/apt/test1/Event.java
diff --git a/tests/apt/processor/SimpleProcessor.java b/tests/apt/test1/SimpleProcessor.java
index 292dcd8d4..292dcd8d4 100644
--- a/tests/apt/processor/SimpleProcessor.java
+++ b/tests/apt/test1/SimpleProcessor.java
diff --git a/tests/apt/src/Some.java b/tests/apt/test1/Some.java
index b47aa787e..b47aa787e 100644
--- a/tests/apt/src/Some.java
+++ b/tests/apt/test1/Some.java
diff --git a/tests/apt/apt_service_description.jar b/tests/apt/test1/apt_service_description.jar
index f823b1784..f823b1784 100644
--- a/tests/apt/apt_service_description.jar
+++ b/tests/apt/test1/apt_service_description.jar
Binary files differ
diff --git a/tests/apt/test2/Code.java b/tests/apt/test2/Code.java
new file mode 100644
index 000000000..fa7ceebc9
--- /dev/null
+++ b/tests/apt/test2/Code.java
@@ -0,0 +1,12 @@
+public class Code {
+
+ public void moo() {}
+
+ @Marker
+ public void boo() {}
+
+ @Marker
+ public void too() {}
+
+ public void woo() {}
+} \ No newline at end of file
diff --git a/tests/apt/test2/DemoProcessor.java b/tests/apt/test2/DemoProcessor.java
new file mode 100644
index 000000000..19498c07e
--- /dev/null
+++ b/tests/apt/test2/DemoProcessor.java
@@ -0,0 +1,46 @@
+import java.io.*;
+import javax.tools.*;
+import javax.tools.Diagnostic.Kind;
+
+import java.util.*;
+import javax.annotation.processing.*;
+import javax.lang.model.*;
+import javax.lang.model.element.*;
+
+@SupportedAnnotationTypes(value= {"*"})
+@SupportedSourceVersion(SourceVersion.RELEASE_6)
+public class DemoProcessor extends AbstractProcessor {
+
+ private Filer filer;
+ private Messager messager;
+
+ @Override
+ public void init(ProcessingEnvironment env) {
+ filer = env.getFiler();
+ messager = env.getMessager();
+ }
+
+ @Override
+ public boolean process(Set elements, RoundEnvironment env) {
+ for (Element element: env.getElementsAnnotatedWith(Marker.class)) {
+ if (element.getKind() == ElementKind.METHOD) {
+ // Create an aspect targeting this method!
+ String methodName = element.getSimpleName().toString();
+ String aspectText =
+ "public aspect Advise_"+methodName+" {\n"+
+ " before(): execution(* "+methodName+"(..)) {\n"+
+ " System.out.println(\""+methodName+" running\");\n"+
+ " }\n"+
+ "}\n";
+ try {
+ JavaFileObject file = filer.createSourceFile("Advise_"+methodName, element);
+ file.openWriter().append(aspectText).close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ messager.printMessage(Diagnostic.Kind.NOTE, "Generated aspect to advise "+element.getSimpleName());
+ }
+ }
+ return true;
+ }
+} \ No newline at end of file
diff --git a/tests/apt/test2/Marker.java b/tests/apt/test2/Marker.java
new file mode 100644
index 000000000..fd96b87df
--- /dev/null
+++ b/tests/apt/test2/Marker.java
@@ -0,0 +1,8 @@
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Marker {
+
+}
+
diff --git a/tests/src/org/aspectj/systemtest/apt/AptTests.java b/tests/src/org/aspectj/systemtest/apt/AptTests.java
index 7781ff013..af8df5e8c 100644
--- a/tests/src/org/aspectj/systemtest/apt/AptTests.java
+++ b/tests/src/org/aspectj/systemtest/apt/AptTests.java
@@ -23,28 +23,32 @@ import java.io.File;
*/
public class AptTests extends XMLBasedAjcTestCase {
- public void testAptWithSpecifiedProcessor() {
- runTest("annotation processing with specified processor");
- }
-
- /**
- * SPI - http://docs.oracle.com/javase/tutorial/sound/SPI-intro.html
- */
- public void testAptUsingSPI() {
- runTest("annotation processing in action using SPI");
- }
-
- public void testDisabledApt() {
- runTest("disabled annotation processing");
- }
-
- public static Test suite() {
- return XMLBasedAjcTestCase.loadSuite(AptTests.class);
- }
-
- @Override
- protected File getSpecFile() {
- return getClassResource("apt-spec.xml");
- }
+ public void testAptWithSpecifiedProcessor() {
+ runTest("annotation processing with specified processor");
+ }
+
+ /**
+ * SPI - http://docs.oracle.com/javase/tutorial/sound/SPI-intro.html
+ */
+ public void testAptUsingSPI() {
+ runTest("annotation processing in action using SPI");
+ }
+
+ public void testDisabledApt() {
+ runTest("disabled annotation processing");
+ }
+
+ public void testAptWithJavaFilesAsAspects() {
+ runTest("annotation processing generating java files with aspects");
+ }
+
+ public static Test suite() {
+ return XMLBasedAjcTestCase.loadSuite(AptTests.class);
+ }
+
+ @Override
+ protected File getSpecFile() {
+ return getClassResource("apt-spec.xml");
+ }
}
diff --git a/tests/src/org/aspectj/systemtest/apt/apt-spec.xml b/tests/src/org/aspectj/systemtest/apt/apt-spec.xml
index c1d34bd23..d2aa1cd79 100644
--- a/tests/src/org/aspectj/systemtest/apt/apt-spec.xml
+++ b/tests/src/org/aspectj/systemtest/apt/apt-spec.xml
@@ -2,8 +2,8 @@
<suite>
- <ajc-test dir="apt" title="annotation processing with specified processor">
- <compile options="-1.8" files="processor/Event.java processor/SimpleProcessor.java"
+ <ajc-test dir="apt/test1" title="annotation processing with specified processor">
+ <compile options="-1.8" files="Event.java SimpleProcessor.java"
outjar="annotation_processor.jar"/>
<!--
SimpleProcessor should generate 2 files for each java class that utilizes @Event annotation:
@@ -15,7 +15,7 @@
}
}
-->
- <compile options="-1.8 -processor test.SimpleProcessor -s generated -showWeaveInfo" files="src/Some.java"
+ <compile options="-1.8 -processor test.SimpleProcessor -s generated -showWeaveInfo" files="Some.java"
classpath="annotation_processor.jar" outjar="code.jar">
<message kind="weave"
text="Type 'test.Some' (Some.java) has intertyped field from 'test.SomeEventsAspect' (SomeEventsAspect.aj:'test.SomeEventsAspect$SomeOnMethod1Event test.Some.OnMethod1Event')"/>
@@ -30,12 +30,12 @@
</run>
</ajc-test>
- <ajc-test dir="apt" title="annotation processing in action using SPI">
+ <ajc-test dir="apt/test1" title="annotation processing in action using SPI">
<!--
what is SPI is described here - http://docs.oracle.com/javase/tutorial/sound/SPI-intro.html
-->
- <!--<compile options="-1.8" files="processor/Event.java processor/SimpleProcessor.java" outjar="annotation_processors_with_spi.jar"/>-->
- <compile options="-1.8 -sourceroots processor" inpath="processor/" outjar="annotation_processor.jar"/>
+ <!--<compile options="-1.8" files="Event.java SimpleProcessor.java" outjar="annotation_processors_with_spi.jar"/>-->
+ <compile options="-1.8" files="Event.java SimpleProcessor.java" outjar="annotation_processor.jar"/>
<!--
SimpleProcessor should generate 2 files for each java class that utilizes @Event annotation:
- {className}EventsAspect.aj - this file describes aspect with advices to weaving method annotated with @Event.
@@ -48,7 +48,7 @@
-->
<!--apt_service_description.jar contains only SPI descrition file - META-INF/services/javax.annotation.processing.Processor-->
- <compile options="-1.8 -s generated -showWeaveInfo" files="src/Some.java"
+ <compile options="-1.8 -s generated -showWeaveInfo" files="Some.java"
classpath="annotation_processor.jar;apt_service_description.jar" outjar="code.jar">
<message kind="weave"
text="Type 'test.Some' (Some.java) has intertyped field from 'test.SomeEventsAspect' (SomeEventsAspect.aj:'test.SomeEventsAspect$SomeOnMethod1Event test.Some.OnMethod1Event')"/>
@@ -64,8 +64,8 @@
</run>
</ajc-test>
- <ajc-test dir="apt" title="disabled annotation processing">
- <compile options="-1.8" files="processor/Event.java processor/SimpleProcessor.java"
+ <ajc-test dir="apt/test1" title="disabled annotation processing">
+ <compile options="-1.8" files="Event.java SimpleProcessor.java"
outjar="annotation_processor.jar"/>
<!--
SimpleProcessor should generate 2 files for each java class that utilizes @Event annotation:
@@ -78,11 +78,23 @@
}
-->
- <compile options="-1.8 -s generated -showWeaveInfo -proc:none" files="src/Some.java"
+ <compile options="-1.8 -s generated -showWeaveInfo -proc:none" files="Some.java"
classpath="annotation_processor.jar" outjar="code.jar">
<!--field was not injected, so error should occur-->
<message kind="error" text="OnMethod1Event cannot be resolved or is not a field"/>
</compile>
</ajc-test>
+ <ajc-test dir="apt/test2" title="annotation processing generating java files with aspects">
+ <compile options="-1.6" files="DemoProcessor.java Marker.java" />
+ <compile options="-1.6 -showWeaveInfo -processor DemoProcessor -s generated" files="Code.java">
+ <message kind="warning" text="Generated aspect to advise too"/>
+ <message kind="warning" text="Generated aspect to advise boo"/>
+ <message kind="weave"
+ text="Join point 'method-execution(void Code.boo())' in Type 'Code' (Code.java:6) advised by before advice from 'Advise_boo' (Advise_boo.java:2)"/>
+ <message kind="weave"
+ text="Join point 'method-execution(void Code.too())' in Type 'Code' (Code.java:9) advised by before advice from 'Advise_too' (Advise_too.java:2)"/>
+ </compile>
+ </ajc-test>
+
</suite>