use of javax.lang.model.type.ArrayType in project buck by facebook.
the class TreeBackedTypesTest method testIsNotSameTypeArrayType.
@Test
public void testIsNotSameTypeArrayType() throws IOException {
compile(Joiner.on('\n').join("class Foo { }", "class Bar { }"));
TypeMirror fooType = elements.getTypeElement("Foo").asType();
TypeMirror barType = elements.getTypeElement("Bar").asType();
ArrayType fooArray = types.getArrayType(fooType);
ArrayType barArray = types.getArrayType(barType);
assertNotSameType(fooArray, barArray);
}
use of javax.lang.model.type.ArrayType in project buck by facebook.
the class TypeResolverTest method testPrimitiveArrayTypeResolves.
@Test
public void testPrimitiveArrayTypeResolves() throws IOException {
compile("abstract class Foo extends java.util.ArrayList<int[]> { }");
TypeElement fooElement = elements.getTypeElement("Foo");
TypeElement listElement = elements.getTypeElement("java.util.ArrayList");
TypeMirror intType = types.getPrimitiveType(TypeKind.INT);
ArrayType intArrayType = types.getArrayType(intType);
DeclaredType expectedSuperclass = types.getDeclaredType(listElement, intArrayType);
assertSameType(expectedSuperclass, fooElement.getSuperclass());
}
use of javax.lang.model.type.ArrayType in project buck by facebook.
the class TypeResolverTest method testArrayTypeResolves.
@Test
public void testArrayTypeResolves() throws IOException {
compile("abstract class Foo extends java.util.ArrayList<java.lang.String[]> { }");
TypeElement fooElement = elements.getTypeElement("Foo");
TypeElement listElement = elements.getTypeElement("java.util.ArrayList");
TypeMirror stringType = elements.getTypeElement("java.lang.String").asType();
ArrayType stringArrayType = types.getArrayType(stringType);
DeclaredType expectedSuperclass = types.getDeclaredType(listElement, stringArrayType);
assertSameType(expectedSuperclass, fooElement.getSuperclass());
}
use of javax.lang.model.type.ArrayType in project buck by facebook.
the class TreeBackedTypesTest method testIsSameTypeArrayType.
@Test
public void testIsSameTypeArrayType() throws IOException {
compile("class Foo { }");
TypeElement fooElement = elements.getTypeElement("Foo");
ArrayType fooArray = types.getArrayType(fooElement.asType());
ArrayType fooArray2 = types.getArrayType(fooElement.asType());
assertSameType(fooArray, fooArray2);
assertNotSameType(fooArray, fooElement.asType());
}
use of javax.lang.model.type.ArrayType in project auto by google.
the class AutoAnnotationProcessor method compatibleTypes.
/**
* Returns true if {@code parameterType} can be used to provide the value of an annotation member
* of type {@code memberType}. They must either be the same type, or the member type must be an
* array and the parameter type must be a collection of a compatible type.
*/
private boolean compatibleTypes(TypeMirror parameterType, TypeMirror memberType) {
if (typeUtils.isAssignable(parameterType, memberType)) {
// is a subtype of that annotation interface (why would you do that?).
return true;
}
// to Collection<Integer> (in this example).
if (memberType.getKind() != TypeKind.ARRAY) {
return false;
}
TypeMirror arrayElementType = ((ArrayType) memberType).getComponentType();
TypeMirror wrappedArrayElementType = arrayElementType.getKind().isPrimitive() ? typeUtils.boxedClass((PrimitiveType) arrayElementType).asType() : arrayElementType;
TypeElement javaUtilCollection = processingEnv.getElementUtils().getTypeElement(Collection.class.getCanonicalName());
DeclaredType collectionOfElement = typeUtils.getDeclaredType(javaUtilCollection, wrappedArrayElementType);
return typeUtils.isAssignable(parameterType, collectionOfElement);
}
Aggregations