Search in sources :

Example 91 with DeclaredType

use of javax.lang.model.type.DeclaredType 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());
}
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 92 with DeclaredType

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

the class TypeResolverTest method testTypeVariableResolves.

@Test
public void testTypeVariableResolves() throws IOException {
    compile("abstract class Foo<T extends java.lang.Runnable> extends java.util.ArrayList<T> { }");
    TypeElement fooElement = elements.getTypeElement("Foo");
    TypeElement listElement = elements.getTypeElement("java.util.ArrayList");
    TypeMirror tType = fooElement.getTypeParameters().get(0).asType();
    DeclaredType expectedSuperclass = types.getDeclaredType(listElement, tType);
    assertSameType(expectedSuperclass, fooElement.getSuperclass());
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) DeclaredType(javax.lang.model.type.DeclaredType) Test(org.junit.Test)

Example 93 with DeclaredType

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

the class TreeBackedTypesTest method testGetDeclaredTypeTopLevelNoGenerics.

@Test
public void testGetDeclaredTypeTopLevelNoGenerics() throws IOException {
    compile("class Foo { }");
    TypeElement fooElement = elements.getTypeElement("Foo");
    TypeMirror fooTypeMirror = types.getDeclaredType(fooElement);
    assertEquals(TypeKind.DECLARED, fooTypeMirror.getKind());
    DeclaredType fooDeclaredType = (DeclaredType) fooTypeMirror;
    assertNotSame(fooElement.asType(), fooDeclaredType);
    assertSame(fooElement, fooDeclaredType.asElement());
    assertEquals(0, fooDeclaredType.getTypeArguments().size());
    TypeMirror enclosingType = fooDeclaredType.getEnclosingType();
    assertEquals(TypeKind.NONE, enclosingType.getKind());
    assertTrue(enclosingType instanceof NoType);
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) NoType(javax.lang.model.type.NoType) TypeElement(javax.lang.model.element.TypeElement) DeclaredType(javax.lang.model.type.DeclaredType) Test(org.junit.Test)

Example 94 with DeclaredType

use of javax.lang.model.type.DeclaredType in project hibernate-orm by hibernate.

the class ClassWriter method findMappedSuperClass.

private static String findMappedSuperClass(MetaEntity entity, Context context) {
    TypeMirror superClass = entity.getTypeElement().getSuperclass();
    //superclass of Object is of NoType which returns some other kind
    while (superClass.getKind() == TypeKind.DECLARED) {
        //F..king Ch...t Have those people used their horrible APIs even once?
        final Element superClassElement = ((DeclaredType) superClass).asElement();
        String superClassName = ((TypeElement) superClassElement).getQualifiedName().toString();
        if (extendsSuperMetaModel(superClassElement, entity.isMetaComplete(), context)) {
            return superClassName;
        }
        superClass = ((TypeElement) superClassElement).getSuperclass();
    }
    return null;
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) DeclaredType(javax.lang.model.type.DeclaredType)

Example 95 with DeclaredType

use of javax.lang.model.type.DeclaredType in project j2objc by google.

the class SwitchRewriter method fixEnumValue.

private void fixEnumValue(SwitchStatement node) {
    Expression expr = node.getExpression();
    TypeMirror type = expr.getTypeMirror();
    if (!TypeUtil.isEnum(type)) {
        return;
    }
    DeclaredType enumType = typeUtil.getSuperclass(type);
    ExecutablePair ordinalMethod = typeUtil.findMethod(enumType, "ordinal");
    MethodInvocation invocation = new MethodInvocation(ordinalMethod, TreeUtil.remove(expr));
    node.setExpression(invocation);
}
Also used : Expression(com.google.devtools.j2objc.ast.Expression) NativeExpression(com.google.devtools.j2objc.ast.NativeExpression) TypeMirror(javax.lang.model.type.TypeMirror) ExecutablePair(com.google.devtools.j2objc.types.ExecutablePair) MethodInvocation(com.google.devtools.j2objc.ast.MethodInvocation) DeclaredType(javax.lang.model.type.DeclaredType)

Aggregations

DeclaredType (javax.lang.model.type.DeclaredType)138 TypeElement (javax.lang.model.element.TypeElement)82 TypeMirror (javax.lang.model.type.TypeMirror)75 ExecutableElement (javax.lang.model.element.ExecutableElement)38 Element (javax.lang.model.element.Element)28 VariableElement (javax.lang.model.element.VariableElement)26 AnnotationMirror (javax.lang.model.element.AnnotationMirror)19 Test (org.junit.Test)19 ArrayType (javax.lang.model.type.ArrayType)15 ArrayList (java.util.ArrayList)14 List (java.util.List)10 Map (java.util.Map)9 AbstractJClass (com.helger.jcodemodel.AbstractJClass)8 HashSet (java.util.HashSet)8 AnnotationValue (javax.lang.model.element.AnnotationValue)8 HashMap (java.util.HashMap)6 TypeParameterElement (javax.lang.model.element.TypeParameterElement)6 Types (javax.lang.model.util.Types)6 Name (javax.lang.model.element.Name)5 PackageElement (javax.lang.model.element.PackageElement)5