Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/java/ElementUtils.java @ 19295:35c3e3af8c39
Truffle-DSL: cleanup unused methods.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Wed, 11 Feb 2015 16:12:53 +0100 |
parents | 62c43fcf5be2 |
children | 2bd8b3aa282f |
comparison
equal
deleted
inserted
replaced
19294:b31b2f289e7d | 19295:35c3e3af8c39 |
---|---|
585 } | 585 } |
586 | 586 |
587 return types; | 587 return types; |
588 } | 588 } |
589 | 589 |
590 public static List<TypeMirror> getAssignableTypes(ProcessorContext context, TypeMirror type) { | |
591 if (isPrimitive(type)) { | |
592 return Arrays.asList(type, boxType(context, type), context.getType(Object.class)); | |
593 } else if (type.getKind() == TypeKind.ARRAY) { | |
594 return Arrays.asList(type, context.getType(Object.class)); | |
595 } else if (type.getKind() == TypeKind.DECLARED) { | |
596 DeclaredType declaredType = (DeclaredType) type; | |
597 TypeElement typeElement = fromTypeMirror(declaredType); | |
598 List<TypeElement> types = getSuperTypes(typeElement); | |
599 List<TypeMirror> mirrors = new ArrayList<>(types.size()); | |
600 mirrors.add(type); | |
601 for (TypeElement superTypeElement : types) { | |
602 mirrors.add(superTypeElement.asType()); | |
603 } | |
604 if (typeElement.getKind().isInterface()) { | |
605 mirrors.add(getType(context.getEnvironment(), Object.class)); | |
606 } | |
607 return mirrors; | |
608 } else { | |
609 return Collections.emptyList(); | |
610 } | |
611 } | |
612 | |
613 /** | 590 /** |
614 * Gets the element representing the {@linkplain TypeElement#getSuperclass() super class} of a | 591 * Gets the element representing the {@linkplain TypeElement#getSuperclass() super class} of a |
615 * given type element. | 592 * given type element. |
616 */ | 593 */ |
617 public static TypeElement getSuperType(TypeElement element) { | 594 public static TypeElement getSuperType(TypeElement element) { |
1080 return type; | 1057 return type; |
1081 } | 1058 } |
1082 return new DeclaredCodeTypeMirror((TypeElement) declaredType.asElement()); | 1059 return new DeclaredCodeTypeMirror((TypeElement) declaredType.asElement()); |
1083 } | 1060 } |
1084 | 1061 |
1085 public static ExecutableElement findMethod(TypeElement type, Set<Modifier> includeModifiers, Set<Modifier> excludeModifiers, String methodName, List<TypeMirror> types) { | |
1086 outer: for (ExecutableElement executable : ElementFilter.methodsIn(type.getEnclosedElements())) { | |
1087 if (includeModifiers != null) { | |
1088 if (!executable.getModifiers().containsAll(includeModifiers)) { | |
1089 continue; | |
1090 } | |
1091 } | |
1092 if (excludeModifiers != null) { | |
1093 if (executable.getModifiers().containsAll(excludeModifiers)) { | |
1094 continue; | |
1095 } | |
1096 } | |
1097 if (!executable.getSimpleName().toString().equals(methodName)) { | |
1098 continue; | |
1099 } | |
1100 if (types.size() != executable.getParameters().size()) { | |
1101 continue; | |
1102 } | |
1103 for (int i = 0; i < types.size(); i++) { | |
1104 TypeMirror var1 = types.get(i); | |
1105 VariableElement var2 = executable.getParameters().get(i); | |
1106 if (ElementUtils.typeEquals(var1, var2.asType())) { | |
1107 continue outer; | |
1108 } | |
1109 } | |
1110 return executable; | |
1111 } | |
1112 return null; | |
1113 } | |
1114 | |
1115 public static List<TypeMirror> asTypes(List<? extends Element> elements) { | |
1116 List<TypeMirror> types = new ArrayList<>(elements.size()); | |
1117 for (Element element : elements) { | |
1118 types.add(element.asType()); | |
1119 } | |
1120 return types; | |
1121 } | |
1122 | |
1123 public static boolean variableEquals(VariableElement var1, VariableElement var2) { | 1062 public static boolean variableEquals(VariableElement var1, VariableElement var2) { |
1124 if (!var1.getSimpleName().equals(var2.getSimpleName())) { | 1063 if (!var1.getSimpleName().equals(var2.getSimpleName())) { |
1125 return false; | 1064 return false; |
1126 } | 1065 } |
1127 if (!ElementUtils.typeEquals(var1.asType(), var2.asType())) { | 1066 if (!ElementUtils.typeEquals(var1.asType(), var2.asType())) { |