diff graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/verify/VerifyTruffleProcessor.java @ 21480:c2b006c5e15f

Testing the annotation processor using the @ExpectedError annotation as suggested by Christian Humer
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Mon, 25 May 2015 10:36:30 +0200
parents fb17e716b03c
children bb51b9a142b3
line wrap: on
line diff
--- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/verify/VerifyTruffleProcessor.java	Mon May 25 09:09:07 2015 +0200
+++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/verify/VerifyTruffleProcessor.java	Mon May 25 10:36:30 2015 +0200
@@ -34,6 +34,7 @@
 import javax.tools.Diagnostic.Kind;
 
 import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
+import com.oracle.truffle.api.dsl.ExpectError;
 import com.oracle.truffle.api.nodes.Node.Child;
 
 @SupportedAnnotationTypes({"com.oracle.truffle.api.CompilerDirectives.TruffleBoundary", "com.oracle.truffle.api.nodes.Node.Child"})
@@ -116,10 +117,45 @@
 
         for (Element e : roundEnv.getElementsAnnotatedWith(Child.class)) {
             if (e.getModifiers().contains(Modifier.FINAL)) {
-                errorMessage(e, "@Child field cannot be final");
+                emitError("@Child field cannot be final", e);
+                continue;
+            }
+            assertNoErrorExpected(e);
+        }
+        return false;
+    }
+
+    void assertNoErrorExpected(Element e) {
+        TypeElement eee = processingEnv.getElementUtils().getTypeElement(ExpectError.class.getName());
+        for (AnnotationMirror am : e.getAnnotationMirrors()) {
+            if (am.getAnnotationType().asElement() == eee) {
+                processingEnv.getMessager().printMessage(Kind.ERROR, "Expected an error, but none found!", e);
             }
         }
-        return false;
+    }
+
+    void emitError(String msg, Element e) {
+        TypeElement eee = processingEnv.getElementUtils().getTypeElement(ExpectError.class.getName());
+        for (AnnotationMirror am : e.getAnnotationMirrors()) {
+            if (am.getAnnotationType().asElement() == eee) {
+                Map<? extends ExecutableElement, ? extends AnnotationValue> vals = am.getElementValues();
+                if (vals.size() == 1) {
+                    AnnotationValue av = vals.values().iterator().next();
+                    if (av.getValue() instanceof List) {
+                        List<?> arr = (List<?>) av.getValue();
+                        for (Object o : arr) {
+                            if (o instanceof AnnotationValue) {
+                                AnnotationValue ov = (AnnotationValue) o;
+                                if (msg.equals(ov.getValue())) {
+                                    return;
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        processingEnv.getMessager().printMessage(Kind.ERROR, msg, e);
     }
 
     /**