mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#65 Doc/formatting improvements
This commit is contained in:
parent
d0db16072a
commit
160af62acf
@ -36,15 +36,14 @@ import org.mapstruct.ap.model.common.Parameter;
|
|||||||
import org.mapstruct.ap.model.common.Type;
|
import org.mapstruct.ap.model.common.Type;
|
||||||
import org.mapstruct.ap.model.source.ForgedMethod;
|
import org.mapstruct.ap.model.source.ForgedMethod;
|
||||||
import org.mapstruct.ap.model.source.SourceMethod;
|
import org.mapstruct.ap.model.source.SourceMethod;
|
||||||
|
import org.mapstruct.ap.model.source.SourceReference;
|
||||||
|
import org.mapstruct.ap.model.source.SourceReference.PropertyEntry;
|
||||||
import org.mapstruct.ap.util.Executables;
|
import org.mapstruct.ap.util.Executables;
|
||||||
|
import org.mapstruct.ap.util.Strings;
|
||||||
|
|
||||||
import static org.mapstruct.ap.model.assignment.Assignment.AssignmentType.DIRECT;
|
import static org.mapstruct.ap.model.assignment.Assignment.AssignmentType.DIRECT;
|
||||||
import static org.mapstruct.ap.model.assignment.Assignment.AssignmentType.TYPE_CONVERTED;
|
import static org.mapstruct.ap.model.assignment.Assignment.AssignmentType.TYPE_CONVERTED;
|
||||||
import static org.mapstruct.ap.model.assignment.Assignment.AssignmentType.TYPE_CONVERTED_MAPPED;
|
import static org.mapstruct.ap.model.assignment.Assignment.AssignmentType.TYPE_CONVERTED_MAPPED;
|
||||||
import org.mapstruct.ap.model.source.SourceReference;
|
|
||||||
import org.mapstruct.ap.model.source.SourceReference.PropertyEntry;
|
|
||||||
import org.mapstruct.ap.util.Strings;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the mapping between a source and target property, e.g. from
|
* Represents the mapping between a source and target property, e.g. from
|
||||||
@ -57,10 +56,8 @@ import org.mapstruct.ap.util.Strings;
|
|||||||
public class PropertyMapping extends ModelElement {
|
public class PropertyMapping extends ModelElement {
|
||||||
|
|
||||||
private final String sourceBeanName;
|
private final String sourceBeanName;
|
||||||
|
|
||||||
private final String targetAccessorName;
|
private final String targetAccessorName;
|
||||||
private final Type targetType;
|
private final Type targetType;
|
||||||
|
|
||||||
private final Assignment assignment;
|
private final Assignment assignment;
|
||||||
|
|
||||||
public static class PropertyMappingBuilder {
|
public static class PropertyMappingBuilder {
|
||||||
@ -99,12 +96,12 @@ public class PropertyMapping extends ModelElement {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PropertyMappingBuilder qualifiers( List<TypeMirror> qualifiers ) {
|
public PropertyMappingBuilder qualifiers(List<TypeMirror> qualifiers) {
|
||||||
this.qualifiers = qualifiers;
|
this.qualifiers = qualifiers;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PropertyMappingBuilder dateFormat( String dateFormat ) {
|
public PropertyMappingBuilder dateFormat(String dateFormat) {
|
||||||
this.dateFormat = dateFormat;
|
this.dateFormat = dateFormat;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -141,7 +138,8 @@ public class PropertyMapping extends ModelElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private PropertyMapping getPropertyMapping(Type sourceType, Type targetType,
|
private PropertyMapping getPropertyMapping(Type sourceType, Type targetType,
|
||||||
TargetAccessorType targetAccessorType, String sourceRefStr, String sourceElement) {
|
TargetAccessorType targetAccessorType, String sourceRefStr,
|
||||||
|
String sourceElement) {
|
||||||
|
|
||||||
Assignment assignment = ctx.getMappingResolver().getTargetAssignment(
|
Assignment assignment = ctx.getMappingResolver().getTargetAssignment(
|
||||||
method,
|
method,
|
||||||
@ -234,10 +232,10 @@ public class PropertyMapping extends ModelElement {
|
|||||||
ctx.getMessager().printMessage(
|
ctx.getMessager().printMessage(
|
||||||
Diagnostic.Kind.ERROR,
|
Diagnostic.Kind.ERROR,
|
||||||
String.format(
|
String.format(
|
||||||
"Can't map %s to \"%s %s\".",
|
"Can't map %s to \"%s %s\".",
|
||||||
sourceElement,
|
sourceElement,
|
||||||
targetType,
|
targetType,
|
||||||
targetPropertyName
|
targetPropertyName
|
||||||
),
|
),
|
||||||
method.getExecutable()
|
method.getExecutable()
|
||||||
);
|
);
|
||||||
@ -267,34 +265,36 @@ public class PropertyMapping extends ModelElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private String getSourceRef() {
|
private String getSourceRef() {
|
||||||
|
|
||||||
Parameter sourceParam = sourceReference.getParameter();
|
Parameter sourceParam = sourceReference.getParameter();
|
||||||
List<PropertyEntry> propertyEntries = sourceReference.getPropertyEntries();
|
List<PropertyEntry> propertyEntries = sourceReference.getPropertyEntries();
|
||||||
|
|
||||||
|
// parameter reference
|
||||||
if ( propertyEntries.isEmpty() ) {
|
if ( propertyEntries.isEmpty() ) {
|
||||||
return sourceParam.getName();
|
return sourceParam.getName();
|
||||||
}
|
}
|
||||||
|
// simple property
|
||||||
else if ( propertyEntries.size() == 1 ) {
|
else if ( propertyEntries.size() == 1 ) {
|
||||||
PropertyEntry propertyEntry = propertyEntries.get( 0 );
|
PropertyEntry propertyEntry = propertyEntries.get( 0 );
|
||||||
return sourceParam.getName() + "." + propertyEntry.getAccessor().getSimpleName() + "()";
|
return sourceParam.getName() + "." + propertyEntry.getAccessor().getSimpleName() + "()";
|
||||||
}
|
}
|
||||||
|
// nested property given as dot path
|
||||||
else {
|
else {
|
||||||
PropertyEntry lastPropertyEntry = propertyEntries.get( propertyEntries.size() - 1 );
|
PropertyEntry lastPropertyEntry = propertyEntries.get( propertyEntries.size() - 1 );
|
||||||
|
|
||||||
// forge a method from the parameter type to the last entry type.
|
// forge a method from the parameter type to the last entry type.
|
||||||
String forgedMethodName = Strings.joinAndCamelize( sourceReference.getElementNames() );
|
String forgedMethodName = Strings.joinAndCamelize( sourceReference.getElementNames() );
|
||||||
ForgedMethod methodToGenerate = new ForgedMethod(
|
ForgedMethod methodToGenerate = new ForgedMethod(
|
||||||
forgedMethodName,
|
forgedMethodName,
|
||||||
sourceReference.getParameter().getType(),
|
sourceReference.getParameter().getType(),
|
||||||
lastPropertyEntry.getType(),
|
lastPropertyEntry.getType(),
|
||||||
method.getExecutable()
|
method.getExecutable()
|
||||||
);
|
);
|
||||||
NestedPropertyMappingMethod.Builder builder = new NestedPropertyMappingMethod.Builder();
|
NestedPropertyMappingMethod.Builder builder = new NestedPropertyMappingMethod.Builder();
|
||||||
NestedPropertyMappingMethod nestedPropertyMapping = builder
|
NestedPropertyMappingMethod nestedPropertyMapping = builder
|
||||||
.method( methodToGenerate )
|
.method( methodToGenerate )
|
||||||
.propertyEntries( sourceReference.getPropertyEntries() )
|
.propertyEntries( sourceReference.getPropertyEntries() )
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// add if not yet existing
|
// add if not yet existing
|
||||||
if ( !ctx.getMappingsToGenerate().contains( nestedPropertyMapping ) ) {
|
if ( !ctx.getMappingsToGenerate().contains( nestedPropertyMapping ) ) {
|
||||||
@ -318,9 +318,10 @@ public class PropertyMapping extends ModelElement {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PropertyEntry lastPropertyEntry = propertyEntries.get( propertyEntries.size() - 1 );
|
PropertyEntry lastPropertyEntry = propertyEntries.get( propertyEntries.size() - 1 );
|
||||||
return String.format( "property \"%s %s\"",
|
return String.format(
|
||||||
lastPropertyEntry.getType(),
|
"property \"%s %s\"",
|
||||||
Strings.join( sourceReference.getElementNames(), "." )
|
lastPropertyEntry.getType(),
|
||||||
|
Strings.join( sourceReference.getElementNames(), "." )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -337,7 +338,7 @@ public class PropertyMapping extends ModelElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Type getTargetType( TargetAccessorType targetAccessorType) {
|
private Type getTargetType(TargetAccessorType targetAccessorType) {
|
||||||
switch ( targetAccessorType ) {
|
switch ( targetAccessorType ) {
|
||||||
case ADDER:
|
case ADDER:
|
||||||
case SETTER:
|
case SETTER:
|
||||||
@ -349,7 +350,7 @@ public class PropertyMapping extends ModelElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Assignment forgeMapOrIterableMapping(Type sourceType, Type targetType, String sourceReference,
|
private Assignment forgeMapOrIterableMapping(Type sourceType, Type targetType, String sourceReference,
|
||||||
ExecutableElement element) {
|
ExecutableElement element) {
|
||||||
|
|
||||||
Assignment assignment = null;
|
Assignment assignment = null;
|
||||||
if ( sourceType.isCollectionType() && targetType.isCollectionType() ) {
|
if ( sourceType.isCollectionType() && targetType.isCollectionType() ) {
|
||||||
|
@ -21,7 +21,6 @@ package org.mapstruct.ap.model.source;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.lang.model.element.ExecutableElement;
|
import javax.lang.model.element.ExecutableElement;
|
||||||
|
|
||||||
import org.mapstruct.ap.model.common.Accessibility;
|
import org.mapstruct.ap.model.common.Accessibility;
|
||||||
@ -42,15 +41,15 @@ public class ForgedMethod implements Method {
|
|||||||
private final ExecutableElement positionHintElement;
|
private final ExecutableElement positionHintElement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Forged Method.
|
* Creates a new forged method.
|
||||||
*
|
* <p>
|
||||||
* The name will be based on the source type name and target type name.
|
* The name will be based on the source type name and target type name.
|
||||||
*
|
*
|
||||||
* @param sourceType the source type
|
* @param sourceType the source type
|
||||||
* @param targetType the target type.
|
* @param targetType the target type.
|
||||||
* @param positionHintElement element used to for reference to the position in the source file.
|
* @param positionHintElement element used to for reference to the position in the source file.
|
||||||
*/
|
*/
|
||||||
public ForgedMethod( Type sourceType, Type targetType, ExecutableElement positionHintElement ) {
|
public ForgedMethod(Type sourceType, Type targetType, ExecutableElement positionHintElement) {
|
||||||
this.parameters = Arrays.asList( new Parameter( Strings.decapitalize( sourceType.getName() ), sourceType ) );
|
this.parameters = Arrays.asList( new Parameter( Strings.decapitalize( sourceType.getName() ), sourceType ) );
|
||||||
this.returnType = targetType;
|
this.returnType = targetType;
|
||||||
|
|
||||||
@ -62,21 +61,21 @@ public class ForgedMethod implements Method {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Forged Method. with the given name.
|
* Creates a new forged method with the given name.
|
||||||
*
|
*
|
||||||
* @param name the (unique name) for this method
|
* @param name the (unique name) for this method
|
||||||
* @param sourceType the source type
|
* @param sourceType the source type
|
||||||
* @param targetType the target type.
|
* @param targetType the target type.
|
||||||
* @param positionHintElement element used to for reference to the position in the source file.
|
* @param positionHintElement element used to for reference to the position in the source file.
|
||||||
*/
|
*/
|
||||||
public ForgedMethod( String name, Type sourceType, Type targetType, ExecutableElement positionHintElement ) {
|
public ForgedMethod(String name, Type sourceType, Type targetType, ExecutableElement positionHintElement) {
|
||||||
this.parameters = Arrays.asList( new Parameter( Strings.decapitalize( sourceType.getName() ), sourceType ) );
|
this.parameters = Arrays.asList( new Parameter( Strings.decapitalize( sourceType.getName() ), sourceType ) );
|
||||||
this.returnType = targetType;
|
this.returnType = targetType;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.positionHintElement = positionHintElement;
|
this.positionHintElement = positionHintElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getName( Type type ) {
|
private String getName(Type type) {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
for ( Type typeParam : type.getTypeParameters() ) {
|
for ( Type typeParam : type.getTypeParameters() ) {
|
||||||
builder.append( typeParam.getName() );
|
builder.append( typeParam.getName() );
|
||||||
@ -86,7 +85,7 @@ public class ForgedMethod implements Method {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches( List<Type> sourceTypes, Type targetType ) {
|
public boolean matches(List<Type> sourceTypes, Type targetType) {
|
||||||
|
|
||||||
if ( !targetType.equals( returnType ) ) {
|
if ( !targetType.equals( returnType ) ) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -34,8 +34,8 @@ import javax.lang.model.type.TypeKind;
|
|||||||
import javax.lang.model.type.TypeMirror;
|
import javax.lang.model.type.TypeMirror;
|
||||||
import javax.tools.Diagnostic;
|
import javax.tools.Diagnostic;
|
||||||
import javax.tools.Diagnostic.Kind;
|
import javax.tools.Diagnostic.Kind;
|
||||||
import org.mapstruct.ap.model.common.TypeFactory;
|
|
||||||
|
|
||||||
|
import org.mapstruct.ap.model.common.TypeFactory;
|
||||||
import org.mapstruct.ap.prism.MappingPrism;
|
import org.mapstruct.ap.prism.MappingPrism;
|
||||||
import org.mapstruct.ap.prism.MappingsPrism;
|
import org.mapstruct.ap.prism.MappingsPrism;
|
||||||
|
|
||||||
@ -177,10 +177,10 @@ public class Mapping {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//CHECKSTYLE:OFF
|
//CHECKSTYLE:OFF
|
||||||
private Mapping(String sourceName, String constant, String javaExpression, String targetName,
|
private Mapping(String sourceName, String constant, String javaExpression, String targetName,
|
||||||
String dateFormat, List<TypeMirror> qualifiers,
|
String dateFormat, List<TypeMirror> qualifiers,
|
||||||
boolean isIgnored, boolean isInheritedFromInverseMethod, AnnotationMirror mirror,
|
boolean isIgnored, boolean isInheritedFromInverseMethod, AnnotationMirror mirror,
|
||||||
AnnotationValue sourceAnnotationValue, AnnotationValue targetAnnotationValue) {
|
AnnotationValue sourceAnnotationValue, AnnotationValue targetAnnotationValue) {
|
||||||
this.sourceName = sourceName;
|
this.sourceName = sourceName;
|
||||||
this.constant = constant;
|
this.constant = constant;
|
||||||
this.javaExpression = javaExpression;
|
this.javaExpression = javaExpression;
|
||||||
@ -195,15 +195,15 @@ public class Mapping {
|
|||||||
}
|
}
|
||||||
//CHECKSTYLE:ON
|
//CHECKSTYLE:ON
|
||||||
|
|
||||||
public void init( SourceMethod method, Messager messager, TypeFactory typeFactory ) {
|
public void init(SourceMethod method, Messager messager, TypeFactory typeFactory) {
|
||||||
|
|
||||||
if ( !method.isEnumMapping() ) {
|
if ( !method.isEnumMapping() ) {
|
||||||
sourceReference = new SourceReference.BuilderFromMapping()
|
sourceReference = new SourceReference.BuilderFromMapping()
|
||||||
.mapping( this )
|
.mapping( this )
|
||||||
.method( method )
|
.method( method )
|
||||||
.messager( messager )
|
.messager( messager )
|
||||||
.typeFactory( typeFactory )
|
.typeFactory( typeFactory )
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,24 +272,23 @@ public class Mapping {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Mapping reverse = new Mapping(
|
Mapping reverse = new Mapping(
|
||||||
sourceName != null ? targetName : null,
|
sourceName != null ? targetName : null,
|
||||||
null, // constant
|
null, // constant
|
||||||
null, // expression
|
null, // expression
|
||||||
sourceName != null ? sourceName : targetName,
|
sourceName != null ? sourceName : targetName,
|
||||||
dateFormat,
|
dateFormat,
|
||||||
qualifiers,
|
qualifiers,
|
||||||
isIgnored,
|
isIgnored,
|
||||||
true,
|
true,
|
||||||
mirror,
|
mirror,
|
||||||
sourceAnnotationValue,
|
sourceAnnotationValue,
|
||||||
targetAnnotationValue
|
targetAnnotationValue
|
||||||
);
|
);
|
||||||
|
|
||||||
reverse.init( method, messager, typeFactory );
|
reverse.init( method, messager, typeFactory );
|
||||||
return reverse;
|
return reverse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Mapping {" +
|
return "Mapping {" +
|
||||||
|
@ -24,6 +24,7 @@ import java.util.List;
|
|||||||
import javax.annotation.processing.Messager;
|
import javax.annotation.processing.Messager;
|
||||||
import javax.lang.model.element.ExecutableElement;
|
import javax.lang.model.element.ExecutableElement;
|
||||||
import javax.tools.Diagnostic;
|
import javax.tools.Diagnostic;
|
||||||
|
|
||||||
import org.mapstruct.ap.model.common.Parameter;
|
import org.mapstruct.ap.model.common.Parameter;
|
||||||
import org.mapstruct.ap.model.common.Type;
|
import org.mapstruct.ap.model.common.Type;
|
||||||
import org.mapstruct.ap.model.common.TypeFactory;
|
import org.mapstruct.ap.model.common.TypeFactory;
|
||||||
@ -32,12 +33,15 @@ import org.mapstruct.ap.util.Strings;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This class describes the source side of a property mapping.
|
* This class describes the source side of a property mapping.
|
||||||
*
|
* <p>
|
||||||
* It contains the source parameter, and all individual (nested) PropertyEntries. So consider the following
|
* It contains the source parameter, and all individual (nested) property entries. So consider the following
|
||||||
* mapping method:
|
* mapping method:
|
||||||
|
*
|
||||||
* {@code
|
* {@code
|
||||||
* @Mapping( source = "in.propA.propB" target = "propC" )
|
*
|
||||||
* TypeB mappingMethod ( TypeA in );
|
* @author Sjaak Derksen
|
||||||
|
* @Mapping( source = "in.propA.propB" target = "propC" )
|
||||||
|
* TypeB mappingMethod ( TypeA in );
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* Then:
|
* Then:
|
||||||
@ -47,9 +51,7 @@ import org.mapstruct.ap.util.Strings;
|
|||||||
* <li>{@link #propertyEntries[1]} will describe {@code propB}</li>
|
* <li>{@link #propertyEntries[1]} will describe {@code propB}</li>
|
||||||
* </ol>
|
* </ol>
|
||||||
*
|
*
|
||||||
* After building, the {@link #isValid} will be true when when no problems are detected during building.
|
* After building, {@link #isValid()} will return true when when no problems are detected during building.
|
||||||
*
|
|
||||||
* @author Sjaak Derksen
|
|
||||||
*/
|
*/
|
||||||
public class SourceReference {
|
public class SourceReference {
|
||||||
|
|
||||||
@ -67,22 +69,22 @@ public class SourceReference {
|
|||||||
private Messager messager;
|
private Messager messager;
|
||||||
private TypeFactory typeFactory;
|
private TypeFactory typeFactory;
|
||||||
|
|
||||||
public BuilderFromMapping messager( Messager messager ) {
|
public BuilderFromMapping messager(Messager messager) {
|
||||||
this.messager = messager;
|
this.messager = messager;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BuilderFromMapping mapping( Mapping mapping ) {
|
public BuilderFromMapping mapping(Mapping mapping) {
|
||||||
this.mapping = mapping;
|
this.mapping = mapping;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BuilderFromMapping method( SourceMethod method ) {
|
public BuilderFromMapping method(SourceMethod method) {
|
||||||
this.method = method;
|
this.method = method;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BuilderFromMapping typeFactory( TypeFactory typeFactory ) {
|
public BuilderFromMapping typeFactory(TypeFactory typeFactory) {
|
||||||
this.typeFactory = typeFactory;
|
this.typeFactory = typeFactory;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -98,7 +100,7 @@ public class SourceReference {
|
|||||||
boolean isValid = true;
|
boolean isValid = true;
|
||||||
boolean foundEntryMatch;
|
boolean foundEntryMatch;
|
||||||
|
|
||||||
String[] sourcePropertyNames = new String[ 0 ];
|
String[] sourcePropertyNames = new String[0];
|
||||||
String[] segments = sourceName.split( "\\." );
|
String[] segments = sourceName.split( "\\." );
|
||||||
Parameter parameter = null;
|
Parameter parameter = null;
|
||||||
|
|
||||||
@ -152,15 +154,15 @@ public class SourceReference {
|
|||||||
|
|
||||||
if ( parameter != null ) {
|
if ( parameter != null ) {
|
||||||
reportMappingError(
|
reportMappingError(
|
||||||
"The type of parameter \"%s\" has no property named \"%s\".",
|
"The type of parameter \"%s\" has no property named \"%s\".",
|
||||||
parameter.getName(),
|
parameter.getName(),
|
||||||
Strings.join( Arrays.asList( sourcePropertyNames ), "." )
|
Strings.join( Arrays.asList( sourcePropertyNames ), "." )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
reportMappingError(
|
reportMappingError(
|
||||||
"No property named \"%s\" exists in source parameter(s).",
|
"No property named \"%s\" exists in source parameter(s).",
|
||||||
mapping.getSourceName()
|
mapping.getSourceName()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
isValid = false;
|
isValid = false;
|
||||||
@ -169,7 +171,7 @@ public class SourceReference {
|
|||||||
return new SourceReference( parameter, entries, isValid );
|
return new SourceReference( parameter, entries, isValid );
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<PropertyEntry> getSourceEntries( Type type, String[] entryNames ) {
|
private List<PropertyEntry> getSourceEntries(Type type, String[] entryNames) {
|
||||||
List<PropertyEntry> sourceEntries = new ArrayList<PropertyEntry>();
|
List<PropertyEntry> sourceEntries = new ArrayList<PropertyEntry>();
|
||||||
Type newType = type;
|
Type newType = type;
|
||||||
for ( String entryName : entryNames ) {
|
for ( String entryName : entryNames ) {
|
||||||
@ -190,12 +192,12 @@ public class SourceReference {
|
|||||||
return sourceEntries;
|
return sourceEntries;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reportMappingError( String message, Object... objects ) {
|
private void reportMappingError(String message, Object... objects) {
|
||||||
messager.printMessage(
|
messager.printMessage(
|
||||||
Diagnostic.Kind.ERROR,
|
Diagnostic.Kind.ERROR,
|
||||||
String.format( message, objects ),
|
String.format( message, objects ),
|
||||||
method.getExecutable(), mapping.getMirror(),
|
method.getExecutable(), mapping.getMirror(),
|
||||||
mapping.getSourceAnnotationValue()
|
mapping.getSourceAnnotationValue()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -210,33 +212,33 @@ public class SourceReference {
|
|||||||
private Type type;
|
private Type type;
|
||||||
private Parameter sourceParameter;
|
private Parameter sourceParameter;
|
||||||
|
|
||||||
public BuilderFromProperty name( String name ) {
|
public BuilderFromProperty name(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BuilderFromProperty accessor( ExecutableElement accessor ) {
|
public BuilderFromProperty accessor(ExecutableElement accessor) {
|
||||||
this.accessor = accessor;
|
this.accessor = accessor;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BuilderFromProperty type( Type type ) {
|
public BuilderFromProperty type(Type type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BuilderFromProperty sourceParameter( Parameter sourceParameter ) {
|
public BuilderFromProperty sourceParameter(Parameter sourceParameter) {
|
||||||
this.sourceParameter = sourceParameter;
|
this.sourceParameter = sourceParameter;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SourceReference build() {
|
public SourceReference build() {
|
||||||
List<PropertyEntry> sourcePropertyEntries = Arrays.asList( new PropertyEntry(name, accessor, type) );
|
List<PropertyEntry> sourcePropertyEntries = Arrays.asList( new PropertyEntry( name, accessor, type ) );
|
||||||
return new SourceReference(sourceParameter, sourcePropertyEntries, true );
|
return new SourceReference( sourceParameter, sourcePropertyEntries, true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private SourceReference( Parameter sourceParameter, List<PropertyEntry> sourcePropertyEntries, boolean isValid ) {
|
private SourceReference(Parameter sourceParameter, List<PropertyEntry> sourcePropertyEntries, boolean isValid) {
|
||||||
this.parameter = sourceParameter;
|
this.parameter = sourceParameter;
|
||||||
this.propertyEntries = sourcePropertyEntries;
|
this.propertyEntries = sourcePropertyEntries;
|
||||||
this.isValid = isValid;
|
this.isValid = isValid;
|
||||||
@ -264,7 +266,7 @@ public class SourceReference {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A PropertyEntry contains information on the name, accessor and return type of a property.
|
* A PropertyEntry contains information on the name, accessor and return type of a property.
|
||||||
*/
|
*/
|
||||||
public static class PropertyEntry {
|
public static class PropertyEntry {
|
||||||
|
|
||||||
@ -272,7 +274,7 @@ public class SourceReference {
|
|||||||
private final ExecutableElement accessor;
|
private final ExecutableElement accessor;
|
||||||
private final Type type;
|
private final Type type;
|
||||||
|
|
||||||
public PropertyEntry( String name, ExecutableElement accessor, Type type ) {
|
public PropertyEntry(String name, ExecutableElement accessor, Type type) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.accessor = accessor;
|
this.accessor = accessor;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
@ -18,19 +18,21 @@
|
|||||||
*/
|
*/
|
||||||
package org.mapstruct.ap.test.nestedsourceproperties;
|
package org.mapstruct.ap.test.nestedsourceproperties;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import static org.fest.assertions.Assertions.assertThat;
|
import static org.fest.assertions.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import org.mapstruct.ap.test.nestedsourceproperties.source.Studio;
|
|
||||||
import org.mapstruct.ap.test.nestedsourceproperties.source.Song;
|
import java.util.Arrays;
|
||||||
import org.mapstruct.ap.test.nestedsourceproperties.source.Label;
|
|
||||||
import org.mapstruct.ap.test.nestedsourceproperties.source.Chart;
|
|
||||||
import org.mapstruct.ap.test.nestedsourceproperties.source.Artist;
|
|
||||||
import org.mapstruct.ap.test.nestedsourceproperties.target.ChartEntry;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mapstruct.ap.test.nestedsourceproperties.source.Artist;
|
||||||
|
import org.mapstruct.ap.test.nestedsourceproperties.source.Chart;
|
||||||
|
import org.mapstruct.ap.test.nestedsourceproperties.source.Label;
|
||||||
|
import org.mapstruct.ap.test.nestedsourceproperties.source.Song;
|
||||||
|
import org.mapstruct.ap.test.nestedsourceproperties.source.Studio;
|
||||||
import org.mapstruct.ap.test.nestedsourceproperties.target.AdderUsageObserver;
|
import org.mapstruct.ap.test.nestedsourceproperties.target.AdderUsageObserver;
|
||||||
|
import org.mapstruct.ap.test.nestedsourceproperties.target.ChartEntry;
|
||||||
import org.mapstruct.ap.test.nestedsourceproperties.target.ChartPositions;
|
import org.mapstruct.ap.test.nestedsourceproperties.target.ChartPositions;
|
||||||
import org.mapstruct.ap.testutil.IssueKey;
|
import org.mapstruct.ap.testutil.IssueKey;
|
||||||
import org.mapstruct.ap.testutil.WithClasses;
|
import org.mapstruct.ap.testutil.WithClasses;
|
||||||
@ -74,10 +76,8 @@ public class NestedSourcePropertiesTest {
|
|||||||
assertThat( chartEntry.getPosition() ).isEqualTo( 0 );
|
assertThat( chartEntry.getPosition() ).isEqualTo( 0 );
|
||||||
assertThat( chartEntry.getRecordedAt() ).isEqualTo( "Abbey Road" );
|
assertThat( chartEntry.getRecordedAt() ).isEqualTo( "Abbey Road" );
|
||||||
assertThat( chartEntry.getTitle() ).isEqualTo( "A Hard Day's Night" );
|
assertThat( chartEntry.getTitle() ).isEqualTo( "A Hard Day's Night" );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@WithClasses( { ArtistToChartEntry.class } )
|
@WithClasses( { ArtistToChartEntry.class } )
|
||||||
public void shouldGenerateImplementationForMultipleParam() {
|
public void shouldGenerateImplementationForMultipleParam() {
|
||||||
@ -111,12 +111,11 @@ public class NestedSourcePropertiesTest {
|
|||||||
assertThat( chartEntry.getPosition() ).isEqualTo( 1 );
|
assertThat( chartEntry.getPosition() ).isEqualTo( 1 );
|
||||||
assertThat( chartEntry.getRecordedAt() ).isEqualTo( "Abbey Road" );
|
assertThat( chartEntry.getRecordedAt() ).isEqualTo( "Abbey Road" );
|
||||||
assertThat( chartEntry.getTitle() ).isEqualTo( "A Hard Day's Night" );
|
assertThat( chartEntry.getTitle() ).isEqualTo( "A Hard Day's Night" );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@WithClasses( { ArtistToChartEntry.class } )
|
@WithClasses( { ArtistToChartEntry.class } )
|
||||||
public void shouldPickPropertyNameIsoParameterName() {
|
public void shouldPickPropertyNameOverParameterName() {
|
||||||
|
|
||||||
Chart chart = new Chart();
|
Chart chart = new Chart();
|
||||||
chart.setName( "Billboard" );
|
chart.setName( "Billboard" );
|
||||||
@ -131,7 +130,6 @@ public class NestedSourcePropertiesTest {
|
|||||||
assertThat( chartEntry.getPosition() ).isEqualTo( 0 );
|
assertThat( chartEntry.getPosition() ).isEqualTo( 0 );
|
||||||
assertThat( chartEntry.getRecordedAt() ).isNull();
|
assertThat( chartEntry.getRecordedAt() ).isNull();
|
||||||
assertThat( chartEntry.getTitle() ).isNull();
|
assertThat( chartEntry.getTitle() ).isNull();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -150,7 +148,6 @@ public class NestedSourcePropertiesTest {
|
|||||||
assertThat( positions.getPositions() ).containsExactly( 3L, 5L );
|
assertThat( positions.getPositions() ).containsExactly( 3L, 5L );
|
||||||
|
|
||||||
assertTrue( AdderUsageObserver.isUsed() );
|
assertTrue( AdderUsageObserver.isUsed() );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -169,7 +166,5 @@ public class NestedSourcePropertiesTest {
|
|||||||
assertThat( positions.getPositions() ).containsExactly( 3L, 5L );
|
assertThat( positions.getPositions() ).containsExactly( 3L, 5L );
|
||||||
|
|
||||||
assertFalse( AdderUsageObserver.isUsed() );
|
assertFalse( AdderUsageObserver.isUsed() );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,4 @@ public class Chart {
|
|||||||
public void setSong( Song song ) {
|
public void setSong( Song song ) {
|
||||||
this.song = song;
|
this.song = song;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,4 @@ public class Label {
|
|||||||
public void setStudio( Studio studio ) {
|
public void setStudio( Studio studio ) {
|
||||||
this.studio = studio;
|
this.studio = studio;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,4 @@ public class Song {
|
|||||||
public void setPositions( List<Integer> positions ) {
|
public void setPositions( List<Integer> positions ) {
|
||||||
this.positions = positions;
|
this.positions = positions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,4 @@ public class Studio {
|
|||||||
public void setName( String name ) {
|
public void setName( String name ) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@ package org.mapstruct.ap.test.nestedsourceproperties.target;
|
|||||||
*/
|
*/
|
||||||
public class ChartEntry {
|
public class ChartEntry {
|
||||||
|
|
||||||
|
|
||||||
private String chartName;
|
private String chartName;
|
||||||
private String title;
|
private String title;
|
||||||
private String artistName;
|
private String artistName;
|
||||||
@ -79,7 +78,4 @@ public class ChartEntry {
|
|||||||
public void setPosition( int position ) {
|
public void setPosition( int position ) {
|
||||||
this.position = position;
|
this.position = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user