Search in sources :

Example 96 with TypeElement

use of javax.lang.model.element.TypeElement in project auto by google.

the class GwtCompatibility method gwtCompatibleAnnotationString.

String gwtCompatibleAnnotationString() {
    if (gwtCompatibleAnnotation.isPresent()) {
        AnnotationMirror annotation = gwtCompatibleAnnotation.get();
        TypeElement annotationElement = (TypeElement) annotation.getAnnotationType().asElement();
        String annotationArguments;
        if (annotation.getElementValues().isEmpty()) {
            annotationArguments = "";
        } else {
            List<String> elements = Lists.newArrayList();
            for (Map.Entry<ExecutableElement, AnnotationValue> entry : getElementValues(annotation).entrySet()) {
                elements.add(entry.getKey().getSimpleName() + " = " + entry.getValue());
            }
            annotationArguments = "(" + Joiner.on(", ").join(elements) + ")";
        }
        return "@" + annotationElement.getQualifiedName() + annotationArguments;
    } else {
        return "";
    }
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) AnnotationValue(javax.lang.model.element.AnnotationValue) Map(java.util.Map)

Example 97 with TypeElement

use of javax.lang.model.element.TypeElement in project squidb by yahoo.

the class ConstantCopyingPlugin method afterProcessVariableElements.

@Override
public void afterProcessVariableElements() {
    // Look for additional constants in @Constant annotated inner classes
    List<? extends Element> elements = modelSpec.getModelSpecElement().getEnclosedElements();
    for (Element element : elements) {
        if (element instanceof TypeElement && element.getAnnotation(Constants.class) != null) {
            if (!element.getModifiers().containsAll(Arrays.asList(Modifier.PUBLIC, Modifier.STATIC))) {
                utils.getMessager().printMessage(Diagnostic.Kind.WARNING, "@Constants annotated class is not " + "public static, will be ignored", element);
                continue;
            }
            TypeElement constantClass = (TypeElement) element;
            List<VariableElement> constantList = new ArrayList<>();
            innerClassConstants.put(constantClass.getSimpleName().toString(), constantList);
            for (Element e : constantClass.getEnclosedElements()) {
                if (e instanceof VariableElement && e.getAnnotation(Ignore.class) == null) {
                    TypeName typeName = utils.getTypeNameFromTypeMirror(e.asType());
                    if (!(typeName instanceof DeclaredTypeName)) {
                        utils.getMessager().printMessage(Diagnostic.Kind.WARNING, "Element type " + typeName + " is not a concrete type, will be ignored", e);
                    } else {
                        processVariableElement((VariableElement) e, constantList);
                    }
                }
            }
        }
    }
}
Also used : DeclaredTypeName(com.yahoo.aptutils.model.DeclaredTypeName) TypeName(com.yahoo.aptutils.model.TypeName) DeclaredTypeName(com.yahoo.aptutils.model.DeclaredTypeName) TypeElement(javax.lang.model.element.TypeElement) VariableElement(javax.lang.model.element.VariableElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) ArrayList(java.util.ArrayList) VariableElement(javax.lang.model.element.VariableElement)

Example 98 with TypeElement

use of javax.lang.model.element.TypeElement in project squidb by yahoo.

the class ImplementsPlugin method parseInterfaces.

private void parseInterfaces() {
    TypeElement modelSpecElement = modelSpec.getModelSpecElement();
    if (modelSpecElement.getAnnotation(Implements.class) != null) {
        List<DeclaredTypeName> typeNames = utils.getTypeNamesFromAnnotationValue(utils.getAnnotationValue(modelSpecElement, Implements.class, "interfaceClasses"));
        if (!AptUtils.isEmpty(typeNames)) {
            interfaces.addAll(typeNames);
        }
        AnnotationValue value = utils.getAnnotationValue(modelSpecElement, Implements.class, "interfaceDefinitions");
        List<AnnotationMirror> interfaceSpecs = utils.getValuesFromAnnotationValue(value, AnnotationMirror.class);
        for (AnnotationMirror spec : interfaceSpecs) {
            AnnotationValue interfaceClassValue = utils.getAnnotationValueFromMirror(spec, "interfaceClass");
            List<DeclaredTypeName> interfaceClassList = utils.getTypeNamesFromAnnotationValue(interfaceClassValue);
            if (!AptUtils.isEmpty(interfaceClassList)) {
                DeclaredTypeName interfaceClass = interfaceClassList.get(0);
                AnnotationValue interfaceTypeArgsValue = utils.getAnnotationValueFromMirror(spec, "interfaceTypeArgs");
                List<DeclaredTypeName> typeArgs = utils.getTypeNamesFromAnnotationValue(interfaceTypeArgsValue);
                if (AptUtils.isEmpty(typeArgs)) {
                    List<String> typeArgNames = utils.getValuesFromAnnotationValue(utils.getAnnotationValueFromMirror(spec, "interfaceTypeArgNames"), String.class);
                    for (String typeArgName : typeArgNames) {
                        typeArgs.add(new DeclaredTypeName(typeArgName));
                    }
                }
                interfaceClass.setTypeArgs(typeArgs);
                interfaces.add(interfaceClass);
            }
        }
    }
}
Also used : DeclaredTypeName(com.yahoo.aptutils.model.DeclaredTypeName) AnnotationMirror(javax.lang.model.element.AnnotationMirror) Implements(com.yahoo.squidb.annotations.Implements) TypeElement(javax.lang.model.element.TypeElement) AnnotationValue(javax.lang.model.element.AnnotationValue)

Example 99 with TypeElement

use of javax.lang.model.element.TypeElement in project j2objc by google.

the class JdtTypes method resolvePrimitiveType.

private void resolvePrimitiveType(AST ast, TypeKind kind, String pName, String cName) {
    PrimitiveType primitiveType = (PrimitiveType) BindingConverter.getType(ast.resolveWellKnownType(pName));
    TypeElement classElement = BindingConverter.getTypeElement(ast.resolveWellKnownType(cName));
    primitiveTypes.put(kind, primitiveType);
    boxedClasses.put(kind, classElement);
    unboxedTypes.put(classElement, primitiveType);
}
Also used : TypeElement(javax.lang.model.element.TypeElement) PrimitiveType(javax.lang.model.type.PrimitiveType)

Example 100 with TypeElement

use of javax.lang.model.element.TypeElement in project j2objc by google.

the class TreeConverter method addImplicitSuperCall.

private static void addImplicitSuperCall(MethodDeclaration node) {
    ExecutableElement method = node.getExecutableElement();
    DeclaredType superType = (DeclaredType) ElementUtil.getDeclaringClass(method).getSuperclass();
    TypeElement superClass = TypeUtil.asTypeElement(superType);
    ExecutableElement superConstructor = findDefaultConstructorElement(superClass);
    SuperConstructorInvocation invocation = new SuperConstructorInvocation(new ExecutablePair(superConstructor, (ExecutableType) JdtTypes.asMemberOfInternal(superType, superConstructor))).setVarargsType(getVarargsType(BindingConverter.unwrapExecutableElement(superConstructor), Collections.emptyList()));
    node.getBody().addStatement(0, invocation);
}
Also used : ExecutablePair(com.google.devtools.j2objc.types.ExecutablePair) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) SuperConstructorInvocation(com.google.devtools.j2objc.ast.SuperConstructorInvocation) 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