Search in sources :

Example 81 with ExecutableType

use of javax.lang.model.type.ExecutableType in project mapstruct by mapstruct.

the class TypeFactory method getReturnType.

public Type getReturnType(DeclaredType includingType, Accessor accessor) {
    Type type;
    TypeMirror accessorType = getMethodType(includingType, accessor.getElement());
    if (isExecutableType(accessorType)) {
        type = getType(((ExecutableType) accessorType).getReturnType());
    } else {
        type = getType(accessorType);
    }
    return type;
}
Also used : ExecutableType(javax.lang.model.type.ExecutableType) WildcardType(javax.lang.model.type.WildcardType) ArrayType(javax.lang.model.type.ArrayType) DeclaredType(javax.lang.model.type.DeclaredType) ExecutableType(javax.lang.model.type.ExecutableType) PrimitiveType(javax.lang.model.type.PrimitiveType) TypeMirror(javax.lang.model.type.TypeMirror)

Example 82 with ExecutableType

use of javax.lang.model.type.ExecutableType in project mapstruct by mapstruct.

the class MethodRetrievalProcessor method retrievePrototypeMethods.

private List<SourceMethod> retrievePrototypeMethods(TypeElement mapperTypeElement, MapperOptions mapperAnnotation) {
    if (!mapperAnnotation.hasMapperConfig()) {
        return Collections.emptyList();
    }
    TypeElement typeElement = asTypeElement(mapperAnnotation.mapperConfigType());
    List<SourceMethod> methods = new ArrayList<>();
    for (ExecutableElement executable : elementUtils.getAllEnclosedExecutableElements(typeElement)) {
        ExecutableType methodType = typeFactory.getMethodType(mapperAnnotation.mapperConfigType(), executable);
        List<Parameter> parameters = typeFactory.getParameters(methodType, executable);
        boolean containsTargetTypeParameter = SourceMethod.containsTargetTypeParameter(parameters);
        // prototype methods don't have prototypes themselves
        List<SourceMethod> prototypeMethods = Collections.emptyList();
        SourceMethod method = getMethodRequiringImplementation(methodType, executable, parameters, containsTargetTypeParameter, mapperAnnotation, prototypeMethods, mapperTypeElement);
        if (method != null) {
            methods.add(method);
        }
    }
    return methods;
}
Also used : ExecutableType(javax.lang.model.type.ExecutableType) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) ArrayList(java.util.ArrayList) Parameter(org.mapstruct.ap.internal.model.common.Parameter) SourceMethod(org.mapstruct.ap.internal.model.source.SourceMethod)

Example 83 with ExecutableType

use of javax.lang.model.type.ExecutableType in project lombok by rzwitserloot.

the class HandleDelegate method addMethodBindings.

public void addMethodBindings(List<MethodSig> signatures, ClassType ct, JavacTypes types, Set<String> banList) throws DelegateRecursion {
    TypeSymbol tsym = ct.asElement();
    if (tsym == null)
        return;
    for (Symbol member : tsym.getEnclosedElements()) {
        for (Compound am : member.getAnnotationMirrors()) {
            String name = null;
            try {
                name = am.type.tsym.flatName().toString();
            } catch (Exception ignore) {
            }
            if ("lombok.Delegate".equals(name) || "lombok.experimental.Delegate".equals(name)) {
                throw new DelegateRecursion(ct.tsym.name.toString(), member.name.toString());
            }
        }
        if (member.getKind() != ElementKind.METHOD)
            continue;
        if (member.isStatic())
            continue;
        if (member.isConstructor())
            continue;
        ExecutableElement exElem = (ExecutableElement) member;
        if (!exElem.getModifiers().contains(Modifier.PUBLIC))
            continue;
        ExecutableType methodType = (ExecutableType) types.asMemberOf(ct, member);
        String sig = printSig(methodType, member.name, types);
        // If add returns false, it was already in there
        if (!banList.add(sig))
            continue;
        boolean isDeprecated = (member.flags() & DEPRECATED) != 0;
        signatures.add(new MethodSig(member.name, methodType, isDeprecated, exElem));
    }
    for (Type type : types.directSupertypes(ct)) {
        if (type instanceof ClassType) {
            addMethodBindings(signatures, (ClassType) type, types, banList);
        }
    }
}
Also used : ExecutableType(javax.lang.model.type.ExecutableType) ClassType(com.sun.tools.javac.code.Type.ClassType) Type(com.sun.tools.javac.code.Type) ExecutableType(javax.lang.model.type.ExecutableType) MethodSymbol(com.sun.tools.javac.code.Symbol.MethodSymbol) TypeSymbol(com.sun.tools.javac.code.Symbol.TypeSymbol) Symbol(com.sun.tools.javac.code.Symbol) ExecutableElement(javax.lang.model.element.ExecutableElement) TypeSymbol(com.sun.tools.javac.code.Symbol.TypeSymbol) Compound(com.sun.tools.javac.code.Attribute.Compound) ClassType(com.sun.tools.javac.code.Type.ClassType) TypeNotConvertibleException(lombok.javac.JavacResolution.TypeNotConvertibleException)

Aggregations

ExecutableType (javax.lang.model.type.ExecutableType)83 ExecutableElement (javax.lang.model.element.ExecutableElement)64 DeclaredType (javax.lang.model.type.DeclaredType)47 TypeMirror (javax.lang.model.type.TypeMirror)45 TypeElement (javax.lang.model.element.TypeElement)44 Element (javax.lang.model.element.Element)33 VariableElement (javax.lang.model.element.VariableElement)33 Nonnull (javax.annotation.Nonnull)22 ArrayList (java.util.ArrayList)18 MethodSpec (com.squareup.javapoet.MethodSpec)15 HashMap (java.util.HashMap)15 Map (java.util.Map)15 AnnotationMirror (javax.lang.model.element.AnnotationMirror)15 TypeSpec (com.squareup.javapoet.TypeSpec)14 HashSet (java.util.HashSet)14 TypeKind (javax.lang.model.type.TypeKind)14 IOException (java.io.IOException)13 Nullable (javax.annotation.Nullable)13 PackageElement (javax.lang.model.element.PackageElement)13 List (java.util.List)12