if (node.getParameterTypes() != null) {
sb.append('(');
for (int i = 0; i < node.getParameterTypes().size(); i++) {
- sb.append((String) node.getParameterTypes().get(i));
+ sb.append(String.valueOf(node.getParameterTypes().get(i)));
sb.append(' ');
sb.append((String) node.getParameterNames().get(i));
if (i < node.getParameterTypes().size() - 1) {
return null;
}
+ protected File getClassResource(String resourceName) {
+ return new File(getClass().getResource(resourceName).getFile());
+ }
+
}
--- /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");
+ }
+}
@Override
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc10x/ajc10x.xml");
+ return getClassResource("ajc10x.xml");
}
public void test001() {
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc11/ajc11.xml");
+ return getClassResource("ajc11.xml");
}
public void test001() {
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc120/ajc120.xml");
+ return getClassResource("ajc120.xml");
}
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc121/ajc121.xml");
+ return getClassResource("ajc121.xml");
}
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml");
+ return getClassResource("ajc150.xml");
}
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml");
+ return getClassResource("ajc150.xml");
}
public void testMixingCodeStyles_pr121385() {
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml");
+ return getClassResource("ajc150.xml");
}
// /////////////////////////////////// @ANNOTATION and CALL
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml");
+ return getClassResource("ajc150.xml");
}
// before(): call(@SimpleAnnotation * *(..)) { }
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml");
+ return getClassResource("ajc150.xml");
}
// No longer a limitation ASC 31Jan05
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml");
+ return getClassResource("ajc150.xml");
}
// Cannot make ITD (c/m/f) on an annotation
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml");
+ return getClassResource("ajc150.xml");
}
public void testSimpleBoxing() {
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml");
+ return getClassResource("ajc150.xml");
}
private boolean verbose = false;
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml");
+ return getClassResource("ajc150.xml");
}
// parsing the various forms of declare @
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml");
+ return getClassResource("ajc150.xml");
}
// Cannot make ITDC on an enum
@Override
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml");
+ return getClassResource("ajc150.xml");
}
private void verifyDebugString(ResolvedMember theMember, String string) {
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml");
+ return getClassResource("ajc150.xml");
}
public void testITDReturningParameterizedType() {
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml");
+ return getClassResource("ajc150.xml");
}
public void testSimpleDecPHasMethod() {
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml");
+ return getClassResource("ajc150.xml");
}
/**
* Compile a simple java class with an aspect library built with aspectj 1.2.1 - this
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml");
+ return getClassResource("ajc150.xml");
}
/**
* infrastructure is properly hidden in ajc$ or synthetic members)
*/
public void testPervasivenessOfWeaving() {
- CompilationResult cR = ajc(new File("../tests/java5/pertypewithin"),new String[]{"U.java","-showWeaveInfo"});
+ CompilationResult cR = ajc(new File("tests/java5/pertypewithin"),new String[]{"U.java","-showWeaveInfo"});
int weavingMessagesFromNormalDeploymentModel = cR.getWeaveMessages().size();
- cR = ajc(new File("../tests/java5/pertypewithin"),new String[]{"V.java","-showWeaveInfo"});
+ cR = ajc(new File("tests/java5/pertypewithin"),new String[]{"V.java","-showWeaveInfo"});
int weavingMessagesFromPerTypeWithin = cR.getWeaveMessages().size();
assertEquals("Expected same number of messages regardless of perclause",
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml");
+ return getClassResource("ajc150.xml");
}
public void test01() {
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml");
+ return getClassResource("ajc150.xml");
}
public void testImportStaticSystemDotOut() {
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml");
+ return getClassResource("ajc150.xml");
}
// Check basic suppression
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml");
+ return getClassResource("ajc150.xml");
}
// check when signature is from a call PCD
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * initial development Jonas Bonér, Alexandre Vasseur
+ * initial development Jonas Bon�r, Alexandre Vasseur
*******************************************************************************/
package org.aspectj.systemtest.ajc150.ataspectj;
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc150/ataspectj/annotationgen.xml");
+ return getClassResource("annotationgen.xml");
}
public void testSimpleAspect() {
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc150/ataspectj/ltw.xml");
+ return getClassResource("ltw.xml");
}
public void testRunThemAllWithJavacCompiledAndLTW() {
public class AtAjMisuseTests extends XMLBasedAjcTestCase {
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc150/ataspectj/misuse.xml");
+ return getClassResource("misuse.xml");
}
public static Test suite() {
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc150/ataspectj/syntax.xml");
+ return getClassResource("syntax.xml");
}
public void testSimpleBefore() {
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc150/ltw/ltw.xml");
+ return getClassResource("ltw.xml");
}
public void testServerWithHelloWorld () {
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc150/ltw/ltw.xml");
+ return getClassResource("ltw.xml");
}
public void testInclusionAndPattern() {
<!DOCTYPE suite SYSTEM "../tests/ajcTestSuite.dtd"[
-<!ENTITY tests SYSTEM "../tests/src/org/aspectj/systemtest/ajc150/ltw/ltw-tests.xml">
+<!ENTITY tests SYSTEM "tests/src/org/aspectj/systemtest/ajc150/ltw/ltw-tests.xml">
]>
<!-- Load-time weaving tests -->
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc151/ajc151.xml");
+ return getClassResource("ajc151.xml");
}
}
\ No newline at end of file
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc151/ataround.xml");
+ return getClassResource("ataround.xml");
}
}
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc151/newarray_joinpoint.xml");
+ return getClassResource("newarray_joinpoint.xml");
}
}
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc151/serialversionuid.xml");
+ return getClassResource("serialversionuid.xml");
}
}
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc152/ajc152.xml");
+ return getClassResource("ajc152.xml");
}
}
\ No newline at end of file
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc152/synchronization.xml");
+ return getClassResource("synchronization.xml");
}
}
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc152/synchronization.xml");
+ return getClassResource("synchronization.xml");
}
public void tearDown() {
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc153/ajc153.xml");
+ return getClassResource("ajc153.xml");
}
}
\ No newline at end of file
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc153/jdtlikehandleprovider.xml");
+ return getClassResource("jdtlikehandleprovider.xml");
}
}
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc153/ajc153.xml");
+ return getClassResource("ajc153.xml");
}
public void testHandleDuplicateConfiguration_pr157474 () {
return XMLBasedAjcTestCase.loadSuite(PipeliningTests.class);
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc153/pipelining.xml");
+ return getClassResource("pipelining.xml");
}
}
\ No newline at end of file
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc154/ajc154.xml");
+ return getClassResource("ajc154.xml");
}
// ---
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc160/ajc160.xml");
+ return getClassResource("ajc160.xml");
}
}
\ No newline at end of file
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc160/annotationValueMatching.xml");
+ return getClassResource("annotationValueMatching.xml");
}
}
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc160/newfeatures-tests.xml");
+ return getClassResource("newfeatures-tests.xml");
}
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc160/parameterAnnotations.xml");
+ return getClassResource("parameterAnnotations.xml");
}
}
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc160/sanity-tests.xml");
+ return getClassResource("sanity-tests.xml");
}
}
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc161/ajc161.xml");
+ return getClassResource("ajc161.xml");
}
}
\ No newline at end of file
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc161/annotationFieldBinding.xml");
+ return getClassResource("annotationFieldBinding.xml");
}
}
@Override
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc1610/ajc1610.xml");
+ return getClassResource("ajc1610.xml");
}
}
\ No newline at end of file
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc1610/newfeatures-tests.xml");
+ return getClassResource("newfeatures-tests.xml");
}
}
\ No newline at end of file
@Override
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc1611/ajc1611.xml");
+ return getClassResource("ajc1611.xml");
}
}
\ No newline at end of file
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc1611/newfeatures-tests.xml");
+ return getClassResource("newfeatures-tests.xml");
}
}
\ No newline at end of file
@Override
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc1612/ajc1612.xml");
+ return getClassResource("ajc1612.xml");
}
}
\ No newline at end of file
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc162/ajc162.xml");
+ return getClassResource("ajc162.xml");
}
}
\ No newline at end of file
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc163/ajc163.xml");
+ return getClassResource("ajc163.xml");
}
// ---
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc164/ajc164.xml");
+ return getClassResource("ajc164.xml");
}
private IProgramElement findElementAtLine(IProgramElement whereToLook, int line) {
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc164/declareMixin.xml");
+ return getClassResource("declareMixin.xml");
}
}
\ No newline at end of file
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc164/joinpointid.xml");
+ return getClassResource("joinpointid.xml");
}
}
\ No newline at end of file
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc165/ajc165.xml");
+ return getClassResource("ajc165.xml");
}
}
\ No newline at end of file
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc166/ajc166.xml");
+ return getClassResource("ajc166.xml");
}
}
\ No newline at end of file
@Override
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc167/ajc167.xml");
+ return getClassResource("ajc167.xml");
}
}
\ No newline at end of file
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc167/overweaving.xml");
+ return getClassResource("overweaving.xml");
}
}
\ No newline at end of file
@Override
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc169/ajc169.xml");
+ return getClassResource("ajc169.xml");
}
}
\ No newline at end of file
@Override
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc169/intertype.xml");
+ return getClassResource("intertype.xml");
}
}
\ No newline at end of file
@Override
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc169/transparentweaving.xml");
+ return getClassResource("transparentweaving.xml");
}
}
\ No newline at end of file
@Override
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc171/ajc171.xml");
+ return getClassResource("ajc171.xml");
}
}
@Override
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc172/ajc172.xml");
+ return getClassResource("ajc172.xml");
}
}
@Override
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc173/ajc173.xml");
+ return getClassResource("ajc173.xml");
}
}
@Override
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc174/ajc174.xml");
+ return getClassResource("ajc174.xml");
}
}
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc175/ajc175.xml");
+ return getClassResource("ajc175.xml");
}
public static void main(String[] args) {
@Override
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc180/ajc180.xml");
+ return getClassResource("ajc180.xml");
}
}
@Override
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc181/ajc181.xml");
+ return getClassResource("ajc181.xml");
}
}
import junit.framework.Test;
import junit.framework.TestSuite;
+import org.aspectj.systemtest.apt.AptTests;
public class AllTestsAspectJ181 {
TestSuite suite = new TestSuite("AspectJ 1.8.1 tests");
// $JUnit-BEGIN$
suite.addTest(Ajc181Tests.suite());
+ suite.addTest(AptTests.suite());
// $JUnit-END$
return suite;
}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2014 Contributors
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andy Clement - initial API and implementation
+ *******************************************************************************/
+package org.aspectj.systemtest.apt;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTestsApt {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite("Annotation processing tests");
+ // $JUnit-BEGIN$
+ suite.addTest(AptTests.suite());
+ // $JUnit-END$
+ return suite;
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2014 Contributors
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andy Clement - initial API and implementation
+ *******************************************************************************/
+package org.aspectj.systemtest.apt;
+
+import junit.framework.Test;
+import org.aspectj.apache.bcel.classfile.Method;
+import org.aspectj.testing.XMLBasedAjcTestCase;
+
+import java.io.File;
+import java.nio.file.Files;
+
+/**
+ * Annotation processing tool tests.
+ *
+ * @author Sergey Stupin.
+ */
+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");
+ }
+
+}
--- /dev/null
+<!DOCTYPE suite SYSTEM "../tests/ajcTestSuite.dtd"[]>
+
+<suite>
+
+ <ajc-test dir="apt" title="annotation processing with specified processor">
+ <compile options="-1.8" files="processor/Event.java processor/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.
+ - {className}Callbacks.java - this file contains callback interfaces for methods annotated with @Event. Example:
+ public final class SomeCallbacks {
+ public interface OnMethod1 {
+ void changed(Some emmiter);
+ }
+ }
+ -->
+ <compile options="-1.8 -processor test.SimpleProcessor -s generated -showWeaveInfo" files="src/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')"/>
+ <message kind="weave"
+ text="Join point 'method-execution(void test.Some.method1())' in Type 'test.Some' (Some.java:14) advised by before advice from 'test.SomeEventsAspect' (SomeEventsAspect.aj:44)"/>
+ </compile>
+ <run class="test.Some">
+ <stdout>
+ <line text="callback registered from before aspect"/>
+ <line text="method1 is invoked"/>
+ </stdout>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="apt" 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"/>
+ <!--
+ 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.
+ - {className}Callbacks.java - this file contains callback interfaces for methods annotated with @Event. Example:
+ public final class SomeCallbacks {
+ public interface OnMethod1 {
+ void changed(Some emmiter);
+ }
+ }
+ -->
+
+ <!--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"
+ 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')"/>
+ <message kind="weave"
+ text="Join point 'method-execution(void test.Some.method1())' in Type 'test.Some' (Some.java:14) advised by before advice from 'test.SomeEventsAspect' (SomeEventsAspect.aj:44)"/>
+ </compile>
+
+ <run class="test.Some">
+ <stdout>
+ <line text="callback registered from before aspect"/>
+ <line text="method1 is invoked"/>
+ </stdout>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="apt" title="disabled annotation processing">
+ <compile options="-1.8" files="processor/Event.java processor/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.
+ - {className}Callbacks.java - this file contains callback interfaces for methods annotated with @Event. Example:
+ public final class SomeCallbacks {
+ public interface OnMethod1 {
+ void changed(Some emmiter);
+ }
+ }
+ -->
+
+ <compile options="-1.8 -s generated -showWeaveInfo -proc:none" files="src/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>
+
+</suite>
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/aspectpath/aspectpath.xml");
+ return getClassResource("aspectpath.xml");
}
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/base/baseTests.xml");
+ return getClassResource("baseTests.xml");
}
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/design/design.xml");
+ return getClassResource("design.xml");
}
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/incremental/incremental.xml");
+ return getClassResource("incremental.xml");
}
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/incremental/model/incremental-model.xml");
+ return getClassResource("incremental-model.xml");
}
// This first test doesnt do a lot currently, but is ready too...
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/inpath/inpath.xml");
+ return getClassResource("inpath.xml");
}
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/java14/java14.xml");
+ return getClassResource("java14.xml");
}
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/model/model.xml");
+ return getClassResource("model.xml");
}
}
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/model/model.xml");
+ return getClassResource("model.xml");
}
}
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/options/options.xml");
+ return getClassResource("options.xml");
}
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/pre10x/pre10x.xml");
+ return getClassResource("pre10x.xml");
}
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/serialVerUID/serialVerUID.xml");
+ return getClassResource("serialVerUID.xml");
}
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/tracing/tracing.xml");
+ return getClassResource("tracing.xml");
}
public void testTracing () {
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/xlint/xlint.xml");
+ return getClassResource("xlint.xml");
}
public void testBug99136(){
}
protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/xlint/xlint.xml");
+ return getClassResource("xlint.xml");
}
/**
* Extract the name of a class from the path to its file. If the basedir is null, then the class is assumed to be in the default
* package unless the classFile has one of the top-level suffixes { com, org, java, javax } as a parent directory.
- *
+ *
* @param basedir the File of the base directory (prefix of classFile)
* @param classFile the File of the class to extract the name for
* @throws IllegalArgumentException if classFile is null or does not end with ".class" or a non-null basedir is not a prefix of
/**
* Normalize path for comparisons by rendering absolute, clipping basedir prefix, trimming and changing '\\' to '/'
- *
+ *
* @param file the File with the path to normalize
* @param basedir the File for the prefix of the file to normalize - ignored if null
* @return "" if null or normalized path otherwise
/**
* Render a set of files to String as a path by getting absolute paths of each and delimiting with infix.
- *
+ *
* @param files the File[] to flatten - may be null or empty
* @param infix the String delimiter internally between entries (if null, then use File.pathSeparator). (alias to
* <code>flatten(getAbsolutePaths(files), infix)</code>
/**
* Flatten File[] to String.
- *
+ *
* @param files the File[] of paths to flatten - null ignored
* @param infix the String infix to use - null treated as File.pathSeparator
*/
/**
* Normalize path for comparisons by rendering absolute trimming and changing '\\' to '/'
- *
+ *
* @return "" if null or normalized path otherwise
*/
public static String normalizedPath(File file) {
/**
* Get best File for the first-readable path in input paths, treating entries prefixed "sp:" as system property keys. Safe to
* call in static initializers.
- *
+ *
* @param paths the String[] of paths to check.
* @return null if not found, or valid File otherwise
*/
/**
* Render as best file, canonical or absolute.
- *
+ *
* @param file the File to get the best File for (not null)
* @return File of the best-available path
* @throws IllegalArgumentException if file is null
/**
* Render as best path, canonical or absolute.
- *
+ *
* @param file the File to get the path for (not null)
* @return String of the best-available path
* @throws IllegalArgumentException if file is null
/**
* Recursively delete the contents of dir, but not the dir itself
- *
+ *
* @return the total number of files deleted
*/
public static int deleteContents(File dir) {
/**
* Recursively delete some contents of dir, but not the dir itself. This deletes any subdirectory which is empty after its files
* are deleted.
- *
+ *
* @return the total number of files deleted
*/
public static int deleteContents(File dir, FileFilter filter) {
/**
* Recursively delete some contents of dir, but not the dir itself. If deleteEmptyDirs is true, this deletes any subdirectory
* which is empty after its files are deleted.
- *
+ *
* @param dir the File directory (if a file, the the file is deleted)
* @return the total number of files deleted
*/
dir.delete();
return 1;
}
- String[] fromFiles = dir.list();
- int result = 0;
- for (int i = 0; i < fromFiles.length; i++) {
- String string = fromFiles[i];
- File file = new File(dir, string);
- if ((null == filter) || filter.accept(file)) {
- if (file.isDirectory()) {
- result += deleteContents(file, filter, deleteEmptyDirs);
- if (deleteEmptyDirs && (0 == file.list().length)) {
- file.delete();
- }
- } else {
- /* boolean ret = */file.delete();
- result++;
- }
+ String[] fromFiles = dir.list();
+ if (fromFiles == null) {
+ return 0;
+ }
+ int result = 0;
+ for (int i = 0; i < fromFiles.length; i++) {
+ String string = fromFiles[i];
+ File file = new File(dir, string);
+ if ((null == filter) || filter.accept(file)) {
+ if (file.isDirectory()) {
+ result += deleteContents(file, filter, deleteEmptyDirs);
+ String[] fileContent = file.list();
+ if (deleteEmptyDirs &&
+ fileContent != null &&
+ 0 == fileContent.length) {
+ file.delete();
+ }
+ } else {
+ /* boolean ret = */
+ file.delete();
+ result++;
+ }
}
}
return result;
/**
* Copy contents of fromDir into toDir
- *
+ *
* @param fromDir must exist and be readable
* @param toDir must exist or be creatable and be writable
* @return the total number of files copied
* Recursively copy files in fromDir (with any fromSuffix) to toDir, replacing fromSuffix with toSuffix if any. This silently
* ignores dirs and files that are not readable but throw IOException for directories that are not writable. This does not clean
* out the original contents of toDir. (subdirectories are not renamed per directory rules)
- *
+ *
* @param fromSuffix select files with this suffix - select all if null or empty
* @param toSuffix replace fromSuffix with toSuffix in the destination file name - ignored if null or empty, appended to name if
* fromSuffix is null or empty
* ignores dirs and files that are not readable but throw IOException for directories that are not writable. This does not clean
* out the original contents of toDir. (subdirectories are not renamed per directory rules) This calls any delegate
* FilenameFilter to collect any selected file.
- *
+ *
* @param fromSuffix select files with this suffix - select all if null or empty
* @param toSuffix replace fromSuffix with toSuffix in the destination file name - ignored if null or empty, appended to name if
* fromSuffix is null or empty
/**
* Recursively list files in srcDir.
- *
+ *
* @return ArrayList with String paths of File under srcDir (relative to srcDir)
*/
public static String[] listFiles(File srcDir) {
/**
* Recursively list files in srcDir.
- *
+ *
* @return ArrayList with String paths of File under srcDir (relative to srcDir)
*/
public static File[] listFiles(File srcDir, FileFilter fileFilter) {
/**
* Recursively list .class files in specified directory
- *
+ *
* @return List of File objects
*/
public static List<File> listClassFiles(File dir) {
/**
* Convert String[] paths to File[] as offset of base directory
- *
+ *
* @param basedir the non-null File base directory for File to create with paths
* @param paths the String[] of paths to create
* @return File[] with same length as paths
/**
* Convert String[] paths to File[] as offset of base directory
- *
+ *
* @param basedir the non-null File base directory for File to create with paths
* @param paths the String[] of paths to create
* @param suffixes the String[] of suffixes to limit sources to - ignored if null
/**
* Create a new File, resolving paths ".." and "." specially.
- *
+ *
* @param dir the File for the parent directory of the file
* @param path the path in the parent directory (filename only?)
* @return File for the new file.
* Copy files from source dir into destination directory, creating any needed directories. This differs from copyDir in not
* being recursive; each input with the source dir creates a full path. However, if the source is a directory, it is copied as
* such.
- *
+ *
* @param srcDir an existing, readable directory containing relativePaths files
* @param relativePaths a set of paths relative to srcDir to readable File to copy
* @param destDir an existing, writable directory to copy files to
/**
* Copy fromFile to toFile, handling file-file, dir-dir, and file-dir copies.
- *
+ *
* @param fromFile the File path of the file or directory to copy - must be readable
* @param toFile the File path of the target file or directory - must be writable (will be created if it does not exist)
*/
/**
* Ensure that the parent directory to path can be written. If the path has a null parent, DEFAULT_PARENT is tested. If the path
* parent does not exist, this tries to create it.
- *
+ *
* @param path the File path whose parent should be writable
* @return the File path of the writable parent directory
* @throws IllegalArgumentException if parent cannot be written or path is null.
/**
* Copy file to file.
- *
+ *
* @param fromFile the File to copy (readable, non-null file)
* @param toFile the File to copy to (non-null, parent dir exists)
* @throws IOException
/**
* Make a new child directory of parent
- *
+ *
* @param parent a File for the parent (writable)
* @param child a prefix for the child directory
* @return a File dir that exists with parentDir as the parent file or null
/**
* Make a new temporary directory in the same directory that the system uses for temporary files, or if that files, in the
* current directory.
- *
+ *
* @param name the preferred (simple) name of the directory - may be null.
* @return File of an existing new temp dir, or null if unable to create
*/
/**
* Get URL for a File. This appends "/" for directories. prints errors to System.err
- *
+ *
* @param file the File to convert to URL (not null)
*/
@SuppressWarnings("deprecation")
/**
* Write contents to file, returning null on success or error message otherwise. This tries to make any necessary parent
* directories first.
- *
+ *
* @param file the File to write (not null)
* @param contents the String to write (use "" if null)
* @return String null on no error, error otherwise
/**
* Do line-based search for literal text in source files, returning file:line where found.
- *
+ *
* @param sought the String text to seek in the file
* @param sources the List of String paths to the source files
* @param listAll if false, only list first match in file
* Do line-based search for literal text in source file, returning line where found as a String in the form
* {sourcePath}:line:column submitted to the collecting parameter sink. Any error is rendered to String and returned as the
* result.
- *
+ *
* @param sought the String text to seek in the file
* @param sources the List of String paths to the source files
* @param listAll if false, only list first match in file
/**
* Sleep until after the last last-modified stamp from the files.
- *
+ *
* @param files the File[] of files to inspect for last modified times (this ignores null or empty files array and null or
* non-existing components of files array)
* @return true if succeeded without 100 interrupts
return url.toURI().getPath();
} catch (URISyntaxException e) {
System.err.println("Warning!! Malformed URL may cause problems: "+url); // TODO: Better way to report this?
- // In this case it was likely not using properly escaped
+ // In this case it was likely not using properly escaped
// characters so we just use the 'bad' method that doesn't decode
// special chars
return url.getPath();
/**
* A pipe when run reads from an input stream to an output stream, optionally sleeping between reads.
- *
+ *
* @see #copyStream(InputStream, OutputStream)
*/
public static class Pipe implements Runnable {
/**
* alias for <code>Pipe(in, out, 100l, false, false)</code>
- *
+ *
* @param in the InputStream source to read
* @param out the OutputStream sink to write
*/
/**
* Tell the pipe to halt the next time it gains control.
- *
+ *
* @param wait if true, this waits synchronously until pipe is done
* @param finishStream if true, then continue until a read from the input stream returns no bytes, then halt.
* @return true if <code>run()</code> will return the next time it gains control