Search in sources :

Example 11 with Type

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

the class MappingMethodOptions method applyIgnoreAll.

public void applyIgnoreAll(SourceMethod method, TypeFactory typeFactory, FormattingMessager messager) {
    CollectionMappingStrategyGem cms = method.getOptions().getMapper().getCollectionMappingStrategy();
    Type writeType = method.getResultType();
    if (!method.isUpdateMethod()) {
        writeType = typeFactory.effectiveResultTypeFor(writeType, method.getOptions().getBeanMapping().getBuilder());
    }
    Map<String, Accessor> writeAccessors = writeType.getPropertyWriteAccessors(cms);
    for (MappingOptions mapping : mappings) {
        String mappedTargetProperty = getFirstTargetPropertyName(mapping);
        if (!".".equals(mappedTargetProperty)) {
            // Remove the mapped target property from the write accessors
            writeAccessors.remove(mappedTargetProperty);
        } else {
            messager.printMessage(method.getExecutable(), getBeanMapping().getMirror(), Message.BEANMAPPING_IGNORE_BY_DEFAULT_WITH_MAPPING_TARGET_THIS);
            // Nothing more to do if this is reached
            return;
        }
    }
    // The writeAccessors now contains only the accessors that should be ignored
    for (String targetPropertyName : writeAccessors.keySet()) {
        MappingOptions mapping = MappingOptions.forIgnore(targetPropertyName);
        mappings.add(mapping);
    }
}
Also used : Type(org.mapstruct.ap.internal.model.common.Type) CollectionMappingStrategyGem(org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem) Accessor(org.mapstruct.ap.internal.util.accessor.Accessor)

Example 12 with Type

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

the class SourceReference method push.

public List<SourceReference> push(TypeFactory typeFactory, FormattingMessager messager, Method method) {
    List<SourceReference> result = new ArrayList<>();
    PropertyEntry deepestProperty = getDeepestProperty();
    if (deepestProperty != null) {
        Type type = deepestProperty.getType();
        Map<String, ReadAccessor> newDeepestReadAccessors = type.getPropertyReadAccessors();
        String parameterName = getParameter().getName();
        String deepestPropertyFullName = deepestProperty.getFullName();
        for (Map.Entry<String, ReadAccessor> newDeepestReadAccessorEntry : newDeepestReadAccessors.entrySet()) {
            // Always include the parameter name in the new full name.
            // Otherwise multi source parameters might be reported incorrectly
            String newFullName = parameterName + "." + deepestPropertyFullName + "." + newDeepestReadAccessorEntry.getKey();
            SourceReference sourceReference = new BuilderFromMapping().sourceName(newFullName).method(method).messager(messager).typeFactory(typeFactory).build();
            result.add(sourceReference);
        }
    }
    return result;
}
Also used : Type(org.mapstruct.ap.internal.model.common.Type) DeclaredType(javax.lang.model.type.DeclaredType) PropertyEntry.forSourceReference(org.mapstruct.ap.internal.model.beanmapping.PropertyEntry.forSourceReference) ReadAccessor(org.mapstruct.ap.internal.util.accessor.ReadAccessor) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 13 with Type

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

the class UpdateWrapper method getThrownTypes.

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

Example 14 with Type

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

the class LocalVarWrapper method getThrownTypes.

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

Example 15 with Type

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

the class WrapperForCollectionsAndMaps method getThrownTypes.

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

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