Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ private SubclassMapping createSubclassMapping(SubclassMappingOptions subclassMap
FormattingParameters.EMPTY,
criteria,
rightHandSide,
null,
subclassMappingOptions.getMirror(),
() -> forgeSubclassMapping(
rightHandSide,
sourceType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.type.TypeMirror;

Expand All @@ -34,14 +37,16 @@ public class SubclassMappingOptions extends DelegatingOptions {
private final TypeMirror target;
private final TypeUtils typeUtils;
private final SelectionParameters selectionParameters;
private final SubclassMappingGem subclassMapping;

public SubclassMappingOptions(TypeMirror source, TypeMirror target, TypeUtils typeUtils, DelegatingOptions next,
SelectionParameters selectionParameters) {
SelectionParameters selectionParameters, SubclassMappingGem subclassMapping) {
super( next );
this.source = source;
this.target = target;
this.typeUtils = typeUtils;
this.selectionParameters = selectionParameters;
this.subclassMapping = subclassMapping;
}

@Override
Expand Down Expand Up @@ -124,14 +129,18 @@ public SelectionParameters getSelectionParameters() {
return selectionParameters;
}

public AnnotationMirror getMirror() {
return Optional.ofNullable( subclassMapping ).map( SubclassMappingGem::mirror ).orElse( null );
}

public static void addInstances(SubclassMappingsGem gem, ExecutableElement method,
BeanMappingOptions beanMappingOptions, FormattingMessager messager,
TypeUtils typeUtils, Set<SubclassMappingOptions> mappings,
List<Parameter> sourceParameters, Type resultType,
SubclassValidator subclassValidator) {
for ( SubclassMappingGem subclassMappingGem : gem.value().get() ) {
for ( SubclassMappingGem subclassMapping : gem.value().get() ) {
addInstance(
subclassMappingGem,
subclassMapping,
method,
beanMappingOptions,
messager,
Expand Down Expand Up @@ -175,25 +184,22 @@ public static void addInstance(SubclassMappingGem subclassMapping, ExecutableEle
targetSubclass,
typeUtils,
beanMappingOptions,
selectionParameters
selectionParameters,
subclassMapping
) );
}

public static List<SubclassMappingOptions> copyForInverseInheritance(Set<SubclassMappingOptions> subclassMappings,
public static List<SubclassMappingOptions> copyForInverseInheritance(Set<SubclassMappingOptions> mappings,
BeanMappingOptions beanMappingOptions) {
// we are not interested in keeping it unique at this point.
List<SubclassMappingOptions> mappings = new ArrayList<>();
for ( SubclassMappingOptions subclassMapping : subclassMappings ) {
mappings.add(
new SubclassMappingOptions(
subclassMapping.target,
subclassMapping.source,
subclassMapping.typeUtils,
beanMappingOptions,
subclassMapping.selectionParameters
) );
}
return mappings;
return mappings.stream().map( mapping -> new SubclassMappingOptions(
mapping.target,
mapping.source,
mapping.typeUtils,
beanMappingOptions,
mapping.selectionParameters,
mapping.subclassMapping
) ).collect( Collectors.toCollection( ArrayList::new ) );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
@Mapper(uses = { RossiniMapper.class, VivaldiMapper.class })
public interface ErroneousSubclassQualifiedByMapper {
@SubclassMapping(source = Rossini.class, target = RossiniDto.class, qualifiedBy = NonExistent.class)
@SubclassMapping(source = Vivaldi.class, target = VivaldiDto.class)
ComposerDto toDto(Composer composer);
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ void subclassQualifiedByNameDoesNotContainUnused() {
diagnostics = @Diagnostic(
type = ErroneousSubclassQualifiedByMapper.class,
kind = javax.tools.Diagnostic.Kind.ERROR,
line = 15,
line = 13,
message = "Qualifier error. No method found annotated with: [ @NonExistent ]. " +
"See https://mapstruct.org/faq/#qualifier for more info."
)
Expand All @@ -245,7 +245,8 @@ void subclassQualifiedByErroneous() {
diagnostics = @Diagnostic(
type = ErroneousSubclassQualifiedByNameMapper.class,
kind = javax.tools.Diagnostic.Kind.ERROR,
line = 15,
line = 13,
alternativeLine = 15,
message = "Qualifier error. No method found annotated with @Named#value: [ non-existent ]. " +
"See https://mapstruct.org/faq/#qualifier for more info."
)
Expand Down