-
-
Notifications
You must be signed in to change notification settings - Fork 990
#2946 allow update methods with @SubclassMapping
#3330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -467,6 +467,7 @@ private SubclassMapping createSubclassMapping(SubclassMappingOptions subclassMap | |
sourceType, | ||
targetType, | ||
mappingReferences ) ); | ||
|
||
String sourceArgument = null; | ||
for ( Parameter parameter : method.getSourceParameters() ) { | ||
if ( ctx | ||
|
@@ -479,7 +480,19 @@ private SubclassMapping createSubclassMapping(SubclassMappingOptions subclassMap | |
} | ||
} | ||
} | ||
return new SubclassMapping( sourceType, sourceArgument, targetType, assignment ); | ||
|
||
String targetArgument = null; | ||
Parameter targetParameter = method.getMappingTargetParameter(); | ||
if ( targetParameter != null ) { | ||
targetArgument = targetParameter.getName(); | ||
if ( assignment != null ) { | ||
assignment.setSourceLocalVarName( | ||
"(" + sourceType.createReferenceName() + ") " + sourceArgument | ||
+ ", (" + targetType.createReferenceName() + ") " + targetArgument ); | ||
} | ||
} | ||
|
||
return new SubclassMapping( sourceType, sourceArgument, targetType, targetArgument, assignment ); | ||
} | ||
|
||
private boolean isAbstractReturnTypeAllowed() { | ||
|
@@ -1942,6 +1955,10 @@ public boolean hasSubclassMappings() { | |
return !subclassMappings.isEmpty(); | ||
} | ||
|
||
public boolean isUpdateMethod() { | ||
return Parameter.getMappingTargetParameter( getParameters() ) != null; | ||
} | ||
|
||
Comment on lines
+1958
to
+1961
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this and use |
||
public boolean isAbstractReturnType() { | ||
return getFactoryMethod() == null && returnTypeToConstruct != null | ||
&& returnTypeToConstruct.isAbstract(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,6 +171,9 @@ private ForgedMethod(String name, Type sourceType, Type returnType, List<Paramet | |
Parameter sourceParameter = new Parameter( sourceParamSafeName, sourceType ); | ||
this.parameters.add( sourceParameter ); | ||
this.parameters.addAll( additionalParameters ); | ||
if ( basedOn.isUpdateMethod() ) { | ||
this.parameters.add( Parameter.forForgedMappingTarget( returnType ) ); | ||
} | ||
Comment on lines
+174
to
+176
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this needed? Why don't we pass everything in the additional parameters? |
||
this.sourceParameters = Parameter.getSourceParameters( parameters ); | ||
this.contextParameters = Parameter.getContextParameters( parameters ); | ||
this.mappingTargetParameter = Parameter.getMappingTargetParameter( parameters ); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -227,21 +227,11 @@ void subclassMappingInheritsInverseMappingWithCompositeMapping() { | |
void subclassOrderWarning() { | ||
} | ||
|
||
@IssueKey( "2946" ) | ||
@ProcessorTest | ||
@WithClasses({ ErroneousSubclassUpdateMapper.class }) | ||
@ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { | ||
@Diagnostic(type = ErroneousSubclassUpdateMapper.class, | ||
kind = javax.tools.Diagnostic.Kind.ERROR, | ||
line = 21, | ||
message = "SubclassMapping annotation can not be used for update methods." | ||
), | ||
@Diagnostic(type = ErroneousSubclassUpdateMapper.class, | ||
kind = javax.tools.Diagnostic.Kind.ERROR, | ||
line = 25, | ||
message = "SubclassMapping annotation can not be used for update methods." | ||
) | ||
}) | ||
void unsupportedUpdateMethod() { | ||
@WithClasses({ SubclassUpdateMapper.class }) | ||
@ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED) | ||
void updateMethod() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this test and write more thorough tests |
||
} | ||
|
||
@ProcessorTest | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this change needed?