use of javax.lang.model.type.TypeMirror in project auto by google.
the class MoreTypesIsTypeOfTest method isTypeOf_PrimitiveFloat.
@Test
public void isTypeOf_PrimitiveFloat() {
assertTrue(MoreTypes.isType(typeElementFor(PrimitiveFloat.class).asType()));
TypeMirror type = extractReturnTypeFromHolder(typeElementFor(PrimitiveFloat.class));
assertThat(MoreTypes.isTypeOf(Float.TYPE, type)).named("mirror of a float").isTrue();
}
use of javax.lang.model.type.TypeMirror in project auto by google.
the class MoreTypesIsTypeOfTest method isTypeOf_PrimitiveLong.
@Test
public void isTypeOf_PrimitiveLong() {
assertTrue(MoreTypes.isType(typeElementFor(PrimitiveLong.class).asType()));
TypeMirror type = extractReturnTypeFromHolder(typeElementFor(PrimitiveLong.class));
assertThat(MoreTypes.isTypeOf(Long.TYPE, type)).named("mirror of a long").isTrue();
}
use of javax.lang.model.type.TypeMirror in project auto by google.
the class TypeSimplifierTest method testImportsForComplicatedTypes.
@Test
public void testImportsForComplicatedTypes() {
TypeElement list = typeElementOf(java.util.List.class);
TypeElement map = typeElementOf(java.util.Map.class);
Set<TypeMirror> types = typeMirrorSet(typeUtils.getPrimitiveType(TypeKind.INT), typeMirrorOf(java.util.regex.Pattern.class), // List<Timer>
typeUtils.getDeclaredType(// List<Timer>
list, typeMirrorOf(java.util.Timer.class)), // Map<? extends Timer, ? super BigInteger>
typeUtils.getDeclaredType(// Map<? extends Timer, ? super BigInteger>
map, typeUtils.getWildcardType(typeMirrorOf(java.util.Timer.class), null), typeUtils.getWildcardType(null, typeMirrorOf(java.math.BigInteger.class))));
// Timer is referenced twice but should obviously only be imported once.
TypeSimplifier typeSimplifier = new TypeSimplifier(typeUtils, "foo.bar", types, baseWithoutContainedTypes());
assertThat(typeSimplifier.typesToImport()).containsExactly("java.math.BigInteger", "java.util.List", "java.util.Map", "java.util.Timer", "java.util.regex.Pattern").inOrder();
}
use of javax.lang.model.type.TypeMirror in project auto by google.
the class TypeSimplifierTest method testSimplifyComplicatedTypes.
@Test
public void testSimplifyComplicatedTypes() {
// This test constructs a set of types and feeds them to TypeSimplifier. Then it verifies that
// the resultant rewrites of those types are what we would expect.
TypeElement list = typeElementOf(java.util.List.class);
TypeElement map = typeElementOf(java.util.Map.class);
TypeMirror string = typeMirrorOf(java.lang.String.class);
TypeMirror integer = typeMirrorOf(java.lang.Integer.class);
TypeMirror pattern = typeMirrorOf(java.util.regex.Pattern.class);
TypeMirror timer = typeMirrorOf(java.util.Timer.class);
TypeMirror bigInteger = typeMirrorOf(java.math.BigInteger.class);
Set<TypeMirror> types = typeMirrorSet(typeUtils.getPrimitiveType(TypeKind.INT), typeUtils.getArrayType(typeUtils.getPrimitiveType(TypeKind.BYTE)), pattern, typeUtils.getArrayType(pattern), typeUtils.getArrayType(typeUtils.getArrayType(pattern)), typeUtils.getDeclaredType(list, typeUtils.getWildcardType(null, null)), typeUtils.getDeclaredType(list, timer), typeUtils.getDeclaredType(map, string, integer), typeUtils.getDeclaredType(map, typeUtils.getWildcardType(timer, null), typeUtils.getWildcardType(null, bigInteger)));
Set<String> expectedSimplifications = ImmutableSet.of("int", "byte[]", "Pattern", "Pattern[]", "Pattern[][]", "List<?>", "List<Timer>", "Map<String, Integer>", "Map<? extends Timer, ? super BigInteger>");
TypeSimplifier typeSimplifier = new TypeSimplifier(typeUtils, "foo.bar", types, baseWithoutContainedTypes());
Set<String> actualSimplifications = new HashSet<String>();
for (TypeMirror type : types) {
actualSimplifications.add(typeSimplifier.simplify(type));
}
assertThat(actualSimplifications).isEqualTo(expectedSimplifications);
}
use of javax.lang.model.type.TypeMirror in project auto by google.
the class TypeSimplifierTest method testSimplifyAmbiguousNames.
@Test
public void testSimplifyAmbiguousNames() {
TypeMirror javaAwtList = typeMirrorOf(java.awt.List.class);
TypeMirror javaUtilList = typeMirrorOf(java.util.List.class);
Set<TypeMirror> types = typeMirrorSet(javaAwtList, javaUtilList);
TypeSimplifier typeSimplifier = new TypeSimplifier(typeUtils, "foo.bar", types, baseWithoutContainedTypes());
assertThat(typeSimplifier.simplify(javaAwtList)).isEqualTo(javaAwtList.toString());
assertThat(typeSimplifier.simplify(javaUtilList)).isEqualTo(javaUtilList.toString());
}
Aggregations