Search in sources :

Example 51 with TypeMirror

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();
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) Test(org.junit.Test)

Example 52 with TypeMirror

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();
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) Test(org.junit.Test)

Example 53 with TypeMirror

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();
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) Test(org.junit.Test)

Example 54 with TypeMirror

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);
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 55 with TypeMirror

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());
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) Test(org.junit.Test)

Aggregations

TypeMirror (javax.lang.model.type.TypeMirror)1086 TypeElement (javax.lang.model.element.TypeElement)419 ExecutableElement (javax.lang.model.element.ExecutableElement)259 VariableElement (javax.lang.model.element.VariableElement)237 Element (javax.lang.model.element.Element)196 DeclaredType (javax.lang.model.type.DeclaredType)177 ArrayList (java.util.ArrayList)154 Test (org.junit.Test)152 AnnotationMirror (javax.lang.model.element.AnnotationMirror)75 Types (javax.lang.model.util.Types)70 List (java.util.List)66 Elements (javax.lang.model.util.Elements)60 HashSet (java.util.HashSet)53 ArrayCodeTypeMirror (com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror)50 Map (java.util.Map)49 ExecutableType (javax.lang.model.type.ExecutableType)45 MethodSpec (com.squareup.javapoet.MethodSpec)44 PackageElement (javax.lang.model.element.PackageElement)41 ArrayType (javax.lang.model.type.ArrayType)41 Expression (com.google.devtools.j2objc.ast.Expression)39