added utility method to retrieve a type's upper bound (JSweet 2 catch-up d01acde34e)

This commit is contained in:
Louis Grignon 2020-09-01 16:56:48 +02:00
parent f502b67b88
commit 1efa9caf6a

View File

@ -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).
*/