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;
|
||||
|
||||
if ( result.getSourceType().isCollectionType() ) {
|
||||
result = new AdderWrapper( result, method.getThrownTypes(), isFieldAssignment() );
|
||||
result = new AdderWrapper( result, method.getThrownTypes(), isFieldAssignment(), targetPropertyName );
|
||||
}
|
||||
else {
|
||||
// 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.
|
||||
String desiredName = first( sourceReference.getPropertyEntries() ).getName();
|
||||
String desiredName = last( sourceReference.getPropertyEntries() ).getName();
|
||||
sourceRhs.setSourceLocalVarName( sourceRhs.createLocalVarName( desiredName ) );
|
||||
|
||||
return sourceRhs;
|
||||
|
@ -24,6 +24,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.mapstruct.ap.internal.model.common.Type;
|
||||
import org.mapstruct.ap.internal.util.Nouns;
|
||||
|
||||
/**
|
||||
* Wraps the assignment in a target setter.
|
||||
@ -34,10 +35,13 @@ public class AdderWrapper extends AssignmentWrapper {
|
||||
|
||||
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 );
|
||||
this.thrownTypesToExclude = thrownTypesToExclude;
|
||||
String desiredName = rhs.getSourceType().getTypeParameters().get( 0 ).getName();
|
||||
String desiredName = Nouns.singularize( targetPropertyName );
|
||||
rhs.setSourceLocalVarName( rhs.createLocalVarName( desiredName ) );
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user