use of javax.lang.model.type.WildcardType in project buck by facebook.
the class StandaloneWildcardTypeTest method testSuperToString.
@Test
public void testSuperToString() throws IOException {
initCompiler();
WildcardType wildcard = types.getWildcardType(null, elements.getTypeElement("java.lang.String").asType());
assertEquals("? super java.lang.String", wildcard.toString());
}
use of javax.lang.model.type.WildcardType in project buck by facebook.
the class StandaloneWildcardTypeTest method testUnboundedToString.
@Test
public void testUnboundedToString() throws IOException {
initCompiler();
WildcardType wildcard = types.getWildcardType(null, null);
assertEquals("?", wildcard.toString());
}
use of javax.lang.model.type.WildcardType in project buck by facebook.
the class StandaloneWildcardTypeTest method testExtendsToString.
@Test
public void testExtendsToString() throws IOException {
initCompiler();
WildcardType wildcard = types.getWildcardType(elements.getTypeElement("java.lang.CharSequence").asType(), null);
assertEquals("? extends java.lang.CharSequence", wildcard.toString());
}
use of javax.lang.model.type.WildcardType in project buck by facebook.
the class TreeBackedTypesTest method testIsSameTypeWildcardType.
@Test
public void testIsSameTypeWildcardType() throws IOException {
compile("class Foo { }");
WildcardType wildcardType = types.getWildcardType(null, null);
WildcardType wildcardType2 = types.getWildcardType(null, null);
// According to the docs, wildcard types are never equal to one another, even if they're
// the exact same instance.
assertNotSameType(wildcardType, wildcardType);
assertNotSameType(wildcardType, wildcardType2);
}
use of javax.lang.model.type.WildcardType in project bazel by bazelbuild.
the class InternalUtils method leastUpperBound.
/**
* Returns the least upper bound of two {@link TypeMirror}s.
*
* @param processingEnv The {@link ProcessingEnvironment} to use.
* @param tm1 A {@link TypeMirror}.
* @param tm2 A {@link TypeMirror}.
* @return The least upper bound of {@code tm1} and {@code tm2}.
*/
public static TypeMirror leastUpperBound(ProcessingEnvironment processingEnv, TypeMirror tm1, TypeMirror tm2) {
Type t1 = (Type) tm1;
Type t2 = (Type) tm2;
JavacProcessingEnvironment javacEnv = (JavacProcessingEnvironment) processingEnv;
Types types = Types.instance(javacEnv.getContext());
if (types.isSameType(t1, t2)) {
// Special case if the two types are equal.
return t1;
}
// Handle the 'null' type manually (not done by types.lub).
if (t1.getKind() == TypeKind.NULL) {
return t2;
}
if (t2.getKind() == TypeKind.NULL) {
return t1;
}
// Special case for primitives.
if (TypesUtils.isPrimitive(t1) || TypesUtils.isPrimitive(t2)) {
if (types.isAssignable(t1, t2)) {
return t2;
} else if (types.isAssignable(t2, t1)) {
return t1;
} else {
return processingEnv.getTypeUtils().getNoType(TypeKind.NONE);
}
}
if (t1.getKind() == TypeKind.WILDCARD) {
WildcardType wc1 = (WildcardType) t1;
Type bound = (Type) wc1.getExtendsBound();
if (bound == null) {
// Implicit upper bound of java.lang.Object
Elements elements = processingEnv.getElementUtils();
return elements.getTypeElement("java.lang.Object").asType();
}
t1 = bound;
}
if (t2.getKind() == TypeKind.WILDCARD) {
WildcardType wc2 = (WildcardType) t2;
Type bound = (Type) wc2.getExtendsBound();
if (bound == null) {
// Implicit upper bound of java.lang.Object
Elements elements = processingEnv.getElementUtils();
return elements.getTypeElement("java.lang.Object").asType();
}
t2 = bound;
}
return types.lub(t1, t2);
}
Aggregations