Search in sources :

Example 61 with DeclaredType

use of javax.lang.model.type.DeclaredType in project ig-json-parser by Instagram.

the class TypeUtils method getParseType.

public ParseType getParseType(TypeMirror typeMirror, Class<? extends Annotation> typeAnnotationClass) {
    if (typeMirror == null) {
        return ParseType.UNSUPPORTED;
    } else if (JAVA_LANG_STRING.equals(typeMirror.toString())) {
        return ParseType.STRING;
    } else if (typeMirror.getKind() == TypeKind.BOOLEAN) {
        return ParseType.BOOLEAN;
    } else if (JAVA_LANG_BOOLEAN.equals(typeMirror.toString())) {
        return ParseType.BOOLEAN_OBJECT;
    } else if (typeMirror.getKind() == TypeKind.INT) {
        return ParseType.INTEGER;
    } else if (JAVA_LANG_INTEGER.equals(typeMirror.toString())) {
        return ParseType.INTEGER_OBJECT;
    } else if (typeMirror.getKind() == TypeKind.LONG) {
        return ParseType.LONG;
    } else if (JAVA_LANG_LONG.equals(typeMirror.toString())) {
        return ParseType.LONG_OBJECT;
    } else if (typeMirror.getKind() == TypeKind.FLOAT) {
        return ParseType.FLOAT;
    } else if (JAVA_LANG_FLOAT.equals(typeMirror.toString())) {
        return ParseType.FLOAT_OBJECT;
    } else if (typeMirror.getKind() == TypeKind.DOUBLE) {
        return ParseType.DOUBLE;
    } else if (JAVA_LANG_DOUBLE.equals(typeMirror.toString())) {
        return ParseType.DOUBLE_OBJECT;
    } else if (typeMirror instanceof DeclaredType) {
        DeclaredType type = (DeclaredType) typeMirror;
        Element element = type.asElement();
        Annotation annotation = element.getAnnotation(typeAnnotationClass);
        if (annotation != null) {
            return ParseType.PARSABLE_OBJECT;
        }
        // is it an enum?
        if (element instanceof TypeElement) {
            TypeElement typeElement = (TypeElement) element;
            TypeMirror superclass = typeElement.getSuperclass();
            if (superclass instanceof DeclaredType) {
                DeclaredType superclassDeclaredType = (DeclaredType) superclass;
                if (JAVA_LANG_ENUM.equals(getCanonicalTypeName(superclassDeclaredType))) {
                    return ParseType.ENUM_OBJECT;
                }
            }
        }
    }
    return ParseType.UNSUPPORTED;
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) TypeParameterElement(javax.lang.model.element.TypeParameterElement) Annotation(java.lang.annotation.Annotation) DeclaredType(javax.lang.model.type.DeclaredType)

Example 62 with DeclaredType

use of javax.lang.model.type.DeclaredType in project spring-framework by spring-projects.

the class TypeHelper method getType.

public String getType(TypeMirror type) {
    if (type == null) {
        return null;
    }
    if (type instanceof DeclaredType) {
        DeclaredType declaredType = (DeclaredType) type;
        Element enclosingElement = declaredType.asElement().getEnclosingElement();
        if (enclosingElement != null && enclosingElement instanceof TypeElement) {
            return getQualifiedName(enclosingElement) + "$" + declaredType.asElement().getSimpleName().toString();
        } else {
            return getQualifiedName(declaredType.asElement());
        }
    }
    return type.toString();
}
Also used : TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) DeclaredType(javax.lang.model.type.DeclaredType)

Example 63 with DeclaredType

use of javax.lang.model.type.DeclaredType in project ceylon-compiler by ceylon.

the class P method process.

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (!ran) {
        ran = true;
        ExecutableElement m = getFirstMethodIn("C");
        System.err.println("method: " + m);
        TypeMirror type = (DeclaredType) m.getParameters().get(0).asType();
        System.err.println("parameters[0]: " + type);
        if (!isParameterized(type))
            throw new AssertionError(type);
        type = ((ExecutableType) m.asType()).getParameterTypes().get(0);
        System.err.println("parameterTypes[0]: " + type);
        if (!isParameterized(type))
            throw new AssertionError(type);
        System.err.println();
    }
    return true;
}
Also used : ExecutableType(javax.lang.model.type.ExecutableType) TypeMirror(javax.lang.model.type.TypeMirror) ExecutableElement(javax.lang.model.element.ExecutableElement) DeclaredType(javax.lang.model.type.DeclaredType)

Example 64 with DeclaredType

use of javax.lang.model.type.DeclaredType in project ceylon-compiler by ceylon.

the class MyScanner method testParseType.

void testParseType(TypeElement clazz) {
    DeclaredType type = (DeclaredType) task.parseType("List<String>", clazz);
    for (Element member : elements.getAllMembers((TypeElement) type.asElement())) {
        TypeMirror mt = types.asMemberOf(type, member);
        System.out.format("%s : %s -> %s%n", member.getSimpleName(), member.asType(), mt);
        numParseTypeElements++;
    }
}
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 65 with DeclaredType

use of javax.lang.model.type.DeclaredType in project ceylon-compiler by ceylon.

the class TestResolveError method testParseType.

void testParseType(TypeElement clazz) {
    DeclaredType type = (DeclaredType) task.parseType("List<String>", clazz);
    for (Element member : elements.getAllMembers((TypeElement) type.asElement())) {
        TypeMirror mt = types.asMemberOf(type, member);
        System.out.format("%s : %s -> %s%n", member.getSimpleName(), member.asType(), mt);
    }
}
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)

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