Search in sources :

Example 1 with Type

use of org.mapstruct.ap.internal.model.common.Type in project mapstruct by mapstruct.

the class MappingMethod method getImportTypes.

@Override
public Set<Type> getImportTypes() {
    Set<Type> types = new HashSet<>();
    for (Parameter param : parameters) {
        types.addAll(param.getType().getImportTypes());
    }
    types.addAll(getReturnType().getImportTypes());
    for (Type type : thrownTypes) {
        types.addAll(type.getImportTypes());
    }
    return types;
}
Also used : Type(org.mapstruct.ap.internal.model.common.Type) Parameter(org.mapstruct.ap.internal.model.common.Parameter) HashSet(java.util.HashSet)

Example 2 with Type

use of org.mapstruct.ap.internal.model.common.Type in project mapstruct by mapstruct.

the class PresenceCheckMethodResolver method findMatchingPresenceCheckMethod.

private static SelectedMethod<SourceMethod> findMatchingPresenceCheckMethod(Method method, SelectionParameters selectionParameters, MappingBuilderContext ctx) {
    MethodSelectors selectors = new MethodSelectors(ctx.getTypeUtils(), ctx.getElementUtils(), ctx.getTypeFactory(), ctx.getMessager());
    Type booleanType = ctx.getTypeFactory().getType(Boolean.class);
    List<SelectedMethod<SourceMethod>> matchingMethods = selectors.getMatchingMethods(method, getAllAvailableMethods(method, ctx.getSourceModel()), Collections.emptyList(), booleanType, booleanType, SelectionCriteria.forPresenceCheckMethods(selectionParameters));
    if (matchingMethods.isEmpty()) {
        return null;
    }
    if (matchingMethods.size() > 1) {
        ctx.getMessager().printMessage(method.getExecutable(), Message.GENERAL_AMBIGUOUS_PRESENCE_CHECK_METHOD, selectionParameters.getSourceRHS().getSourceType().describe(), matchingMethods.stream().map(SelectedMethod::getMethod).map(Method::describe).collect(Collectors.joining(", ")));
        return null;
    }
    return matchingMethods.get(0);
}
Also used : Type(org.mapstruct.ap.internal.model.common.Type) SelectedMethod(org.mapstruct.ap.internal.model.source.selector.SelectedMethod) SelectedMethod(org.mapstruct.ap.internal.model.source.selector.SelectedMethod) SourceMethod(org.mapstruct.ap.internal.model.source.SourceMethod) Method(org.mapstruct.ap.internal.model.source.Method) MethodSelectors(org.mapstruct.ap.internal.model.source.selector.MethodSelectors)

Example 3 with Type

use of org.mapstruct.ap.internal.model.common.Type in project mapstruct by mapstruct.

the class AdderWrapper method getThrownTypes.

@Override
public List<Type> getThrownTypes() {
    List<Type> parentThrownTypes = super.getThrownTypes();
    List<Type> result = new ArrayList<>(parentThrownTypes);
    for (Type thrownTypeToExclude : thrownTypesToExclude) {
        for (Type parentExceptionType : parentThrownTypes) {
            if (parentExceptionType.isAssignableTo(thrownTypeToExclude)) {
                result.remove(parentExceptionType);
            }
        }
    }
    return result;
}
Also used : Type(org.mapstruct.ap.internal.model.common.Type) ArrayList(java.util.ArrayList)

Example 4 with Type

use of org.mapstruct.ap.internal.model.common.Type in project mapstruct by mapstruct.

the class AbstractMappingMethodBuilder method getName.

private String getName(Type type) {
    StringBuilder builder = new StringBuilder();
    for (Type typeParam : type.getTypeParameters()) {
        builder.append(typeParam.getIdentification());
    }
    builder.append(type.getIdentification());
    return builder.toString();
}
Also used : Type(org.mapstruct.ap.internal.model.common.Type)

Example 5 with Type

use of org.mapstruct.ap.internal.model.common.Type in project mapstruct by mapstruct.

the class MapperCreationProcessor method getExtraImports.

private SortedSet<Type> getExtraImports(TypeElement element, MapperOptions mapperOptions) {
    SortedSet<Type> extraImports = new TreeSet<>();
    for (TypeMirror extraImport : mapperOptions.imports()) {
        Type type = typeFactory.getType(extraImport);
        extraImports.add(type);
    }
    // Add original package if a dest package has been set
    if (!"default".equals(mapperOptions.implementationPackage())) {
        extraImports.add(typeFactory.getType(element));
    }
    return extraImports;
}
Also used : Type(org.mapstruct.ap.internal.model.common.Type) TypeMirror(javax.lang.model.type.TypeMirror) TreeSet(java.util.TreeSet)

Aggregations

Type (org.mapstruct.ap.internal.model.common.Type)36 ArrayList (java.util.ArrayList)13 Parameter (org.mapstruct.ap.internal.model.common.Parameter)11 DeclaredType (javax.lang.model.type.DeclaredType)10 ExecutableType (javax.lang.model.type.ExecutableType)6 SourceMethod (org.mapstruct.ap.internal.model.source.SourceMethod)6 HashSet (java.util.HashSet)5 TypeMirror (javax.lang.model.type.TypeMirror)4 TreeSet (java.util.TreeSet)3 BeanMappingMethod (org.mapstruct.ap.internal.model.BeanMappingMethod)3 ContainerMappingMethod (org.mapstruct.ap.internal.model.ContainerMappingMethod)3 IterableMappingMethod (org.mapstruct.ap.internal.model.IterableMappingMethod)3 MapMappingMethod (org.mapstruct.ap.internal.model.MapMappingMethod)3 MappingMethod (org.mapstruct.ap.internal.model.MappingMethod)3 StreamMappingMethod (org.mapstruct.ap.internal.model.StreamMappingMethod)3 ValueMappingMethod (org.mapstruct.ap.internal.model.ValueMappingMethod)3 Map (java.util.Map)2 ExecutableElement (javax.lang.model.element.ExecutableElement)2 TypeElement (javax.lang.model.element.TypeElement)2 ArrayType (javax.lang.model.type.ArrayType)2