diff --git a/transpiler/src/main/java/org/jsweet/transpiler/util/Util.java b/transpiler/src/main/java/org/jsweet/transpiler/util/Util.java index 095b099d..3008f05a 100644 --- a/transpiler/src/main/java/org/jsweet/transpiler/util/Util.java +++ b/transpiler/src/main/java/org/jsweet/transpiler/util/Util.java @@ -55,6 +55,7 @@ import javax.lang.model.type.ExecutableType; import javax.lang.model.type.PrimitiveType; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; +import javax.lang.model.type.TypeVariable; import javax.lang.model.util.Elements; import javax.lang.model.util.Types; import javax.tools.JavaFileObject; @@ -124,6 +125,18 @@ public class Util { this.context = context; } + /** + * If the given type is a capture and has an upper bound, returns it, else + * return the given type unchanged. + */ + public TypeMirror getUpperBound(TypeMirror type) { + if (type instanceof TypeVariable && ((TypeVariable) type).getUpperBound() != null) { + return ((TypeVariable) type).getUpperBound(); + } else { + return type; + } + } + /** * Gets the type arguments of a given type (if any). */