Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/java/ElementUtils.java @ 16786:45c8f64978d6
Truffle-DSL: initial cleanups for code sharing with the new graal annotation processor.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Tue, 12 Aug 2014 17:21:06 +0200 |
parents | 89f635cbd85e |
children | 7977cb9fa21f |
comparison
equal
deleted
inserted
replaced
16785:af3da93ea934 | 16786:45c8f64978d6 |
---|---|
37 | 37 |
38 /** | 38 /** |
39 * THIS IS NOT PUBLIC API. | 39 * THIS IS NOT PUBLIC API. |
40 */ | 40 */ |
41 public class ElementUtils { | 41 public class ElementUtils { |
42 | |
43 public static TypeMirror getType(ProcessingEnvironment processingEnv, Class<?> element) { | |
44 TypeMirror mirror; | |
45 if (element.isPrimitive()) { | |
46 TypeKind typeKind; | |
47 if (element == boolean.class) { | |
48 typeKind = TypeKind.BOOLEAN; | |
49 } else if (element == byte.class) { | |
50 typeKind = TypeKind.BYTE; | |
51 } else if (element == short.class) { | |
52 typeKind = TypeKind.SHORT; | |
53 } else if (element == char.class) { | |
54 typeKind = TypeKind.CHAR; | |
55 } else if (element == int.class) { | |
56 typeKind = TypeKind.INT; | |
57 } else if (element == long.class) { | |
58 typeKind = TypeKind.LONG; | |
59 } else if (element == float.class) { | |
60 typeKind = TypeKind.FLOAT; | |
61 } else if (element == double.class) { | |
62 typeKind = TypeKind.DOUBLE; | |
63 } else if (element == void.class) { | |
64 typeKind = TypeKind.VOID; | |
65 } else { | |
66 assert false; | |
67 return null; | |
68 } | |
69 mirror = processingEnv.getTypeUtils().getPrimitiveType(typeKind); | |
70 } else { | |
71 mirror = processingEnv.getElementUtils().getTypeElement(element.getCanonicalName()).asType(); | |
72 } | |
73 return mirror; | |
74 } | |
42 | 75 |
43 public static ExecutableElement findExecutableElement(DeclaredType type, String name) { | 76 public static ExecutableElement findExecutableElement(DeclaredType type, String name) { |
44 List<? extends ExecutableElement> elements = ElementFilter.methodsIn(type.asElement().getEnclosedElements()); | 77 List<? extends ExecutableElement> elements = ElementFilter.methodsIn(type.asElement().getEnclosedElements()); |
45 for (ExecutableElement executableElement : elements) { | 78 for (ExecutableElement executableElement : elements) { |
46 if (executableElement.getSimpleName().toString().equals(name)) { | 79 if (executableElement.getSimpleName().toString().equals(name)) { |
799 } | 832 } |
800 } | 833 } |
801 return null; | 834 return null; |
802 } | 835 } |
803 | 836 |
804 private static PackageElement findPackageElement(Element type) { | 837 public static PackageElement findPackageElement(Element type) { |
805 List<Element> hierarchy = getElementHierarchy(type); | 838 List<Element> hierarchy = getElementHierarchy(type); |
806 for (Element element : hierarchy) { | 839 for (Element element : hierarchy) { |
807 if (element.getKind() == ElementKind.PACKAGE) { | 840 if (element.getKind() == ElementKind.PACKAGE) { |
808 return (PackageElement) element; | 841 return (PackageElement) element; |
809 } | 842 } |