Search in sources :

Example 6 with DeclaredType

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

the class TreeBackedTypeElementTest method testGetSuperclassNoSuperclassIsObject.

@Test
public void testGetSuperclassNoSuperclassIsObject() throws IOException {
    compile("class Foo { }");
    TypeElement fooElement = elements.getTypeElement("Foo");
    DeclaredType superclass = (DeclaredType) fooElement.getSuperclass();
    TypeElement objectElement = elements.getTypeElement("java.lang.Object");
    assertSame(objectElement, superclass.asElement());
}
Also used : TypeElement(javax.lang.model.element.TypeElement) DeclaredType(javax.lang.model.type.DeclaredType) Test(org.junit.Test)

Example 7 with DeclaredType

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

the class TypeResolverTest method testParameterizedTypeResolves.

@Test
public void testParameterizedTypeResolves() throws IOException {
    compile(Joiner.on('\n').join("abstract class Foo extends java.util.ArrayList<java.lang.String> { }", "abstract class Bar extends java.util.ArrayList<java.lang.String> { }"));
    TypeElement listElement = elements.getTypeElement("java.util.ArrayList");
    TypeElement stringElement = elements.getTypeElement("java.lang.String");
    DeclaredType expectedSuperclass = types.getDeclaredType(listElement, stringElement.asType());
    TypeElement fooElement = elements.getTypeElement("Foo");
    TypeElement barElement = elements.getTypeElement("Bar");
    DeclaredType fooSuperclass = (DeclaredType) fooElement.getSuperclass();
    DeclaredType barSuperclass = (DeclaredType) barElement.getSuperclass();
    assertNotSame(expectedSuperclass, fooSuperclass);
    assertSameType(expectedSuperclass, fooSuperclass);
    assertSameType(fooSuperclass, barSuperclass);
}
Also used : TypeElement(javax.lang.model.element.TypeElement) DeclaredType(javax.lang.model.type.DeclaredType) Test(org.junit.Test)

Example 8 with DeclaredType

use of javax.lang.model.type.DeclaredType in project RoboBinding by RoboBinding.

the class WrappedTypeElement method firstTypeArgument.

public WrappedTypeElement firstTypeArgument() {
    List<? extends TypeMirror> typeArguments = type.getTypeArguments();
    DeclaredType firstTypeArgument = (DeclaredType) typeArguments.get(0);
    return typeElementOf(firstTypeArgument);
}
Also used : DeclaredType(javax.lang.model.type.DeclaredType) WrappedDeclaredType(org.robobinding.codegen.apt.type.WrappedDeclaredType)

Example 9 with DeclaredType

use of javax.lang.model.type.DeclaredType in project epoxy by airbnb.

the class HashCodeValidator method validateImplementsHashCode.

private void validateImplementsHashCode(TypeMirror mirror) throws EpoxyProcessorException {
    if (TypeName.get(mirror).isPrimitive()) {
        return;
    }
    if (mirror.getKind() == TypeKind.ARRAY) {
        validateArrayType((ArrayType) mirror);
        return;
    }
    if (!(mirror instanceof DeclaredType)) {
        return;
    }
    DeclaredType declaredType = (DeclaredType) mirror;
    Element element = typeUtils.asElement(mirror);
    TypeElement clazz = (TypeElement) element;
    if (isIterableType(clazz)) {
        validateIterableType(declaredType);
        return;
    }
    if (isAutoValueType(element)) {
        return;
    }
    if (isWhiteListedType(element)) {
        return;
    }
    if (!hasHashCodeInClassHierarchy(clazz)) {
        throwError("Attribute does not implement hashCode");
    }
}
Also used : TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) DeclaredType(javax.lang.model.type.DeclaredType)

Example 10 with DeclaredType

use of javax.lang.model.type.DeclaredType in project epoxy by airbnb.

the class ProcessorUtils method getEpoxyObjectType.

/**
   * Returns the type of the Epoxy model.
   * <p>
   * Eg for "class MyModel extends EpoxyModel<TextView>" it would return TextView.
   */
static TypeMirror getEpoxyObjectType(TypeElement clazz, Types typeUtils) {
    if (clazz.asType().getKind() != TypeKind.DECLARED) {
        return null;
    }
    DeclaredType superclass = (DeclaredType) clazz.getSuperclass();
    List<? extends TypeMirror> superTypeArguments = superclass.getTypeArguments();
    if (superTypeArguments.isEmpty()) {
        return getEpoxyObjectType((TypeElement) typeUtils.asElement(superclass), typeUtils);
    }
    // should be rare, but it would be nice to handle.
    return superTypeArguments.get(0);
}
Also used : DeclaredType(javax.lang.model.type.DeclaredType)

Aggregations

DeclaredType (javax.lang.model.type.DeclaredType)136 TypeElement (javax.lang.model.element.TypeElement)81 TypeMirror (javax.lang.model.type.TypeMirror)74 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 ArrayList (java.util.ArrayList)14 ArrayType (javax.lang.model.type.ArrayType)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 Types (javax.lang.model.util.Types)6 Name (javax.lang.model.element.Name)5 PackageElement (javax.lang.model.element.PackageElement)5 TypeParameterElement (javax.lang.model.element.TypeParameterElement)5