Search in sources :

Example 51 with TypeElement

use of javax.lang.model.element.TypeElement in project neo4j by neo4j.

the class ServiceProcessor method process.

@SuppressWarnings("unchecked")
@Override
protected void process(TypeElement annotationType, Element annotated, AnnotationMirror annotation, Map<? extends ExecutableElement, ? extends AnnotationValue> values) throws IOException {
    for (AnnotationValue o : (List<? extends AnnotationValue>) values.values().iterator().next().getValue()) {
        TypeMirror service = (TypeMirror) o.getValue();
        addTo(((TypeElement) annotated).getQualifiedName().toString(), "META-INF", "services", service.toString());
    }
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) AnnotationValue(javax.lang.model.element.AnnotationValue) List(java.util.List)

Example 52 with TypeElement

use of javax.lang.model.element.TypeElement in project OpenAM by OpenRock.

the class UpgradeStepProcessor method process.

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (!roundEnv.processingOver()) {
        Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(UpgradeStepInfo.class);
        for (Element element : elements) {
            Set<DependencyInfo> depends = new LinkedHashSet<DependencyInfo>(2);
            String annotatedType = element.asType().toString();
            UpgradeStepInfo annotation = element.getAnnotation(UpgradeStepInfo.class);
            for (String name : annotation.dependsOn()) {
                DependencyInfo depInfo = stepMappings.get(name);
                if (depInfo == null) {
                    depInfo = new DependencyInfo(name);
                    stepMappings.put(name, depInfo);
                }
                depends.add(depInfo);
            }
            DependencyInfo depInfo = stepMappings.get(annotatedType);
            if (depInfo == null) {
                depInfo = new DependencyInfo(annotatedType);
                stepMappings.put(annotatedType, depInfo);
            }
            for (DependencyInfo dep : depends) {
                depInfo.dependencies.add(dep);
            }
        }
        createDAG();
    }
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) UpgradeStepInfo(org.forgerock.openam.upgrade.UpgradeStepInfo)

Example 53 with TypeElement

use of javax.lang.model.element.TypeElement in project butterknife by JakeWharton.

the class ButterKnifeProcessor method parseRClass.

private void parseRClass(String respectivePackageName, String rClass) {
    Element element;
    try {
        element = elementUtils.getTypeElement(rClass);
    } catch (MirroredTypeException mte) {
        element = typeUtils.asElement(mte.getTypeMirror());
    }
    JCTree tree = (JCTree) trees.getTree(element);
    if (tree != null) {
        // tree can be null if the references are compiled types and not source
        IdScanner idScanner = new IdScanner(symbols, elementUtils.getPackageOf(element).getQualifiedName().toString(), respectivePackageName);
        tree.accept(idScanner);
    } else {
        parseCompiledR(respectivePackageName, (TypeElement) element);
    }
}
Also used : MirroredTypeException(javax.lang.model.type.MirroredTypeException) TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) VariableElement(javax.lang.model.element.VariableElement) ExecutableElement(javax.lang.model.element.ExecutableElement) JCTree(com.sun.tools.javac.tree.JCTree)

Example 54 with TypeElement

use of javax.lang.model.element.TypeElement in project ig-json-parser by Instagram.

the class JsonAnnotationProcessor method isFieldAnnotationValid.

private boolean isFieldAnnotationValid(Class<? extends Annotation> annotationClass, Element element) {
    TypeElement enclosingElement = (TypeElement) element.getEnclosingElement();
    // Verify containing type.
    if (enclosingElement.getKind() != CLASS) {
        error(enclosingElement, "@%s field may only be contained in classes. (%s.%s)", annotationClass.getSimpleName(), enclosingElement.getQualifiedName(), element.getSimpleName());
        return false;
    }
    Annotation annotation = enclosingElement.getAnnotation(JsonType.class);
    if (annotation == null) {
        error(enclosingElement, "@%s field may only be contained in classes annotated with @%s (%s.%s)", annotationClass.getSimpleName(), JsonType.class.toString(), enclosingElement.getQualifiedName(), element.getSimpleName());
        return false;
    }
    // Verify containing class visibility is not private.
    if (enclosingElement.getModifiers().contains(PRIVATE)) {
        error(enclosingElement, "@%s %s may not be contained in private classes. (%s.%s)", annotationClass.getSimpleName(), enclosingElement.getQualifiedName(), element.getSimpleName());
        return false;
    }
    return true;
}
Also used : JsonType(com.instagram.common.json.annotation.JsonType) TypeElement(javax.lang.model.element.TypeElement) Annotation(java.lang.annotation.Annotation)

Example 55 with TypeElement

use of javax.lang.model.element.TypeElement 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)

Aggregations

TypeElement (javax.lang.model.element.TypeElement)1562 ExecutableElement (javax.lang.model.element.ExecutableElement)517 Element (javax.lang.model.element.Element)502 TypeMirror (javax.lang.model.type.TypeMirror)420 VariableElement (javax.lang.model.element.VariableElement)333 DeclaredType (javax.lang.model.type.DeclaredType)201 ArrayList (java.util.ArrayList)177 PackageElement (javax.lang.model.element.PackageElement)159 AnnotationMirror (javax.lang.model.element.AnnotationMirror)151 Test (org.junit.Test)136 HashMap (java.util.HashMap)118 HashSet (java.util.HashSet)109 Elements (javax.lang.model.util.Elements)101 Map (java.util.Map)98 IOException (java.io.IOException)97 List (java.util.List)97 ClassName (com.squareup.javapoet.ClassName)88 Test (org.junit.jupiter.api.Test)80 MethodSpec (com.squareup.javapoet.MethodSpec)72 TypeSpec (com.squareup.javapoet.TypeSpec)63