diff options
author | hsestupin <stupin.sergey@gmail.com> | 2014-08-14 12:54:28 +0400 |
---|---|---|
committer | Andy Clement <aclement@gopivotal.com> | 2014-08-14 11:11:08 -0700 |
commit | 66469244e4aa352f0db6d91854541a85d68e7032 (patch) | |
tree | cd942afb3382dcfbbb831e4468db450168d3f4ec /tests/apt | |
parent | ac48f780a46720f201ac893c8fbf9b1e17cc60d4 (diff) | |
download | aspectj-66469244e4aa352f0db6d91854541a85d68e7032.tar.gz aspectj-66469244e4aa352f0db6d91854541a85d68e7032.zip |
add APT test generating Java files
Signed-off-by: hsestupin <stupin.sergey@gmail.com>
Diffstat (limited to 'tests/apt')
-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) | bin | 542 -> 542 bytes | |||
-rw-r--r-- | tests/apt/test2/Code.java | 12 | ||||
-rw-r--r-- | tests/apt/test2/DemoProcessor.java | 46 | ||||
-rw-r--r-- | tests/apt/test2/Marker.java | 8 |
7 files changed, 66 insertions, 0 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 Binary files differindex f823b1784..f823b1784 100644 --- a/tests/apt/apt_service_description.jar +++ b/tests/apt/test1/apt_service_description.jar 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 { + +} + |