From 1e2744d37cd2ac3438f8f1e6b8aae7c4a6c6b8d6 Mon Sep 17 00:00:00 2001 From: Andy Clement Date: Wed, 20 Aug 2014 08:00:10 -0700 Subject: enabling AJDT to use annotation processors --- .../ProcessorConsumer1/base/src/Code.java | 26 ++++++++++++ .../ProcessorConsumer2/base/src/Code.java | 26 ++++++++++++ .../ProcessorProject/base/src/DemoProcessor.java | 47 +++++++++++++++++++++ .../ProcessorProject2/base/src/DemoProcessor.java | 47 +++++++++++++++++++++ .../services/javax.annotation.processing.Processor | 1 + .../ProcessorProject2/base/src/proc.jar | Bin 0 -> 1289 bytes .../ProcessorProject3/base/src/DemoProcessor2.java | 47 +++++++++++++++++++++ .../services/javax.annotation.processing.Processor | 1 + 8 files changed, 195 insertions(+) create mode 100644 tests/multiIncremental/ProcessorConsumer1/base/src/Code.java create mode 100644 tests/multiIncremental/ProcessorConsumer2/base/src/Code.java create mode 100644 tests/multiIncremental/ProcessorProject/base/src/DemoProcessor.java create mode 100644 tests/multiIncremental/ProcessorProject2/base/src/DemoProcessor.java create mode 100644 tests/multiIncremental/ProcessorProject2/base/src/META-INF/services/javax.annotation.processing.Processor create mode 100644 tests/multiIncremental/ProcessorProject2/base/src/proc.jar create mode 100644 tests/multiIncremental/ProcessorProject3/base/src/DemoProcessor2.java create mode 100644 tests/multiIncremental/ProcessorProject3/base/src/META-INF/services/javax.annotation.processing.Processor (limited to 'tests/multiIncremental') diff --git a/tests/multiIncremental/ProcessorConsumer1/base/src/Code.java b/tests/multiIncremental/ProcessorConsumer1/base/src/Code.java new file mode 100644 index 000000000..72efafcfa --- /dev/null +++ b/tests/multiIncremental/ProcessorConsumer1/base/src/Code.java @@ -0,0 +1,26 @@ +public class Code { + public static void main(String []argv) { + new Code().run(); + } + + public static void runner() { + new Code().run(); + } + + public void run() { + aaa(); + bbb(); + ccc(); + ddd(); + } + + @SuppressWarnings("rawtypes") + public void aaa() {} + + public void bbb() {} + + @SuppressWarnings("rawtypes") + public void ccc() {} + + public void ddd() {} +} diff --git a/tests/multiIncremental/ProcessorConsumer2/base/src/Code.java b/tests/multiIncremental/ProcessorConsumer2/base/src/Code.java new file mode 100644 index 000000000..72efafcfa --- /dev/null +++ b/tests/multiIncremental/ProcessorConsumer2/base/src/Code.java @@ -0,0 +1,26 @@ +public class Code { + public static void main(String []argv) { + new Code().run(); + } + + public static void runner() { + new Code().run(); + } + + public void run() { + aaa(); + bbb(); + ccc(); + ddd(); + } + + @SuppressWarnings("rawtypes") + public void aaa() {} + + public void bbb() {} + + @SuppressWarnings("rawtypes") + public void ccc() {} + + public void ddd() {} +} diff --git a/tests/multiIncremental/ProcessorProject/base/src/DemoProcessor.java b/tests/multiIncremental/ProcessorProject/base/src/DemoProcessor.java new file mode 100644 index 000000000..05ff20107 --- /dev/null +++ b/tests/multiIncremental/ProcessorProject/base/src/DemoProcessor.java @@ -0,0 +1,47 @@ +import java.io.*; +import javax.tools.*; +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; + + @Override + public void init(ProcessingEnvironment env) { + filer = env.getFiler(); + } + + @Override + public boolean process(Set elements, RoundEnvironment env) { +System.out.println("Processor running"); + // Discover anything marked with @SuppressWarnings + for (Element element: env.getElementsAnnotatedWith(SuppressWarnings.class)) { + if (element.getKind() == ElementKind.METHOD) { + // For any methods we find, create an aspect: + 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(); + System.out.println("Generated aspect to advise "+element.getSimpleName()); + } catch (IOException ioe) { + // already creates message can appear if processor runs more than once + if (!ioe.getMessage().contains("already created")) { + ioe.printStackTrace(); + } + } + } + } + return true; + } +} diff --git a/tests/multiIncremental/ProcessorProject2/base/src/DemoProcessor.java b/tests/multiIncremental/ProcessorProject2/base/src/DemoProcessor.java new file mode 100644 index 000000000..05ff20107 --- /dev/null +++ b/tests/multiIncremental/ProcessorProject2/base/src/DemoProcessor.java @@ -0,0 +1,47 @@ +import java.io.*; +import javax.tools.*; +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; + + @Override + public void init(ProcessingEnvironment env) { + filer = env.getFiler(); + } + + @Override + public boolean process(Set elements, RoundEnvironment env) { +System.out.println("Processor running"); + // Discover anything marked with @SuppressWarnings + for (Element element: env.getElementsAnnotatedWith(SuppressWarnings.class)) { + if (element.getKind() == ElementKind.METHOD) { + // For any methods we find, create an aspect: + 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(); + System.out.println("Generated aspect to advise "+element.getSimpleName()); + } catch (IOException ioe) { + // already creates message can appear if processor runs more than once + if (!ioe.getMessage().contains("already created")) { + ioe.printStackTrace(); + } + } + } + } + return true; + } +} diff --git a/tests/multiIncremental/ProcessorProject2/base/src/META-INF/services/javax.annotation.processing.Processor b/tests/multiIncremental/ProcessorProject2/base/src/META-INF/services/javax.annotation.processing.Processor new file mode 100644 index 000000000..3c594a8be --- /dev/null +++ b/tests/multiIncremental/ProcessorProject2/base/src/META-INF/services/javax.annotation.processing.Processor @@ -0,0 +1 @@ +DemoProcessor diff --git a/tests/multiIncremental/ProcessorProject2/base/src/proc.jar b/tests/multiIncremental/ProcessorProject2/base/src/proc.jar new file mode 100644 index 000000000..be2dd1e85 Binary files /dev/null and b/tests/multiIncremental/ProcessorProject2/base/src/proc.jar differ diff --git a/tests/multiIncremental/ProcessorProject3/base/src/DemoProcessor2.java b/tests/multiIncremental/ProcessorProject3/base/src/DemoProcessor2.java new file mode 100644 index 000000000..e55e665bc --- /dev/null +++ b/tests/multiIncremental/ProcessorProject3/base/src/DemoProcessor2.java @@ -0,0 +1,47 @@ +import java.io.*; +import javax.tools.*; +import java.util.*; +import javax.annotation.processing.*; +import javax.lang.model.*; +import javax.lang.model.element.*; + +@SupportedAnnotationTypes(value= {"java.lang.SuppressWarnings"}) +@SupportedSourceVersion(SourceVersion.RELEASE_6) +public class DemoProcessor2 extends AbstractProcessor { + + private Filer filer; + + @Override + public void init(ProcessingEnvironment env) { + filer = env.getFiler(); + } + + @Override + public boolean process(Set elements, RoundEnvironment env) { +System.out.println("Processor (around) running"); + // Discover anything marked with @SuppressWarnings + for (Element element: env.getElementsAnnotatedWith(SuppressWarnings.class)) { + if (element.getKind() == ElementKind.METHOD) { + // For any methods we find, create an aspect: + String methodName = element.getSimpleName().toString(); + String aspectText = + "public aspect AroundAdvise_"+methodName+" {\n"+ + " void around(): execution(* "+methodName+"(..)) {\n"+ + " System.out.println(\"Around advice on "+methodName+" running\");\n"+ + " }\n"+ + "}\n"; + try { + JavaFileObject file = filer.createSourceFile("AroundAdvise_"+methodName, element); + file.openWriter().append(aspectText).close(); + System.out.println("Generated aspect with around advice to advise "+element.getSimpleName()); + } catch (IOException ioe) { + // already creates message can appear if processor runs more than once + if (!ioe.getMessage().contains("already created")) { + ioe.printStackTrace(); + } + } + } + } + return false; + } +} diff --git a/tests/multiIncremental/ProcessorProject3/base/src/META-INF/services/javax.annotation.processing.Processor b/tests/multiIncremental/ProcessorProject3/base/src/META-INF/services/javax.annotation.processing.Processor new file mode 100644 index 000000000..62e145eb6 --- /dev/null +++ b/tests/multiIncremental/ProcessorProject3/base/src/META-INF/services/javax.annotation.processing.Processor @@ -0,0 +1 @@ +DemoProcessor2 -- cgit v1.2.3