Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/LanguageRegistrationProcessor.java @ 21494:f5b49d881909
Truffle-DSL: move internal @ExpectError annotation from public API to the test package only; share expect error handling between new processors.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Tue, 26 May 2015 20:04:08 +0200 |
parents | bb51b9a142b3 |
children | 31fc2fce38f3 |
comparison
equal
deleted
inserted
replaced
21493:99e3f4c5c853 | 21494:f5b49d881909 |
---|---|
20 * or visit www.oracle.com if you need additional information or have any | 20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. | 21 * questions. |
22 */ | 22 */ |
23 package com.oracle.truffle.dsl.processor; | 23 package com.oracle.truffle.dsl.processor; |
24 | 24 |
25 import com.oracle.truffle.api.TruffleLanguage; | 25 import java.io.*; |
26 import java.util.*; | |
27 | |
28 import javax.annotation.processing.*; | |
29 import javax.lang.model.*; | |
30 import javax.lang.model.element.*; | |
31 import javax.lang.model.type.*; | |
32 import javax.tools.Diagnostic.Kind; | |
33 import javax.tools.*; | |
34 | |
35 import com.oracle.truffle.api.*; | |
26 import com.oracle.truffle.api.TruffleLanguage.Registration; | 36 import com.oracle.truffle.api.TruffleLanguage.Registration; |
27 import com.oracle.truffle.api.dsl.ExpectError; | |
28 import java.io.IOException; | |
29 import java.io.OutputStream; | |
30 import java.util.List; | |
31 import java.util.Map; | |
32 import java.util.Properties; | |
33 import java.util.Set; | |
34 import javax.annotation.processing.AbstractProcessor; | |
35 import javax.annotation.processing.RoundEnvironment; | |
36 import javax.annotation.processing.SupportedAnnotationTypes; | |
37 import javax.lang.model.SourceVersion; | |
38 import javax.lang.model.element.AnnotationMirror; | |
39 import javax.lang.model.element.AnnotationValue; | |
40 import javax.lang.model.element.Element; | |
41 import javax.lang.model.element.ElementKind; | |
42 import javax.lang.model.element.ExecutableElement; | |
43 import javax.lang.model.element.Modifier; | |
44 import javax.lang.model.element.TypeElement; | |
45 import javax.lang.model.type.TypeMirror; | |
46 import javax.tools.Diagnostic.Kind; | |
47 import javax.tools.FileObject; | |
48 import javax.tools.StandardLocation; | |
49 | 37 |
50 @SupportedAnnotationTypes("com.oracle.truffle.api.*") | 38 @SupportedAnnotationTypes("com.oracle.truffle.api.*") |
51 public final class LanguageRegistrationProcessor extends AbstractProcessor { | 39 public final class LanguageRegistrationProcessor extends AbstractProcessor { |
52 @Override | 40 @Override |
53 public SourceVersion getSupportedSourceVersion() { | 41 public SourceVersion getSupportedSourceVersion() { |
121 | 109 |
122 return true; | 110 return true; |
123 } | 111 } |
124 | 112 |
125 void assertNoErrorExpected(Element e) { | 113 void assertNoErrorExpected(Element e) { |
126 TypeElement eee = processingEnv.getElementUtils().getTypeElement(ExpectError.class.getName()); | 114 ExpectError.assertNoErrorExpected(processingEnv, e); |
127 for (AnnotationMirror am : e.getAnnotationMirrors()) { | |
128 if (am.getAnnotationType().asElement().equals(eee)) { | |
129 processingEnv.getMessager().printMessage(Kind.ERROR, "Expected an error, but none found!", e); | |
130 } | |
131 } | |
132 } | 115 } |
133 | 116 |
134 void emitError(String msg, Element e) { | 117 void emitError(String msg, Element e) { |
135 TypeElement eee = processingEnv.getElementUtils().getTypeElement(ExpectError.class.getName()); | 118 if (ExpectError.isExpectedError(processingEnv, e, msg)) { |
136 for (AnnotationMirror am : e.getAnnotationMirrors()) { | 119 return; |
137 if (am.getAnnotationType().asElement().equals(eee)) { | |
138 Map<? extends ExecutableElement, ? extends AnnotationValue> vals = am.getElementValues(); | |
139 if (vals.size() == 1) { | |
140 AnnotationValue av = vals.values().iterator().next(); | |
141 if (av.getValue() instanceof List) { | |
142 List<?> arr = (List<?>) av.getValue(); | |
143 for (Object o : arr) { | |
144 if (o instanceof AnnotationValue) { | |
145 AnnotationValue ov = (AnnotationValue) o; | |
146 if (msg.equals(ov.getValue())) { | |
147 return; | |
148 } | |
149 } | |
150 } | |
151 } | |
152 } | |
153 } | |
154 } | 120 } |
155 processingEnv.getMessager().printMessage(Kind.ERROR, msg, e); | 121 processingEnv.getMessager().printMessage(Kind.ERROR, msg, e); |
156 } | 122 } |
123 | |
157 } | 124 } |