+++ /dev/null
-package test;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Retention(RetentionPolicy.CLASS)
-@Target(ElementType.METHOD)
-public @interface Event {
-
- enum Order {
- Before,
- After
- }
-
- Order value() default Order.Before;
-
- boolean treadSafe() default false;
-}
\ No newline at end of file
+++ /dev/null
-package test;
-
-import javax.annotation.Generated;
-import javax.annotation.processing.AbstractProcessor;
-import javax.annotation.processing.RoundEnvironment;
-import javax.annotation.processing.SupportedSourceVersion;
-import javax.lang.model.SourceVersion;
-import javax.lang.model.element.*;
-import javax.lang.model.type.TypeMirror;
-import javax.tools.Diagnostic;
-import javax.tools.FileObject;
-import javax.tools.JavaFileObject;
-import javax.tools.StandardLocation;
-import java.io.BufferedWriter;
-import java.io.IOException;
-import java.util.*;
-
-@SupportedSourceVersion(SourceVersion.RELEASE_7)
-public final class SimpleProcessor extends AbstractProcessor {
-
- private final Map<TypeElement, List<Item>> collectedElements = new HashMap<>();
- private static String callbacksClassName(TypeElement ce) {
- return ce.getSimpleName() + "Callbacks";
- }
-
- private static String capitalize(String str) {
- char[] chars = str.toCharArray();
- return String.valueOf(chars[0]).toUpperCase() + String.valueOf(Arrays.copyOfRange(chars, 1, chars.length));
- }
-
- private static String callbacksSubClassName(Item item) {
- return "On" + capitalize(item.element.getSimpleName().toString());
- }
-
- private static String callbackName(TypeElement ce, Item item) {
- return callbacksClassName(ce) + '.' + callbacksSubClassName(item);
- }
-
- private static String eventName(TypeElement ce, Item item) {
- return ce.getSimpleName() + fieldName(item);
- }
-
- private static String fieldName(Item item) {
- return "On" + capitalize(item.element.getSimpleName().toString()) + "Event";
- }
-
- private static String toString(VariableElement var, boolean printNames) {
- final StringBuilder builder = new StringBuilder();
- if (printNames) {
- for (final AnnotationMirror annotation : var.getAnnotationMirrors())
- builder.append(annotation).append(' ');
- }
- builder.append(var.asType());
- if (printNames)
- builder.append(' ').append(var);
-
- return builder.toString();
- }
-
- private static void generateEmit(BufferedWriter bw, TypeElement ce, Item item) throws IOException {
- bw.append(" private static void emit(").append(eventName(ce, item)).append(" event, ").append(ce.getSimpleName()).append(" emmiter");
- for (final VariableElement variableElement : item.element.getParameters())
- bw.append(", ").append(toString(variableElement, true));
- bw.append(") {\n");
- bw.append(" final Collection<").append(callbackName(ce, item)).append("> callbacksSafe = event.callbacks;\n");
- bw.append(" if (callbacksSafe == null)\n");
- bw.append(" return;\n");
- bw.append(" for (final ").append(callbackName(ce, item)).append(" callback : new ArrayList<>(callbacksSafe))\n");
- bw.append(" callback.changed(emmiter");
- for (final VariableElement variableElement : item.element.getParameters())
- bw.append(", ").append(variableElement.getSimpleName());
- bw.append(");\n");
- bw.append(" }\n");
- bw.newLine();
- }
-
- private static void generateEvent(BufferedWriter bw, TypeElement ce, Item item) throws IOException {
- bw.append(" public static final class ").append(eventName(ce, item)).append(" {\n");
- bw.append(" private Collection<").append(callbackName(ce, item)).append("> callbacks = null;\n");
- bw.append("\n");
- bw.append(" ").append(eventName(ce, item)).append("() {\n");
- bw.append(" }\n");
- bw.append("\n");
- bw.append(" public void add(").append(callbackName(ce, item)).append(" callback) {\n");
- bw.append(" Collection<").append(callbackName(ce, item)).append("> callbacksSafe = callbacks;\n");
- bw.append(" if (callbacksSafe == null) {\n");
- bw.append(" callbacksSafe = new ArrayList<>(1);\n");
- bw.append(" callbacks = callbacksSafe;\n");
- bw.append(" }\n");
- bw.append(" callbacksSafe.add(callback);\n");
- bw.append(" }\n");
- bw.append("\n");
- bw.append(" public void clean() {\n");
- bw.append(" callbacks = null;\n");
- bw.append(" }\n");
- bw.append(" }");
- bw.newLine();
- bw.newLine();
- }
-
- private static void generateField(BufferedWriter bw, TypeElement ce, Item item) throws IOException {
- bw.append(" @SuppressWarnings(\"PublicField\")\n");
- bw.append(" public final ").append(eventName(ce, item)).append(' ').append(ce.getQualifiedName()).append('.').append(fieldName(item))
- .append(" = new ").append(eventName(ce, item)).append("();\n");
- bw.newLine();
- }
-
- private static void generatePointcut(BufferedWriter bw, TypeElement ce, Item item) throws IOException {
- bw.append(" ").append(item.description.value().name().toLowerCase()).append("(): execution(").append(item.element.getReturnType().toString()).append(' ').append(ce.getQualifiedName()).append('.')
- .append(item.element.getSimpleName()).append('(');
- for (final Iterator<? extends TypeParameterElement> i = item.element.getTypeParameters().iterator(); i.hasNext(); ) {
- bw.append(i.next().getSimpleName());
- if (i.hasNext())
- bw.append(", ");
- }
- bw.append(")) {\n");
- bw.append(" final ").append(ce.getQualifiedName()).append(" emmiter = (").append(ce.getQualifiedName()).append(") thisJoinPoint.getThis();\n");
- bw.append(" emit(emmiter.").append(fieldName(item)).append(", emmiter");
- final List<? extends VariableElement> parameters = item.element.getParameters();
- for (int i = 0, s = parameters.size(); i < s; i++) {
- final VariableElement element = parameters.get(i);
- final TypeMirror type = element.asType();
- bw.append(", ").append('(').append(type.toString()).append(") thisJoinPoint.getArgs()[").append(Integer.toString(i)).append(']');
- }
- bw.append(");\n");
- bw.append(" }");
- bw.newLine();
- bw.newLine();
- }
-
- @Override
- public Set<String> getSupportedAnnotationTypes() {
- return Collections.singleton(Event.class.getName());
- }
-
- @Override
- public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
- if (roundEnv.processingOver()) {
- generateAll();
- return true;
- }
-
- for (final Element elem : roundEnv.getElementsAnnotatedWith(Event.class)) {
- final Event description = elem.getAnnotation(Event.class);
- if (description == null)
- continue;
-
- if (elem.getKind() == ElementKind.FIELD) {
- // TODO(yushkovskiy): implement this
- continue;
- }
-
- if (elem.getKind() != ElementKind.METHOD)
- continue;
-
- final ExecutableElement exeElement = (ExecutableElement) elem;
- final Element enclosingElement = exeElement.getEnclosingElement();
- final TypeElement classElement = (TypeElement) enclosingElement;
-
- List<Item> items = collectedElements.get(classElement);
- if (items == null) {
- items = new ArrayList<>();
- collectedElements.put(classElement, items);
- }
- items.add(new Item(exeElement, description));
- }
-
- return true; // no further processing of this annotation type
- }
-
- private void generateCallbacks(TypeElement ce, List<Item> items) throws IOException {
- final PackageElement packageElement = (PackageElement) ce.getEnclosingElement();
- final JavaFileObject jfo = processingEnv.getFiler().createSourceFile(packageElement.getQualifiedName().toString() + '.' + callbacksClassName(ce));
- try (final BufferedWriter bw = new BufferedWriter(jfo.openWriter())) {
- bw.append("package ").append(packageElement.getQualifiedName()).append(";");
- bw.newLine();
- bw.newLine();
- bw.append("/**\n").append(" * Events' callbacks for ").append(ce.getQualifiedName()).append(".\n").append(" *\n").append(" * @author ").append(SimpleProcessor.class.getCanonicalName()).append("\n").append(" */");
- bw.newLine();
-
- bw.append("public final class ").append(callbacksClassName(ce)).append(" {");
- bw.newLine();
-
- for (final Item item : items) {
- bw.append(" public interface ").append(callbacksSubClassName(item)).append(" {\n");
- bw.append(" void changed(").append(ce.getSimpleName()).append(" emmiter");
- for (final VariableElement var : item.element.getParameters())
- bw.append(", ").append(toString(var, true));
- bw.append(");\n");
- bw.append(" }");
- bw.newLine();
- bw.newLine();
- }
-
- bw.append("}");
- bw.newLine();
- bw.newLine();
- }
- }
-
- private void generateAll() {
- for (final Map.Entry<TypeElement, List<Item>> entry : collectedElements.entrySet()) {
- final TypeElement classElement = entry.getKey();
- final PackageElement packageElement = (PackageElement) classElement.getEnclosingElement();
- try {
- final FileObject jfo = processingEnv.getFiler().createResource(
- StandardLocation.SOURCE_OUTPUT,
- packageElement.getQualifiedName(),
- classElement.getSimpleName() + "EventsAspect.aj");
-
- try (final BufferedWriter bw = new BufferedWriter(jfo.openWriter())) {
- bw.append("package ").append(packageElement.getQualifiedName()).append(";");
- bw.newLine();
- bw.append("import java.util.ArrayList;\n");
- bw.append("import java.util.Collection;");
- bw.newLine();
- bw.newLine();
- bw.append("/**\n").append(" * Events for ").append(classElement.getQualifiedName()).append(".\n").append(" *\n").append(" * @author ").append(SimpleProcessor.class.getCanonicalName()).append("\n").append(" */");
- bw.newLine();
- bw.append("@").append(Generated.class.getCanonicalName()).append("(\"").append(SimpleProcessor.class.getCanonicalName()).append("\")");
- bw.newLine();
- bw.append("final aspect ").append(classElement.getSimpleName()).append("EventsAspect").append(" {");
- bw.newLine();
- bw.newLine();
-
- generateCallbacks(classElement, entry.getValue());
- for (final Item item : entry.getValue()) {
- generateEvent(bw, classElement, item);
- generateEmit(bw, classElement, item);
- generateField(bw, classElement, item);
- generatePointcut(bw, classElement, item);
- }
-
- bw.append("}");
- bw.newLine();
- bw.newLine();
- }
- } catch (final Throwable e) {
- processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, e.getMessage());
- }
- }
- }
-
- private static final class Item {
- private final ExecutableElement element;
- private final Event description;
-
- private Item(ExecutableElement element, Event description) {
- this.element = element;
- this.description = description;
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-package test;
-
-public class Some {
-
- public static void main(String[] args) {
- Some some = new Some();
- some.OnMethod1Event.add((emmiter) -> {
- System.out.println("callback registered from before aspect");
- });
- some.method1();
- }
-
- @Event(Event.Order.Before)
- public void method1() {
- System.out.println("method1 is invoked");
- }
-}
--- /dev/null
+package test;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.CLASS)
+@Target(ElementType.METHOD)
+public @interface Event {
+
+ enum Order {
+ Before,
+ After
+ }
+
+ Order value() default Order.Before;
+
+ boolean treadSafe() default false;
+}
\ No newline at end of file
--- /dev/null
+package test;
+
+import javax.annotation.Generated;
+import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.RoundEnvironment;
+import javax.annotation.processing.SupportedSourceVersion;
+import javax.lang.model.SourceVersion;
+import javax.lang.model.element.*;
+import javax.lang.model.type.TypeMirror;
+import javax.tools.Diagnostic;
+import javax.tools.FileObject;
+import javax.tools.JavaFileObject;
+import javax.tools.StandardLocation;
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.util.*;
+
+@SupportedSourceVersion(SourceVersion.RELEASE_7)
+public final class SimpleProcessor extends AbstractProcessor {
+
+ private final Map<TypeElement, List<Item>> collectedElements = new HashMap<>();
+ private static String callbacksClassName(TypeElement ce) {
+ return ce.getSimpleName() + "Callbacks";
+ }
+
+ private static String capitalize(String str) {
+ char[] chars = str.toCharArray();
+ return String.valueOf(chars[0]).toUpperCase() + String.valueOf(Arrays.copyOfRange(chars, 1, chars.length));
+ }
+
+ private static String callbacksSubClassName(Item item) {
+ return "On" + capitalize(item.element.getSimpleName().toString());
+ }
+
+ private static String callbackName(TypeElement ce, Item item) {
+ return callbacksClassName(ce) + '.' + callbacksSubClassName(item);
+ }
+
+ private static String eventName(TypeElement ce, Item item) {
+ return ce.getSimpleName() + fieldName(item);
+ }
+
+ private static String fieldName(Item item) {
+ return "On" + capitalize(item.element.getSimpleName().toString()) + "Event";
+ }
+
+ private static String toString(VariableElement var, boolean printNames) {
+ final StringBuilder builder = new StringBuilder();
+ if (printNames) {
+ for (final AnnotationMirror annotation : var.getAnnotationMirrors())
+ builder.append(annotation).append(' ');
+ }
+ builder.append(var.asType());
+ if (printNames)
+ builder.append(' ').append(var);
+
+ return builder.toString();
+ }
+
+ private static void generateEmit(BufferedWriter bw, TypeElement ce, Item item) throws IOException {
+ bw.append(" private static void emit(").append(eventName(ce, item)).append(" event, ").append(ce.getSimpleName()).append(" emmiter");
+ for (final VariableElement variableElement : item.element.getParameters())
+ bw.append(", ").append(toString(variableElement, true));
+ bw.append(") {\n");
+ bw.append(" final Collection<").append(callbackName(ce, item)).append("> callbacksSafe = event.callbacks;\n");
+ bw.append(" if (callbacksSafe == null)\n");
+ bw.append(" return;\n");
+ bw.append(" for (final ").append(callbackName(ce, item)).append(" callback : new ArrayList<>(callbacksSafe))\n");
+ bw.append(" callback.changed(emmiter");
+ for (final VariableElement variableElement : item.element.getParameters())
+ bw.append(", ").append(variableElement.getSimpleName());
+ bw.append(");\n");
+ bw.append(" }\n");
+ bw.newLine();
+ }
+
+ private static void generateEvent(BufferedWriter bw, TypeElement ce, Item item) throws IOException {
+ bw.append(" public static final class ").append(eventName(ce, item)).append(" {\n");
+ bw.append(" private Collection<").append(callbackName(ce, item)).append("> callbacks = null;\n");
+ bw.append("\n");
+ bw.append(" ").append(eventName(ce, item)).append("() {\n");
+ bw.append(" }\n");
+ bw.append("\n");
+ bw.append(" public void add(").append(callbackName(ce, item)).append(" callback) {\n");
+ bw.append(" Collection<").append(callbackName(ce, item)).append("> callbacksSafe = callbacks;\n");
+ bw.append(" if (callbacksSafe == null) {\n");
+ bw.append(" callbacksSafe = new ArrayList<>(1);\n");
+ bw.append(" callbacks = callbacksSafe;\n");
+ bw.append(" }\n");
+ bw.append(" callbacksSafe.add(callback);\n");
+ bw.append(" }\n");
+ bw.append("\n");
+ bw.append(" public void clean() {\n");
+ bw.append(" callbacks = null;\n");
+ bw.append(" }\n");
+ bw.append(" }");
+ bw.newLine();
+ bw.newLine();
+ }
+
+ private static void generateField(BufferedWriter bw, TypeElement ce, Item item) throws IOException {
+ bw.append(" @SuppressWarnings(\"PublicField\")\n");
+ bw.append(" public final ").append(eventName(ce, item)).append(' ').append(ce.getQualifiedName()).append('.').append(fieldName(item))
+ .append(" = new ").append(eventName(ce, item)).append("();\n");
+ bw.newLine();
+ }
+
+ private static void generatePointcut(BufferedWriter bw, TypeElement ce, Item item) throws IOException {
+ bw.append(" ").append(item.description.value().name().toLowerCase()).append("(): execution(").append(item.element.getReturnType().toString()).append(' ').append(ce.getQualifiedName()).append('.')
+ .append(item.element.getSimpleName()).append('(');
+ for (final Iterator<? extends TypeParameterElement> i = item.element.getTypeParameters().iterator(); i.hasNext(); ) {
+ bw.append(i.next().getSimpleName());
+ if (i.hasNext())
+ bw.append(", ");
+ }
+ bw.append(")) {\n");
+ bw.append(" final ").append(ce.getQualifiedName()).append(" emmiter = (").append(ce.getQualifiedName()).append(") thisJoinPoint.getThis();\n");
+ bw.append(" emit(emmiter.").append(fieldName(item)).append(", emmiter");
+ final List<? extends VariableElement> parameters = item.element.getParameters();
+ for (int i = 0, s = parameters.size(); i < s; i++) {
+ final VariableElement element = parameters.get(i);
+ final TypeMirror type = element.asType();
+ bw.append(", ").append('(').append(type.toString()).append(") thisJoinPoint.getArgs()[").append(Integer.toString(i)).append(']');
+ }
+ bw.append(");\n");
+ bw.append(" }");
+ bw.newLine();
+ bw.newLine();
+ }
+
+ @Override
+ public Set<String> getSupportedAnnotationTypes() {
+ return Collections.singleton(Event.class.getName());
+ }
+
+ @Override
+ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
+ if (roundEnv.processingOver()) {
+ generateAll();
+ return true;
+ }
+
+ for (final Element elem : roundEnv.getElementsAnnotatedWith(Event.class)) {
+ final Event description = elem.getAnnotation(Event.class);
+ if (description == null)
+ continue;
+
+ if (elem.getKind() == ElementKind.FIELD) {
+ // TODO(yushkovskiy): implement this
+ continue;
+ }
+
+ if (elem.getKind() != ElementKind.METHOD)
+ continue;
+
+ final ExecutableElement exeElement = (ExecutableElement) elem;
+ final Element enclosingElement = exeElement.getEnclosingElement();
+ final TypeElement classElement = (TypeElement) enclosingElement;
+
+ List<Item> items = collectedElements.get(classElement);
+ if (items == null) {
+ items = new ArrayList<>();
+ collectedElements.put(classElement, items);
+ }
+ items.add(new Item(exeElement, description));
+ }
+
+ return true; // no further processing of this annotation type
+ }
+
+ private void generateCallbacks(TypeElement ce, List<Item> items) throws IOException {
+ final PackageElement packageElement = (PackageElement) ce.getEnclosingElement();
+ final JavaFileObject jfo = processingEnv.getFiler().createSourceFile(packageElement.getQualifiedName().toString() + '.' + callbacksClassName(ce));
+ try (final BufferedWriter bw = new BufferedWriter(jfo.openWriter())) {
+ bw.append("package ").append(packageElement.getQualifiedName()).append(";");
+ bw.newLine();
+ bw.newLine();
+ bw.append("/**\n").append(" * Events' callbacks for ").append(ce.getQualifiedName()).append(".\n").append(" *\n").append(" * @author ").append(SimpleProcessor.class.getCanonicalName()).append("\n").append(" */");
+ bw.newLine();
+
+ bw.append("public final class ").append(callbacksClassName(ce)).append(" {");
+ bw.newLine();
+
+ for (final Item item : items) {
+ bw.append(" public interface ").append(callbacksSubClassName(item)).append(" {\n");
+ bw.append(" void changed(").append(ce.getSimpleName()).append(" emmiter");
+ for (final VariableElement var : item.element.getParameters())
+ bw.append(", ").append(toString(var, true));
+ bw.append(");\n");
+ bw.append(" }");
+ bw.newLine();
+ bw.newLine();
+ }
+
+ bw.append("}");
+ bw.newLine();
+ bw.newLine();
+ }
+ }
+
+ private void generateAll() {
+ for (final Map.Entry<TypeElement, List<Item>> entry : collectedElements.entrySet()) {
+ final TypeElement classElement = entry.getKey();
+ final PackageElement packageElement = (PackageElement) classElement.getEnclosingElement();
+ try {
+ final FileObject jfo = processingEnv.getFiler().createResource(
+ StandardLocation.SOURCE_OUTPUT,
+ packageElement.getQualifiedName(),
+ classElement.getSimpleName() + "EventsAspect.aj");
+
+ try (final BufferedWriter bw = new BufferedWriter(jfo.openWriter())) {
+ bw.append("package ").append(packageElement.getQualifiedName()).append(";");
+ bw.newLine();
+ bw.append("import java.util.ArrayList;\n");
+ bw.append("import java.util.Collection;");
+ bw.newLine();
+ bw.newLine();
+ bw.append("/**\n").append(" * Events for ").append(classElement.getQualifiedName()).append(".\n").append(" *\n").append(" * @author ").append(SimpleProcessor.class.getCanonicalName()).append("\n").append(" */");
+ bw.newLine();
+ bw.append("@").append(Generated.class.getCanonicalName()).append("(\"").append(SimpleProcessor.class.getCanonicalName()).append("\")");
+ bw.newLine();
+ bw.append("final aspect ").append(classElement.getSimpleName()).append("EventsAspect").append(" {");
+ bw.newLine();
+ bw.newLine();
+
+ generateCallbacks(classElement, entry.getValue());
+ for (final Item item : entry.getValue()) {
+ generateEvent(bw, classElement, item);
+ generateEmit(bw, classElement, item);
+ generateField(bw, classElement, item);
+ generatePointcut(bw, classElement, item);
+ }
+
+ bw.append("}");
+ bw.newLine();
+ bw.newLine();
+ }
+ } catch (final Throwable e) {
+ processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, e.getMessage());
+ }
+ }
+ }
+
+ private static final class Item {
+ private final ExecutableElement element;
+ private final Event description;
+
+ private Item(ExecutableElement element, Event description) {
+ this.element = element;
+ this.description = description;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+package test;
+
+public class Some {
+
+ public static void main(String[] args) {
+ Some some = new Some();
+ some.OnMethod1Event.add((emmiter) -> {
+ System.out.println("callback registered from before aspect");
+ });
+ some.method1();
+ }
+
+ @Event(Event.Order.Before)
+ public void method1() {
+ System.out.println("method1 is invoked");
+ }
+}
--- /dev/null
+public class Code {
+
+ public void moo() {}
+
+ @Marker
+ public void boo() {}
+
+ @Marker
+ public void too() {}
+
+ public void woo() {}
+}
\ No newline at end of file
--- /dev/null
+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
--- /dev/null
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Marker {
+
+}
+
*/
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");
+ }
}
<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:
}
}
-->
- <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')"/>
</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.
-->
<!--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')"/>
</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:
}
-->
- <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>