comparison graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/template/TemplateParser.java @ 8252:0905d796944a

Refactored codegen error model to make error redirection a lot easier.
author Christian Humer <christian.humer@gmail.com>
date Wed, 13 Mar 2013 19:58:28 +0100
parents 5e3d1a68664e
children 8b2573c8d47f
comparison
equal deleted inserted replaced
8251:cb70ed101b5f 8252:0905d796944a
41 41
42 public ExtensionParser getExtensionParser() { 42 public ExtensionParser getExtensionParser() {
43 return extensionParser; 43 return extensionParser;
44 } 44 }
45 45
46 protected boolean verifyExclusiveMethodAnnotation(TypeElement type, Class<?>... annotationTypes) { 46 protected void verifyExclusiveMethodAnnotation(Template template, Class<?>... annotationTypes) {
47 boolean valid = true; 47 List<ExecutableElement> methods = ElementFilter.methodsIn(template.getTemplateType().getEnclosedElements());
48 List<ExecutableElement> methods = ElementFilter.methodsIn(type.getEnclosedElements());
49 for (ExecutableElement method : methods) { 48 for (ExecutableElement method : methods) {
50 List<AnnotationMirror> foundAnnotations = new ArrayList<>(); 49 List<AnnotationMirror> foundAnnotations = new ArrayList<>();
51 for (int i = 0; i < annotationTypes.length; i++) { 50 for (int i = 0; i < annotationTypes.length; i++) {
52 Class<?> annotationType = annotationTypes[i]; 51 Class<?> annotationType = annotationTypes[i];
53 AnnotationMirror mirror = Utils.findAnnotationMirror(context.getEnvironment(), method, annotationType); 52 AnnotationMirror mirror = Utils.findAnnotationMirror(context.getEnvironment(), method, annotationType);
59 List<String> annotationNames = new ArrayList<>(); 58 List<String> annotationNames = new ArrayList<>();
60 for (AnnotationMirror mirror : foundAnnotations) { 59 for (AnnotationMirror mirror : foundAnnotations) {
61 annotationNames.add("@" + Utils.getSimpleName(mirror.getAnnotationType())); 60 annotationNames.add("@" + Utils.getSimpleName(mirror.getAnnotationType()));
62 } 61 }
63 62
64 for (AnnotationMirror mirror : foundAnnotations) { 63 template.addError("Non exclusive usage of annotations %s.", annotationNames);
65 context.getLog().error(method, mirror, "Non exclusive usage of annotations %s.", annotationNames);
66 }
67 valid = false;
68 } 64 }
69 } 65 }
70 return valid;
71 }
72
73 protected boolean verifyTemplateType(TypeElement template, AnnotationMirror annotation) {
74 // annotation type on class path!?
75 boolean valid = true;
76 TypeElement annotationTypeElement = processingEnv.getElementUtils().getTypeElement(getAnnotationType().getCanonicalName());
77 if (annotationTypeElement == null) {
78 log.error(template, annotation, "Required class " + getAnnotationType().getName() + " is not on the classpath.");
79 valid = false;
80 }
81 if (template.getModifiers().contains(Modifier.PRIVATE)) {
82 log.error(template, annotation, "The annotated class must have at least package protected visibility.");
83 valid = false;
84 }
85
86 if (template.getModifiers().contains(Modifier.FINAL)) {
87 log.error(template, annotation, "The annotated class must not be final.");
88 valid = false;
89 }
90
91 return valid;
92 } 66 }
93 67
94 } 68 }