Search in sources :

Example 26 with VariableElement

use of javax.lang.model.element.VariableElement in project spring-boot by spring-projects.

the class ConfigurationMetadataAnnotationProcessor method processNestedType.

private void processNestedType(String prefix, TypeElement element, ExecutableElement source, String name, ExecutableElement getter, VariableElement field, TypeMirror returnType) {
    Element returnElement = this.processingEnv.getTypeUtils().asElement(returnType);
    boolean isNested = isNested(returnElement, field, element);
    AnnotationMirror annotation = getAnnotation(getter, configurationPropertiesAnnotation());
    if (returnElement != null && returnElement instanceof TypeElement && annotation == null && isNested) {
        String nestedPrefix = ConfigurationMetadata.nestedPrefix(prefix, name);
        this.metadataCollector.add(ItemMetadata.newGroup(nestedPrefix, this.typeUtils.getQualifiedName(returnElement), this.typeUtils.getQualifiedName(element), (getter == null ? null : getter.toString())));
        processTypeElement(nestedPrefix, (TypeElement) returnElement, source);
    }
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) TypeElement(javax.lang.model.element.TypeElement) VariableElement(javax.lang.model.element.VariableElement) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element)

Example 27 with VariableElement

use of javax.lang.model.element.VariableElement in project spring-boot by spring-projects.

the class ConfigurationMetadataAnnotationProcessor method processSimpleLombokTypes.

private void processSimpleLombokTypes(String prefix, TypeElement element, ExecutableElement source, TypeElementMembers members, Map<String, Object> fieldValues) {
    for (Map.Entry<String, VariableElement> entry : members.getFields().entrySet()) {
        String name = entry.getKey();
        VariableElement field = entry.getValue();
        if (!isLombokField(field, element)) {
            continue;
        }
        TypeMirror returnType = field.asType();
        Element returnTypeElement = this.processingEnv.getTypeUtils().asElement(returnType);
        boolean isExcluded = this.typeExcludeFilter.isExcluded(returnType);
        boolean isNested = isNested(returnTypeElement, field, element);
        boolean isCollection = this.typeUtils.isCollectionOrMap(returnType);
        boolean hasSetter = hasLombokSetter(field, element);
        if (!isExcluded && !isNested && (hasSetter || isCollection)) {
            String dataType = this.typeUtils.getType(returnType);
            String sourceType = this.typeUtils.getQualifiedName(element);
            String description = this.typeUtils.getJavaDoc(field);
            Object defaultValue = fieldValues.get(name);
            boolean deprecated = isDeprecated(field) || isDeprecated(source);
            this.metadataCollector.add(ItemMetadata.newProperty(prefix, name, dataType, sourceType, null, description, defaultValue, (deprecated ? new ItemDeprecation() : null)));
        }
    }
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) ItemDeprecation(org.springframework.boot.configurationprocessor.metadata.ItemDeprecation) VariableElement(javax.lang.model.element.VariableElement) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) VariableElement(javax.lang.model.element.VariableElement) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 28 with VariableElement

use of javax.lang.model.element.VariableElement in project spring-boot by spring-projects.

the class ConfigurationMetadataAnnotationProcessor method processNestedTypes.

private void processNestedTypes(String prefix, TypeElement element, ExecutableElement source, TypeElementMembers members) {
    for (Map.Entry<String, ExecutableElement> entry : members.getPublicGetters().entrySet()) {
        String name = entry.getKey();
        ExecutableElement getter = entry.getValue();
        VariableElement field = members.getFields().get(name);
        processNestedType(prefix, element, source, name, getter, field, getter.getReturnType());
    }
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement) VariableElement(javax.lang.model.element.VariableElement) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 29 with VariableElement

use of javax.lang.model.element.VariableElement in project spring-boot by spring-projects.

the class ConfigurationMetadataAnnotationProcessor method processSimpleTypes.

private void processSimpleTypes(String prefix, TypeElement element, ExecutableElement source, TypeElementMembers members, Map<String, Object> fieldValues) {
    for (Map.Entry<String, ExecutableElement> entry : members.getPublicGetters().entrySet()) {
        String name = entry.getKey();
        ExecutableElement getter = entry.getValue();
        TypeMirror returnType = getter.getReturnType();
        ExecutableElement setter = members.getPublicSetter(name, returnType);
        VariableElement field = members.getFields().get(name);
        Element returnTypeElement = this.processingEnv.getTypeUtils().asElement(returnType);
        boolean isExcluded = this.typeExcludeFilter.isExcluded(returnType);
        boolean isNested = isNested(returnTypeElement, field, element);
        boolean isCollection = this.typeUtils.isCollectionOrMap(returnType);
        if (!isExcluded && !isNested && (setter != null || isCollection)) {
            String dataType = this.typeUtils.getType(returnType);
            String sourceType = this.typeUtils.getQualifiedName(element);
            String description = this.typeUtils.getJavaDoc(field);
            Object defaultValue = fieldValues.get(name);
            boolean deprecated = isDeprecated(getter) || isDeprecated(setter) || isDeprecated(source);
            this.metadataCollector.add(ItemMetadata.newProperty(prefix, name, dataType, sourceType, null, description, defaultValue, (deprecated ? getItemDeprecation(getter) : null)));
        }
    }
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) ExecutableElement(javax.lang.model.element.ExecutableElement) VariableElement(javax.lang.model.element.VariableElement) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) VariableElement(javax.lang.model.element.VariableElement) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 30 with VariableElement

use of javax.lang.model.element.VariableElement in project androidannotations by androidannotations.

the class APTCodeModelHelper method getMethod.

private ExecutableElement getMethod(List<ExecutableElement> methods, String methodName, String returnType, String... parameterTypes) {
    for (ExecutableElement method : methods) {
        List<? extends VariableElement> parameters = method.getParameters();
        // Get the method return type or "VOID" if none.
        String methodReturnType = method.getReturnType().getKind() == TypeKind.VOID ? TypeKind.VOID.toString() : method.getReturnType().toString();
        if (parameters.size() == parameterTypes.length && methodReturnType.equals(returnType)) {
            if (methodName == null || method.getSimpleName().toString().equals(methodName)) {
                // At this point, method name, return type and number of
                // parameters are correct. Now we need to validate the
                // parameter types.
                boolean validMethod = true;
                for (int i = 0; i < parameters.size(); i++) {
                    VariableElement param = parameters.get(i);
                    if (!param.asType().toString().equals(parameterTypes[i])) {
                        // Parameter type does not match, this is not the
                        // correct method.
                        validMethod = false;
                        break;
                    }
                }
                if (validMethod) {
                    return method;
                }
            }
        }
    }
    return null;
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement) VariableElement(javax.lang.model.element.VariableElement)

Aggregations

VariableElement (javax.lang.model.element.VariableElement)248 ExecutableElement (javax.lang.model.element.ExecutableElement)75 TypeElement (javax.lang.model.element.TypeElement)75 TypeMirror (javax.lang.model.type.TypeMirror)72 GeneratedVariableElement (com.google.devtools.j2objc.types.GeneratedVariableElement)35 Element (javax.lang.model.element.Element)35 Expression (com.google.devtools.j2objc.ast.Expression)30 SimpleName (com.google.devtools.j2objc.ast.SimpleName)28 JVar (com.helger.jcodemodel.JVar)25 InfixExpression (com.google.devtools.j2objc.ast.InfixExpression)23 ArrayList (java.util.ArrayList)23 PostfixExpression (com.google.devtools.j2objc.ast.PostfixExpression)16 PrefixExpression (com.google.devtools.j2objc.ast.PrefixExpression)16 JInvocation (com.helger.jcodemodel.JInvocation)16 DeclaredType (javax.lang.model.type.DeclaredType)16 JBlock (com.helger.jcodemodel.JBlock)15 AbstractJClass (com.helger.jcodemodel.AbstractJClass)14 SingleVariableDeclaration (com.google.devtools.j2objc.ast.SingleVariableDeclaration)13 Elements (javax.lang.model.util.Elements)13 VariableDeclarationStatement (com.google.devtools.j2objc.ast.VariableDeclarationStatement)12