Mercurial > hg > graal-jvmci-8
diff graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/java/ElementUtils.java @ 16923:93e061157811
Truffle-DSL: better support for types with type arguments.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 25 Aug 2014 20:59:56 +0200 |
parents | 62cfffca9be2 |
children | cbe585ebce98 |
line wrap: on
line diff
--- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/java/ElementUtils.java Mon Aug 25 16:30:40 2014 +0200 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/java/ElementUtils.java Mon Aug 25 20:59:56 2014 +0200 @@ -34,6 +34,7 @@ import com.oracle.truffle.dsl.processor.*; import com.oracle.truffle.dsl.processor.java.model.*; import com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.DeclaredCodeTypeMirror; +import com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.WildcardTypeMirror; /** * THIS IS NOT PUBLIC API. @@ -1034,4 +1035,35 @@ return actualType.getKind() == TypeKind.DECLARED && getQualifiedName(actualType).equals("java.lang.Object"); } + public static TypeMirror fillInGenericWildcards(TypeMirror type) { + if (type.getKind() != TypeKind.DECLARED) { + return type; + } + DeclaredType declaredType = (DeclaredType) type; + TypeElement element = (TypeElement) declaredType.asElement(); + if (element == null) { + return type; + } + int typeParameters = element.getTypeParameters().size(); + if (typeParameters > 0 && declaredType.getTypeArguments().size() != typeParameters) { + List<TypeMirror> genericTypes = new ArrayList<>(); + for (int i = 0; i < typeParameters; i++) { + genericTypes.add(new WildcardTypeMirror(null, null)); + } + return new DeclaredCodeTypeMirror(element, genericTypes); + } + return type; + } + + public static TypeMirror eraseGenericTypes(TypeMirror type) { + if (type.getKind() != TypeKind.DECLARED) { + return type; + } + DeclaredType declaredType = (DeclaredType) type; + if (declaredType.getTypeArguments().size() == 0) { + return type; + } + return new DeclaredCodeTypeMirror((TypeElement) declaredType.asElement()); + } + }