Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/java/ElementUtils.java @ 20940:476374f3fe9a
Truffle-DSL: generate better polymorphic execute signatures
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Tue, 14 Apr 2015 15:12:48 +0200 |
parents | f83fd99b2962 |
children | 810d466073f0 |
comparison
equal
deleted
inserted
replaced
20939:f83fd99b2962 | 20940:476374f3fe9a |
---|---|
118 b.append(")"); | 118 b.append(")"); |
119 return b.toString(); | 119 return b.toString(); |
120 } | 120 } |
121 | 121 |
122 public static TypeMirror boxType(ProcessorContext context, TypeMirror primitiveType) { | 122 public static TypeMirror boxType(ProcessorContext context, TypeMirror primitiveType) { |
123 if (primitiveType == null) { | |
124 return null; | |
125 } | |
123 TypeMirror boxedType = primitiveType; | 126 TypeMirror boxedType = primitiveType; |
124 if (boxedType.getKind().isPrimitive()) { | 127 if (boxedType.getKind().isPrimitive()) { |
125 boxedType = context.getEnvironment().getTypeUtils().boxedClass((PrimitiveType) boxedType).asType(); | 128 boxedType = context.getEnvironment().getTypeUtils().boxedClass((PrimitiveType) boxedType).asType(); |
126 } | 129 } |
127 return boxedType; | 130 return boxedType; |
213 case ERROR: | 216 case ERROR: |
214 return true; | 217 return true; |
215 default: | 218 default: |
216 throw new RuntimeException("Unknown type specified " + mirror.getKind() + " mirror: " + mirror); | 219 throw new RuntimeException("Unknown type specified " + mirror.getKind() + " mirror: " + mirror); |
217 } | 220 } |
221 } | |
222 | |
223 public static boolean isSubtypeBoxed(ProcessorContext context, TypeMirror from, TypeMirror to) { | |
224 return isSubtype(boxType(context, from), boxType(context, to)); | |
218 } | 225 } |
219 | 226 |
220 public static boolean isSubtype(TypeMirror type1, TypeMirror type2) { | 227 public static boolean isSubtype(TypeMirror type1, TypeMirror type2) { |
221 if (type1 instanceof CodeTypeMirror || type2 instanceof CodeTypeMirror) { | 228 if (type1 instanceof CodeTypeMirror || type2 instanceof CodeTypeMirror) { |
222 throw new UnsupportedOperationException(); | 229 throw new UnsupportedOperationException(); |
1176 return ElementUtils.getSimpleName(signature1).compareTo(ElementUtils.getSimpleName(signature2)); | 1183 return ElementUtils.getSimpleName(signature1).compareTo(ElementUtils.getSimpleName(signature2)); |
1177 } | 1184 } |
1178 | 1185 |
1179 public static List<TypeMirror> uniqueSortedTypes(Collection<TypeMirror> types) { | 1186 public static List<TypeMirror> uniqueSortedTypes(Collection<TypeMirror> types) { |
1180 if (types.isEmpty()) { | 1187 if (types.isEmpty()) { |
1181 return Collections.emptyList(); | 1188 return new ArrayList<>(0); |
1182 } else if (types.size() <= 1) { | 1189 } else if (types.size() <= 1) { |
1183 if (types instanceof List) { | 1190 if (types instanceof List) { |
1184 return (List<TypeMirror>) types; | 1191 return (List<TypeMirror>) types; |
1185 } else { | 1192 } else { |
1186 return new ArrayList<>(types); | 1193 return new ArrayList<>(types); |