mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#1998 preparation move classes to new names 2
This commit is contained in:
parent
2b36c220a3
commit
b84526b24a
@ -36,7 +36,7 @@ import org.mapstruct.ap.internal.model.common.Type;
|
||||
import org.mapstruct.ap.internal.model.dependency.GraphAnalyzer;
|
||||
import org.mapstruct.ap.internal.model.dependency.GraphAnalyzer.GraphAnalyzerBuilder;
|
||||
import org.mapstruct.ap.internal.model.source.BeanMappingOptions;
|
||||
import org.mapstruct.ap.internal.model.source.Mapping;
|
||||
import org.mapstruct.ap.internal.model.source.MappingOptions;
|
||||
import org.mapstruct.ap.internal.model.source.MappingMethodOptions;
|
||||
import org.mapstruct.ap.internal.model.source.Method;
|
||||
import org.mapstruct.ap.internal.model.source.SelectionParameters;
|
||||
@ -536,7 +536,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
|
||||
PropertyMapping propertyMapping = null;
|
||||
|
||||
TargetReference targetRef = mappingRef.getTargetReference();
|
||||
Mapping mapping = mappingRef.getMapping();
|
||||
MappingOptions mapping = mappingRef.getMapping();
|
||||
PropertyEntry targetProperty = first( targetRef.getPropertyEntries() );
|
||||
String targetPropertyName = targetProperty.getName();
|
||||
|
||||
|
@ -21,7 +21,7 @@ import org.mapstruct.ap.internal.model.beanmapping.PropertyEntry;
|
||||
import org.mapstruct.ap.internal.model.beanmapping.SourceReference;
|
||||
import org.mapstruct.ap.internal.model.beanmapping.TargetReference;
|
||||
import org.mapstruct.ap.internal.model.common.Parameter;
|
||||
import org.mapstruct.ap.internal.model.source.Mapping;
|
||||
import org.mapstruct.ap.internal.model.source.MappingOptions;
|
||||
import org.mapstruct.ap.internal.model.source.Method;
|
||||
|
||||
import static org.mapstruct.ap.internal.util.Collections.first;
|
||||
@ -294,7 +294,7 @@ public class NestedTargetPropertyMappingHolder {
|
||||
}
|
||||
|
||||
/**
|
||||
* The target references are popped. The {@code List<}{@link Mapping}{@code >} are keyed on the unique first
|
||||
* The target references are popped. The {@code List<}{@link MappingOptions}{@code >} are keyed on the unique first
|
||||
* entries of the target references.
|
||||
*
|
||||
* <p>
|
||||
@ -503,7 +503,7 @@ public class NestedTargetPropertyMappingHolder {
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param entryByParam the entry of a {@link Parameter} and it's associated {@link Mapping}(s) that need to
|
||||
* @param entryByParam the entry of a {@link Parameter} and it's associated {@link MappingOptions}(s) that need to
|
||||
* be used for grouping on popped source references
|
||||
* @param singleTargetReferences the single target references that match the source mappings
|
||||
*
|
||||
|
@ -7,26 +7,26 @@ package org.mapstruct.ap.internal.model.beanmapping;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.mapstruct.ap.internal.model.source.Mapping;
|
||||
import org.mapstruct.ap.internal.model.source.MappingOptions;
|
||||
|
||||
/**
|
||||
* Represents the intermediate (nesting) state of the {@link Mapping} in this class.
|
||||
* Represents the intermediate (nesting) state of the {@link MappingOptions} in this class.
|
||||
*/
|
||||
public class MappingReference {
|
||||
|
||||
private Mapping mapping;
|
||||
private MappingOptions mapping;
|
||||
|
||||
private TargetReference targetReference;
|
||||
|
||||
private SourceReference sourceReference;
|
||||
|
||||
public MappingReference(Mapping mapping, TargetReference targetReference, SourceReference sourceReference) {
|
||||
public MappingReference(MappingOptions mapping, TargetReference targetReference, SourceReference sourceReference) {
|
||||
this.mapping = mapping;
|
||||
this.targetReference = targetReference;
|
||||
this.sourceReference = sourceReference;
|
||||
}
|
||||
|
||||
public Mapping getMapping() {
|
||||
public MappingOptions getMapping() {
|
||||
return mapping;
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.mapstruct.ap.internal.model.common.TypeFactory;
|
||||
import org.mapstruct.ap.internal.model.source.Mapping;
|
||||
import org.mapstruct.ap.internal.model.source.MappingOptions;
|
||||
import org.mapstruct.ap.internal.model.source.SourceMethod;
|
||||
import org.mapstruct.ap.internal.util.FormattingMessager;
|
||||
|
||||
@ -35,7 +35,7 @@ public class MappingReferences {
|
||||
Set<MappingReference> references = new LinkedHashSet<>();
|
||||
List<MappingReference> targetThisReferences = new ArrayList<>( );
|
||||
|
||||
for ( Mapping mapping : sourceMethod.getMappingOptions().getMappings() ) {
|
||||
for ( MappingOptions mapping : sourceMethod.getMappingOptions().getMappings() ) {
|
||||
|
||||
// handle source reference
|
||||
SourceReference sourceReference = new SourceReference.BuilderFromMapping().mapping( mapping )
|
||||
@ -139,7 +139,7 @@ public class MappingReferences {
|
||||
* @return
|
||||
*/
|
||||
private static boolean isValidWhenInversed(MappingReference mappingRef) {
|
||||
Mapping mapping = mappingRef.getMapping();
|
||||
MappingOptions mapping = mappingRef.getMapping();
|
||||
if ( mapping.getInheritContext() != null && mapping.getInheritContext().isReversed() ) {
|
||||
return mappingRef.getTargetReference().isValid() && ( mappingRef.getSourceReference() == null ||
|
||||
mappingRef.getSourceReference().isValid() );
|
||||
|
@ -18,7 +18,7 @@ import javax.lang.model.type.DeclaredType;
|
||||
import org.mapstruct.ap.internal.model.common.Parameter;
|
||||
import org.mapstruct.ap.internal.model.common.Type;
|
||||
import org.mapstruct.ap.internal.model.common.TypeFactory;
|
||||
import org.mapstruct.ap.internal.model.source.Mapping;
|
||||
import org.mapstruct.ap.internal.model.source.MappingOptions;
|
||||
import org.mapstruct.ap.internal.model.source.Method;
|
||||
import org.mapstruct.ap.internal.util.FormattingMessager;
|
||||
import org.mapstruct.ap.internal.util.Message;
|
||||
@ -72,7 +72,7 @@ public class SourceReference extends AbstractReference {
|
||||
return this;
|
||||
}
|
||||
|
||||
public BuilderFromMapping mapping(Mapping mapping) {
|
||||
public BuilderFromMapping mapping(MappingOptions mapping) {
|
||||
this.sourceName = mapping.getSourceName();
|
||||
this.annotationMirror = mapping.getMirror();
|
||||
this.sourceAnnotationValue = mapping.getSourceAnnotationValue();
|
||||
|
@ -19,7 +19,7 @@ import org.mapstruct.ap.internal.model.common.Parameter;
|
||||
import org.mapstruct.ap.internal.model.common.Type;
|
||||
import org.mapstruct.ap.internal.model.common.TypeFactory;
|
||||
import org.mapstruct.ap.internal.model.source.BeanMappingOptions;
|
||||
import org.mapstruct.ap.internal.model.source.Mapping;
|
||||
import org.mapstruct.ap.internal.model.source.MappingOptions;
|
||||
import org.mapstruct.ap.internal.model.source.Method;
|
||||
import org.mapstruct.ap.internal.prism.BuilderPrism;
|
||||
import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism;
|
||||
@ -84,7 +84,7 @@ public class TargetReference extends AbstractReference {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder mapping(Mapping mapping) {
|
||||
public Builder mapping(MappingOptions mapping) {
|
||||
if ( mapping.getInheritContext() != null ) {
|
||||
this.isReversed = mapping.getInheritContext().isReversed();
|
||||
this.templateMethod = mapping.getInheritContext().getInheritedFromMethod();
|
||||
|
@ -17,7 +17,7 @@ import org.mapstruct.ap.internal.model.common.TypeFactory;
|
||||
import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism;
|
||||
import org.mapstruct.ap.internal.util.accessor.Accessor;
|
||||
|
||||
import static org.mapstruct.ap.internal.model.source.Mapping.getMappingTargetNamesBy;
|
||||
import static org.mapstruct.ap.internal.model.source.MappingOptions.getMappingTargetNamesBy;
|
||||
|
||||
/**
|
||||
* Encapsulates all options specifiable on a mapping method
|
||||
@ -32,14 +32,14 @@ public class MappingMethodOptions {
|
||||
Collections.emptyList()
|
||||
);
|
||||
|
||||
private Set<Mapping> mappings;
|
||||
private Set<MappingOptions> mappings;
|
||||
private IterableMappingOptions iterableMapping;
|
||||
private MapMappingOptions mapMapping;
|
||||
private BeanMappingOptions beanMapping;
|
||||
private List<ValueMapping> valueMappings;
|
||||
private boolean fullyInitialized;
|
||||
|
||||
public MappingMethodOptions(Set<Mapping> mappings, IterableMappingOptions iterableMapping, MapMappingOptions mapMapping,
|
||||
public MappingMethodOptions(Set<MappingOptions> mappings, IterableMappingOptions iterableMapping, MapMappingOptions mapMapping,
|
||||
BeanMappingOptions beanMapping, List<ValueMapping> valueMappings ) {
|
||||
this.mappings = mappings;
|
||||
this.iterableMapping = iterableMapping;
|
||||
@ -58,10 +58,10 @@ public class MappingMethodOptions {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the {@link Mapping}s configured for this method, keyed by target property name. Only for enum mapping
|
||||
* @return the {@link MappingOptions}s configured for this method, keyed by target property name. Only for enum mapping
|
||||
* methods a target will be mapped by several sources. TODO. Remove the value list when 2.0
|
||||
*/
|
||||
public Set<Mapping> getMappings() {
|
||||
public Set<MappingOptions> getMappings() {
|
||||
return mappings;
|
||||
}
|
||||
|
||||
@ -153,8 +153,8 @@ public class MappingMethodOptions {
|
||||
}
|
||||
}
|
||||
|
||||
Set<Mapping> newMappings = new LinkedHashSet<>();
|
||||
for ( Mapping mapping : inherited.getMappings() ) {
|
||||
Set<MappingOptions> newMappings = new LinkedHashSet<>();
|
||||
for ( MappingOptions mapping : inherited.getMappings() ) {
|
||||
if ( isInverse ) {
|
||||
if ( mapping.canInverse() ) {
|
||||
newMappings.add( mapping.copyForInverseInheritance( templateMethod ) );
|
||||
@ -191,25 +191,25 @@ public class MappingMethodOptions {
|
||||
|
||||
for ( String targetPropertyName : writeAccessors.keySet() ) {
|
||||
if ( !mappedPropertyNames.contains( targetPropertyName ) ) {
|
||||
Mapping mapping = Mapping.forIgnore( targetPropertyName );
|
||||
MappingOptions mapping = MappingOptions.forIgnore( targetPropertyName );
|
||||
mappings.add( mapping );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void filterNestedTargetIgnores( Set<Mapping> mappings) {
|
||||
private void filterNestedTargetIgnores( Set<MappingOptions> mappings) {
|
||||
|
||||
// collect all properties to ignore, and safe their target name ( == same name as first ref target property)
|
||||
Set<String> ignored = getMappingTargetNamesBy( Mapping::isIgnored, mappings );
|
||||
Set<String> ignored = getMappingTargetNamesBy( MappingOptions::isIgnored, mappings );
|
||||
mappings.removeIf( m -> isToBeIgnored( ignored, m ) );
|
||||
}
|
||||
|
||||
private boolean isToBeIgnored(Set<String> ignored, Mapping mapping) {
|
||||
private boolean isToBeIgnored(Set<String> ignored, MappingOptions mapping) {
|
||||
String[] propertyEntries = getPropertyEntries( mapping );
|
||||
return propertyEntries.length > 1 && ignored.contains( propertyEntries[ 0 ] );
|
||||
}
|
||||
|
||||
private String[] getPropertyEntries( Mapping mapping ) {
|
||||
private String[] getPropertyEntries( MappingOptions mapping ) {
|
||||
return mapping.getTargetName().split( "\\." );
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ import org.mapstruct.ap.internal.util.Message;
|
||||
*
|
||||
* @author Gunnar Morling
|
||||
*/
|
||||
public class Mapping {
|
||||
public class MappingOptions {
|
||||
|
||||
private static final Pattern JAVA_EXPRESSION = Pattern.compile( "^java\\((.*)\\)$" );
|
||||
|
||||
@ -81,19 +81,19 @@ public class Mapping {
|
||||
}
|
||||
}
|
||||
|
||||
public static Set<String> getMappingTargetNamesBy(Predicate<Mapping> predicate, Set<Mapping> mappings) {
|
||||
public static Set<String> getMappingTargetNamesBy(Predicate<MappingOptions> predicate, Set<MappingOptions> mappings) {
|
||||
return mappings.stream()
|
||||
.filter( predicate )
|
||||
.map( Mapping::getTargetName )
|
||||
.map( MappingOptions::getTargetName )
|
||||
.collect( Collectors.toCollection( LinkedHashSet::new ) );
|
||||
}
|
||||
|
||||
public static Mapping getMappingByTargetName(String targetName, Set<Mapping> mappings) {
|
||||
public static MappingOptions getMappingByTargetName(String targetName, Set<MappingOptions> mappings) {
|
||||
return mappings.stream().filter( mapping -> mapping.targetName.equals( targetName ) ).findAny().orElse( null );
|
||||
}
|
||||
|
||||
public static void addFromMappingsPrism(MappingsPrism mappingsAnnotation, ExecutableElement method,
|
||||
FormattingMessager messager, Types typeUtils, Set<Mapping> mappings) {
|
||||
FormattingMessager messager, Types typeUtils, Set<MappingOptions> mappings) {
|
||||
|
||||
for ( MappingPrism mappingPrism : mappingsAnnotation.value() ) {
|
||||
addFromMappingPrism( mappingPrism, method, messager, typeUtils, mappings );
|
||||
@ -101,7 +101,7 @@ public class Mapping {
|
||||
}
|
||||
|
||||
public static void addFromMappingPrism(MappingPrism mappingPrism, ExecutableElement method,
|
||||
FormattingMessager messager, Types typeUtils, Set<Mapping> mappings) {
|
||||
FormattingMessager messager, Types typeUtils, Set<MappingOptions> mappings) {
|
||||
|
||||
if (!isConsistent( mappingPrism, method, messager ) ) {
|
||||
return;
|
||||
@ -144,7 +144,7 @@ public class Mapping {
|
||||
? null
|
||||
: NullValuePropertyMappingStrategyPrism.valueOf( mappingPrism.nullValuePropertyMappingStrategy() );
|
||||
|
||||
Mapping mapping = new Mapping(
|
||||
MappingOptions mapping = new MappingOptions(
|
||||
source,
|
||||
constant,
|
||||
expression,
|
||||
@ -172,8 +172,8 @@ public class Mapping {
|
||||
}
|
||||
}
|
||||
|
||||
public static Mapping forIgnore( String targetName) {
|
||||
return new Mapping(
|
||||
public static MappingOptions forIgnore(String targetName) {
|
||||
return new MappingOptions(
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
@ -267,14 +267,14 @@ public class Mapping {
|
||||
}
|
||||
|
||||
@SuppressWarnings("checkstyle:parameternumber")
|
||||
private Mapping(String sourceName, String constant, String javaExpression, String defaultJavaExpression,
|
||||
String targetName, String defaultValue, boolean isIgnored, AnnotationMirror mirror,
|
||||
AnnotationValue sourceAnnotationValue, AnnotationValue targetAnnotationValue,
|
||||
FormattingParameters formattingParameters, SelectionParameters selectionParameters,
|
||||
AnnotationValue dependsOnAnnotationValue, Set<String> dependsOn,
|
||||
NullValueCheckStrategyPrism nullValueCheckStrategy,
|
||||
NullValuePropertyMappingStrategyPrism nullValuePropertyMappingStrategy,
|
||||
InheritContext inheritContext) {
|
||||
private MappingOptions(String sourceName, String constant, String javaExpression, String defaultJavaExpression,
|
||||
String targetName, String defaultValue, boolean isIgnored, AnnotationMirror mirror,
|
||||
AnnotationValue sourceAnnotationValue, AnnotationValue targetAnnotationValue,
|
||||
FormattingParameters formattingParameters, SelectionParameters selectionParameters,
|
||||
AnnotationValue dependsOnAnnotationValue, Set<String> dependsOn,
|
||||
NullValueCheckStrategyPrism nullValueCheckStrategy,
|
||||
NullValuePropertyMappingStrategyPrism nullValuePropertyMappingStrategy,
|
||||
InheritContext inheritContext) {
|
||||
this.sourceName = sourceName;
|
||||
this.constant = constant;
|
||||
this.javaExpression = javaExpression;
|
||||
@ -421,9 +421,9 @@ public class Mapping {
|
||||
return constant == null && javaExpression == null && !( isIgnored && sourceName == null );
|
||||
}
|
||||
|
||||
public Mapping copyForInverseInheritance(SourceMethod method ) {
|
||||
public MappingOptions copyForInverseInheritance(SourceMethod method ) {
|
||||
|
||||
return new Mapping(
|
||||
return new MappingOptions(
|
||||
sourceName != null ? targetName : null,
|
||||
null, // constant
|
||||
null, // expression
|
||||
@ -450,8 +450,8 @@ public class Mapping {
|
||||
*
|
||||
* @return the copy
|
||||
*/
|
||||
public Mapping copyForForwardInheritance( SourceMethod method ) {
|
||||
return new Mapping(
|
||||
public MappingOptions copyForForwardInheritance(SourceMethod method ) {
|
||||
return new MappingOptions(
|
||||
sourceName,
|
||||
constant,
|
||||
javaExpression,
|
||||
@ -485,7 +485,7 @@ public class Mapping {
|
||||
if ( o == null || getClass() != o.getClass() ) {
|
||||
return false;
|
||||
}
|
||||
Mapping mapping = (Mapping) o;
|
||||
MappingOptions mapping = (MappingOptions) o;
|
||||
return targetName.equals( mapping.targetName );
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ public class SourceMethod implements Method {
|
||||
private List<Parameter> parameters;
|
||||
private Type returnType = null;
|
||||
private List<Type> exceptionTypes;
|
||||
private Set<Mapping> mappings;
|
||||
private Set<MappingOptions> mappings;
|
||||
private IterableMappingOptions iterableMapping = null;
|
||||
private MapMappingOptions mapMapping = null;
|
||||
private BeanMappingOptions beanMapping = null;
|
||||
@ -113,7 +113,7 @@ public class SourceMethod implements Method {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setMappings(Set<Mapping> mappings) {
|
||||
public Builder setMappings(Set<MappingOptions> mappings) {
|
||||
this.mappings = mappings;
|
||||
return this;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ import org.mapstruct.ap.internal.model.common.TypeFactory;
|
||||
import org.mapstruct.ap.internal.model.source.BeanMappingOptions;
|
||||
import org.mapstruct.ap.internal.model.source.IterableMappingOptions;
|
||||
import org.mapstruct.ap.internal.model.source.MapMappingOptions;
|
||||
import org.mapstruct.ap.internal.model.source.Mapping;
|
||||
import org.mapstruct.ap.internal.model.source.MappingOptions;
|
||||
import org.mapstruct.ap.internal.model.source.ParameterProvidedMethods;
|
||||
import org.mapstruct.ap.internal.model.source.SourceMethod;
|
||||
import org.mapstruct.ap.internal.model.source.ValueMapping;
|
||||
@ -505,20 +505,20 @@ public class MethodRetrievalProcessor implements ModelElementProcessor<Void, Lis
|
||||
*
|
||||
* @return The mappings for the given method, keyed by target property name
|
||||
*/
|
||||
private Set<Mapping> getMappings(ExecutableElement method, Element element, Set<Mapping> mappings,
|
||||
Set<Element> handledElements) {
|
||||
private Set<MappingOptions> getMappings(ExecutableElement method, Element element, Set<MappingOptions> mappings,
|
||||
Set<Element> handledElements) {
|
||||
|
||||
for ( AnnotationMirror annotationMirror : element.getAnnotationMirrors() ) {
|
||||
Element lElement = annotationMirror.getAnnotationType().asElement();
|
||||
if ( isAnnotation( lElement, MAPPING_FQN ) ) {
|
||||
// although getInstanceOn does a search on annotation mirrors, the order is preserved
|
||||
MappingPrism mappingAnnotation = MappingPrism.getInstanceOn( element );
|
||||
Mapping.addFromMappingPrism( mappingAnnotation, method, messager, typeUtils, mappings );
|
||||
MappingOptions.addFromMappingPrism( mappingAnnotation, method, messager, typeUtils, mappings );
|
||||
}
|
||||
else if ( isAnnotation( lElement, MAPPINGS_FQN ) ) {
|
||||
// although getInstanceOn does a search on annotation mirrors, the order is preserved
|
||||
MappingsPrism mappingsAnnotation = MappingsPrism.getInstanceOn( element );
|
||||
Mapping.addFromMappingsPrism( mappingsAnnotation, method, messager, typeUtils, mappings );
|
||||
MappingOptions.addFromMappingsPrism( mappingsAnnotation, method, messager, typeUtils, mappings );
|
||||
}
|
||||
else if ( !isAnnotationInPackage( lElement, JAVA_LANG_ANNOTATION_PGK )
|
||||
&& !isAnnotationInPackage( lElement, ORG_MAPSTRUCT_PKG )
|
||||
|
Loading…
x
Reference in New Issue
Block a user