mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#941 adapting more logical names for local variables
This commit is contained in:
parent
2fdd392e19
commit
78db48f7cb
@ -366,7 +366,7 @@ public class PropertyMapping extends ModelElement {
|
|||||||
Assignment result = rightHandSide;
|
Assignment result = rightHandSide;
|
||||||
|
|
||||||
if ( result.getSourceType().isCollectionType() ) {
|
if ( result.getSourceType().isCollectionType() ) {
|
||||||
result = new AdderWrapper( result, method.getThrownTypes(), isFieldAssignment() );
|
result = new AdderWrapper( result, method.getThrownTypes(), isFieldAssignment(), targetPropertyName );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Possibly adding null to a target collection. So should be surrounded by an null check.
|
// Possibly adding null to a target collection. So should be surrounded by an null check.
|
||||||
@ -508,7 +508,7 @@ public class PropertyMapping extends ModelElement {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// create a local variable to which forged method can be assigned.
|
// create a local variable to which forged method can be assigned.
|
||||||
String desiredName = first( sourceReference.getPropertyEntries() ).getName();
|
String desiredName = last( sourceReference.getPropertyEntries() ).getName();
|
||||||
sourceRhs.setSourceLocalVarName( sourceRhs.createLocalVarName( desiredName ) );
|
sourceRhs.setSourceLocalVarName( sourceRhs.createLocalVarName( desiredName ) );
|
||||||
|
|
||||||
return sourceRhs;
|
return sourceRhs;
|
||||||
|
@ -24,6 +24,7 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.mapstruct.ap.internal.model.common.Type;
|
import org.mapstruct.ap.internal.model.common.Type;
|
||||||
|
import org.mapstruct.ap.internal.util.Nouns;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps the assignment in a target setter.
|
* Wraps the assignment in a target setter.
|
||||||
@ -34,10 +35,13 @@ public class AdderWrapper extends AssignmentWrapper {
|
|||||||
|
|
||||||
private final List<Type> thrownTypesToExclude;
|
private final List<Type> thrownTypesToExclude;
|
||||||
|
|
||||||
public AdderWrapper( Assignment rhs, List<Type> thrownTypesToExclude, boolean fieldAssignment ) {
|
public AdderWrapper( Assignment rhs,
|
||||||
|
List<Type> thrownTypesToExclude,
|
||||||
|
boolean fieldAssignment,
|
||||||
|
String targetPropertyName ) {
|
||||||
super( rhs, fieldAssignment );
|
super( rhs, fieldAssignment );
|
||||||
this.thrownTypesToExclude = thrownTypesToExclude;
|
this.thrownTypesToExclude = thrownTypesToExclude;
|
||||||
String desiredName = rhs.getSourceType().getTypeParameters().get( 0 ).getName();
|
String desiredName = Nouns.singularize( targetPropertyName );
|
||||||
rhs.setSourceLocalVarName( rhs.createLocalVarName( desiredName ) );
|
rhs.setSourceLocalVarName( rhs.createLocalVarName( desiredName ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user