Search in sources :

Example 6 with TypeMirror

use of javax.lang.model.type.TypeMirror in project buck by facebook.

the class TypeResolverTest method testMultiDimArrayTypeResolves.

@Test
public void testMultiDimArrayTypeResolves() 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);
    ArrayType stringArrayArrayType = types.getArrayType(stringArrayType);
    DeclaredType expectedSuperclass = types.getDeclaredType(listElement, stringArrayArrayType);
    assertSameType(expectedSuperclass, fooElement.getSuperclass());
}
Also used : ArrayType(javax.lang.model.type.ArrayType) TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) DeclaredType(javax.lang.model.type.DeclaredType) Test(org.junit.Test)

Example 7 with TypeMirror

use of javax.lang.model.type.TypeMirror in project buck by facebook.

the class TreeBackedTypeParameterElementTest method testTypeParameterBoundedTypeParameter.

@Test
public void testTypeParameterBoundedTypeParameter() throws IOException {
    compile("class Foo<T, U extends T> { }");
    TypeElement fooElement = elements.getTypeElement("Foo");
    TypeParameterElement uElement = fooElement.getTypeParameters().get(1);
    TypeMirror tType = fooElement.getTypeParameters().get(0).asType();
    assertSameType(tType, uElement.getBounds().get(0));
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) TypeParameterElement(javax.lang.model.element.TypeParameterElement) Test(org.junit.Test)

Example 8 with TypeMirror

use of javax.lang.model.type.TypeMirror in project buck by facebook.

the class TreeBackedTypesTest method testIsNotSameTypeStaticNoGenerics.

@Test
public void testIsNotSameTypeStaticNoGenerics() throws IOException {
    compile(ImmutableMap.of("Foo.java", "class Foo { }", "Bar.java", "class Bar { }"));
    TypeMirror fooType = elements.getTypeElement("Foo").asType();
    TypeMirror barType = elements.getTypeElement("Bar").asType();
    assertNotSameType(fooType, barType);
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) Test(org.junit.Test)

Example 9 with TypeMirror

use of javax.lang.model.type.TypeMirror in project buck by facebook.

the class TreeBackedTypesTest method testIsNotSameTypeParameterizedType.

@Test
public void testIsNotSameTypeParameterizedType() throws IOException {
    initCompiler();
    TypeElement listElement = elements.getTypeElement("java.util.List");
    TypeMirror stringType = elements.getTypeElement("java.lang.String").asType();
    TypeMirror integerType = elements.getTypeElement("java.lang.Integer").asType();
    TypeMirror listStringType = types.getDeclaredType(listElement, stringType);
    TypeMirror listIntType = types.getDeclaredType(listElement, integerType);
    assertNotSameType(listStringType, listIntType);
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) Test(org.junit.Test)

Example 10 with TypeMirror

use of javax.lang.model.type.TypeMirror in project buck by facebook.

the class TreeBackedTypesTest method testIsSameTypeUnboundedTypeVariable.

@Test
public void testIsSameTypeUnboundedTypeVariable() throws IOException {
    compile("class Foo<T> extends java.util.ArrayList<T> { }");
    TypeElement fooElement = elements.getTypeElement("Foo");
    TypeMirror t1 = fooElement.getTypeParameters().get(0).asType();
    TypeMirror t2 = ((DeclaredType) fooElement.getSuperclass()).getTypeArguments().get(0);
    assertSameType(t1, t2);
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) Test(org.junit.Test)

Aggregations

TypeMirror (javax.lang.model.type.TypeMirror)475 TypeElement (javax.lang.model.element.TypeElement)197 ExecutableElement (javax.lang.model.element.ExecutableElement)105 Test (org.junit.Test)90 VariableElement (javax.lang.model.element.VariableElement)88 DeclaredType (javax.lang.model.type.DeclaredType)76 Element (javax.lang.model.element.Element)61 ArrayList (java.util.ArrayList)36 Expression (com.google.devtools.j2objc.ast.Expression)32 PrefixExpression (com.google.devtools.j2objc.ast.PrefixExpression)28 Elements (javax.lang.model.util.Elements)28 FunctionInvocation (com.google.devtools.j2objc.ast.FunctionInvocation)24 AbstractJClass (com.helger.jcodemodel.AbstractJClass)24 List (java.util.List)23 Types (javax.lang.model.util.Types)22 InfixExpression (com.google.devtools.j2objc.ast.InfixExpression)21 TypeParameterElement (javax.lang.model.element.TypeParameterElement)21 ArrayType (javax.lang.model.type.ArrayType)21 FunctionElement (com.google.devtools.j2objc.types.FunctionElement)20 IJExpression (com.helger.jcodemodel.IJExpression)20