Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/Utils.java @ 9220:97ad6d3e7557
Codegen API changes. Executed child nodes are now defined using @NodeChildren instead of fields.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Sat, 20 Apr 2013 12:16:22 +0200 |
parents | bd067a48a9c2 |
children | 6d92fdf1c999 |
comparison
equal
deleted
inserted
replaced
9219:1964871a642d | 9220:97ad6d3e7557 |
---|---|
30 import javax.lang.model.element.*; | 30 import javax.lang.model.element.*; |
31 import javax.lang.model.type.*; | 31 import javax.lang.model.type.*; |
32 import javax.lang.model.util.*; | 32 import javax.lang.model.util.*; |
33 | 33 |
34 import com.oracle.truffle.codegen.processor.ast.*; | 34 import com.oracle.truffle.codegen.processor.ast.*; |
35 import com.oracle.truffle.codegen.processor.ast.CodeTypeMirror.DeclaredCodeTypeMirror; | |
35 import com.oracle.truffle.codegen.processor.compiler.*; | 36 import com.oracle.truffle.codegen.processor.compiler.*; |
36 | 37 |
37 /** | 38 /** |
38 * THIS IS NOT PUBLIC API. | 39 * THIS IS NOT PUBLIC API. |
39 */ | 40 */ |
61 types.add(element.asType()); | 62 types.add(element.asType()); |
62 } | 63 } |
63 return types; | 64 return types; |
64 } | 65 } |
65 | 66 |
67 public static DeclaredType getDeclaredType(TypeElement typeElem, TypeMirror... typeArgs) { | |
68 return new DeclaredCodeTypeMirror(typeElem, Arrays.asList(typeArgs)); | |
69 } | |
70 | |
66 public static List<AnnotationMirror> collectAnnotations(ProcessorContext context, AnnotationMirror markerAnnotation, String elementName, Element element, | 71 public static List<AnnotationMirror> collectAnnotations(ProcessorContext context, AnnotationMirror markerAnnotation, String elementName, Element element, |
67 Class<? extends Annotation> annotationClass) { | 72 Class<? extends Annotation> annotationClass) { |
68 List<AnnotationMirror> result = Utils.getAnnotationValueList(AnnotationMirror.class, markerAnnotation, elementName); | 73 List<AnnotationMirror> result = new ArrayList<>(); |
74 if (markerAnnotation != null) { | |
75 result.addAll(Utils.getAnnotationValueList(AnnotationMirror.class, markerAnnotation, elementName)); | |
76 } | |
69 AnnotationMirror explicit = Utils.findAnnotationMirror(context.getEnvironment(), element, annotationClass); | 77 AnnotationMirror explicit = Utils.findAnnotationMirror(context.getEnvironment(), element, annotationClass); |
70 if (explicit != null) { | 78 if (explicit != null) { |
71 result.add(explicit); | 79 result.add(explicit); |
72 } | |
73 | |
74 for (AnnotationMirror mirror : result) { | |
75 assert Utils.typeEquals(mirror.getAnnotationType(), context.getType(annotationClass)); | |
76 } | 80 } |
77 return result; | 81 return result; |
78 } | 82 } |
79 | 83 |
80 public static TypeMirror getCommonSuperType(ProcessorContext context, TypeMirror[] types) { | 84 public static TypeMirror getCommonSuperType(ProcessorContext context, TypeMirror[] types) { |
317 return "void"; | 321 return "void"; |
318 case TYPEVAR: | 322 case TYPEVAR: |
319 return getSimpleName(mirror); | 323 return getSimpleName(mirror); |
320 case ERROR: | 324 case ERROR: |
321 throw new CompileErrorException("Type error " + mirror); | 325 throw new CompileErrorException("Type error " + mirror); |
326 case NONE: | |
327 return "$none"; | |
322 default: | 328 default: |
323 throw new RuntimeException("Unknown type specified " + mirror + " mirror: " + mirror); | 329 throw new RuntimeException("Unknown type specified " + mirror + " mirror: " + mirror); |
324 } | 330 } |
325 } | 331 } |
326 | 332 |
369 } | 375 } |
370 | 376 |
371 return null; | 377 return null; |
372 } | 378 } |
373 | 379 |
374 private static List<Element> getElementHierarchy(Element e) { | 380 public static List<Element> getElementHierarchy(Element e) { |
375 List<Element> elements = new ArrayList<>(); | 381 List<Element> elements = new ArrayList<>(); |
376 elements.add(e); | 382 elements.add(e); |
377 | 383 |
378 Element enclosing = e.getEnclosingElement(); | 384 Element enclosing = e.getEnclosingElement(); |
379 while (enclosing != null && enclosing.getKind() != ElementKind.PACKAGE) { | 385 while (enclosing != null && enclosing.getKind() != ElementKind.PACKAGE) { |
587 return t; | 593 return t; |
588 } | 594 } |
589 | 595 |
590 @Override | 596 @Override |
591 public Object visitEnumConstant(VariableElement c, Void p) { | 597 public Object visitEnumConstant(VariableElement c, Void p) { |
592 return c.getConstantValue(); | 598 return c; |
593 } | 599 } |
594 | 600 |
595 @Override | 601 @Override |
596 public Object visitAnnotation(AnnotationMirror a, Void p) { | 602 public Object visitAnnotation(AnnotationMirror a, Void p) { |
597 return a; | 603 return a; |
770 return false; | 776 return false; |
771 } | 777 } |
772 | 778 |
773 public static Modifier getVisibility(Set<Modifier> modifier) { | 779 public static Modifier getVisibility(Set<Modifier> modifier) { |
774 for (Modifier mod : modifier) { | 780 for (Modifier mod : modifier) { |
775 if (mod == Modifier.PUBLIC) { | 781 if (mod == Modifier.PUBLIC || mod == Modifier.PRIVATE || mod == Modifier.PROTECTED) { |
776 return mod; | |
777 } else if (mod == Modifier.PRIVATE) { | |
778 return mod; | |
779 } else if (mod == Modifier.PROTECTED) { | |
780 return mod; | 782 return mod; |
781 } | 783 } |
782 } | 784 } |
783 return null; | 785 return null; |
784 } | 786 } |
811 | 813 |
812 public static boolean isObject(TypeMirror actualType) { | 814 public static boolean isObject(TypeMirror actualType) { |
813 return getQualifiedName(actualType).equals("java.lang.Object"); | 815 return getQualifiedName(actualType).equals("java.lang.Object"); |
814 } | 816 } |
815 | 817 |
818 public static boolean isFieldAccessible(Element element, VariableElement variable) { | |
819 TypeElement type = Utils.findNearestEnclosingType(element); | |
820 TypeElement varType = Utils.findNearestEnclosingType(variable); | |
821 | |
822 while (type != null) { | |
823 if (typeEquals(type.asType(), varType.asType())) { | |
824 return true; | |
825 } | |
826 if (type.getSuperclass() != null) { | |
827 type = Utils.fromTypeMirror(type.getSuperclass()); | |
828 } else { | |
829 type = null; | |
830 } | |
831 } | |
832 return false; | |
833 } | |
816 } | 834 } |