Search in sources :

Example 1 with NoType

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

the class TypeMirrorWrapperTest method unsupportedTypeMirrors.

@DataPoints("unsupportedTypeMirrors")
public static TypeMirror[] unsupportedTypeMirrors() {
    Types types = compilation.getTypes();
    NullType nullType = types.getNullType();
    NoType noneType = types.getNoType(TypeKind.NONE);
    return new TypeMirror[] { nullType, noneType };
}
Also used : Types(javax.lang.model.util.Types) NoType(javax.lang.model.type.NoType) TypeMirror(javax.lang.model.type.TypeMirror) NullType(javax.lang.model.type.NullType) FromDataPoints(org.junit.experimental.theories.FromDataPoints) DataPoints(org.junit.experimental.theories.DataPoints)

Example 2 with NoType

use of javax.lang.model.type.NoType in project querydsl by querydsl.

the class AbstractQuerydslProcessor method collectElements.

protected Set<TypeElement> collectElements() {
    // from delegate methods
    Set<TypeElement> elements = new HashSet<TypeElement>(processDelegateMethods());
    // from class annotations
    for (Class<? extends Annotation> annotation : conf.getEntityAnnotations()) {
        for (Element element : getElements(annotation)) {
            if (element instanceof TypeElement) {
                elements.add((TypeElement) element);
            }
        }
    }
    // from package annotations
    if (conf.getEntitiesAnnotation() != null) {
        for (Element element : getElements(conf.getEntitiesAnnotation())) {
            AnnotationMirror mirror = TypeUtils.getAnnotationMirrorOfType(element, conf.getEntitiesAnnotation());
            elements.addAll(TypeUtils.getAnnotationValuesAsElements(mirror, "value"));
        }
    }
    // from embedded annotations
    if (conf.getEmbeddedAnnotation() != null) {
        elements.addAll(getEmbeddedTypes());
    }
    // from embedded
    if (conf.isUnknownAsEmbedded()) {
        elements.addAll(getTypeFromProperties(elements));
    }
    // from annotation less supertypes
    if (!conf.isStrictMode()) {
        elements.addAll(getAnnotationlessSupertypes(elements));
    }
    // register possible embedded types of non-tracked supertypes
    if (conf.getEmbeddedAnnotation() != null) {
        Class<? extends Annotation> embedded = conf.getEmbeddedAnnotation();
        Set<TypeElement> embeddedElements = new HashSet<TypeElement>();
        for (TypeElement element : elements) {
            TypeMirror superTypeMirror = element.getSuperclass();
            while (superTypeMirror != null) {
                TypeElement superTypeElement = (TypeElement) processingEnv.getTypeUtils().asElement(superTypeMirror);
                if (superTypeElement != null) {
                    List<? extends Element> enclosed = superTypeElement.getEnclosedElements();
                    for (Element child : enclosed) {
                        if (child.getAnnotation(embedded) != null) {
                            handleEmbeddedType(child, embeddedElements);
                        }
                    }
                    superTypeMirror = superTypeElement.getSuperclass();
                    if (superTypeMirror instanceof NoType) {
                        superTypeMirror = null;
                    }
                } else {
                    superTypeMirror = null;
                }
            }
        }
        // register found elements
        for (TypeElement element : embeddedElements) {
            if (!elements.contains(element)) {
                elementHandler.handleEntityType(element);
            }
        }
    }
    return elements;
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) NoType(javax.lang.model.type.NoType)

Example 3 with NoType

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

the class TreeBackedTypeElementTest method testAsType.

@Test
public void testAsType() throws IOException {
    compile("class Foo { }");
    TypeElement fooElement = elements.getTypeElement("Foo");
    TypeMirror fooTypeMirror = fooElement.asType();
    assertEquals(TypeKind.DECLARED, fooTypeMirror.getKind());
    DeclaredType fooDeclaredType = (DeclaredType) fooTypeMirror;
    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 4 with NoType

use of javax.lang.model.type.NoType 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 5 with NoType

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

the class TypeMirrorWrapperTest method supportedTypeMirrors.

@DataPoints("supportedTypeMirrors")
public static TypeMirrorToWrapped[] supportedTypeMirrors() {
    Types types = compilation.getTypes();
    NoType voidType = types.getNoType(TypeKind.VOID);
    PrimitiveType primitiveType = types.getPrimitiveType(TypeKind.INT);
    Elements elements = compilation.getElements();
    DeclaredType declaredType = (DeclaredType) elements.getTypeElement(Object.class.getName()).asType();
    ArrayType arrayType = types.getArrayType(declaredType);
    return new TypeMirrorToWrapped[] { a(voidType).itsWrapped(WrappedVoidType.class), a(primitiveType).itsWrapped(WrappedPrimitiveType.class), a(declaredType).itsWrapped(WrappedDeclaredType.class), a(arrayType).itsWrapped(WrappedArrayType.class) };
}
Also used : ArrayType(javax.lang.model.type.ArrayType) Types(javax.lang.model.util.Types) NoType(javax.lang.model.type.NoType) PrimitiveType(javax.lang.model.type.PrimitiveType) Elements(javax.lang.model.util.Elements) DeclaredType(javax.lang.model.type.DeclaredType) FromDataPoints(org.junit.experimental.theories.FromDataPoints) DataPoints(org.junit.experimental.theories.DataPoints)

Aggregations

NoType (javax.lang.model.type.NoType)8 TypeMirror (javax.lang.model.type.TypeMirror)7 TypeElement (javax.lang.model.element.TypeElement)4 DeclaredType (javax.lang.model.type.DeclaredType)3 Types (javax.lang.model.util.Types)2 Test (org.junit.Test)2 DataPoints (org.junit.experimental.theories.DataPoints)2 FromDataPoints (org.junit.experimental.theories.FromDataPoints)2 HashSet (java.util.HashSet)1 Element (javax.lang.model.element.Element)1 ExecutableElement (javax.lang.model.element.ExecutableElement)1 VariableElement (javax.lang.model.element.VariableElement)1 ArrayType (javax.lang.model.type.ArrayType)1 NullType (javax.lang.model.type.NullType)1 PrimitiveType (javax.lang.model.type.PrimitiveType)1 Elements (javax.lang.model.util.Elements)1