mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#3413 Using Mapping#expression and Mapping#conditionaQualifiedBy(Name) should lead to compile error
This commit is contained in:
parent
2af291ce2f
commit
2bb2aefed8
@ -42,6 +42,7 @@ Kevin Grüneberg - https://github.com/kevcodez
|
||||
Lukas Lazar - https://github.com/LukeLaz
|
||||
Nikolas Charalambidis - https://github.com/Nikolas-Charalambidis
|
||||
Michael Pardo - https://github.com/pardom
|
||||
Muhammad Usama - https://github.com/the-mgi
|
||||
Mustafa Caylak - https://github.com/luxmeter
|
||||
Oliver Ehrenmüller - https://github.com/greuelpirat
|
||||
Oliver Erhart - https://github.com/thunderhook
|
||||
|
@ -207,10 +207,13 @@ public class MappingOptions extends DelegatingOptions {
|
||||
if ( gem.source().hasValue() && gem.constant().hasValue() ) {
|
||||
message = Message.PROPERTYMAPPING_SOURCE_AND_CONSTANT_BOTH_DEFINED;
|
||||
}
|
||||
else if ( gem.expression().hasValue() && gem.conditionQualifiedByName().hasValue() ) {
|
||||
message = Message.PROPERTYMAPPING_EXPRESSION_AND_CONDITION_QUALIFIED_BY_NAME_BOTH_DEFINED;
|
||||
}
|
||||
else if ( gem.source().hasValue() && gem.expression().hasValue() ) {
|
||||
message = Message.PROPERTYMAPPING_SOURCE_AND_EXPRESSION_BOTH_DEFINED;
|
||||
}
|
||||
else if (gem.expression().hasValue() && gem.constant().hasValue() ) {
|
||||
else if ( gem.expression().hasValue() && gem.constant().hasValue() ) {
|
||||
message = Message.PROPERTYMAPPING_EXPRESSION_AND_CONSTANT_BOTH_DEFINED;
|
||||
}
|
||||
else if ( gem.expression().hasValue() && gem.defaultValue().hasValue() ) {
|
||||
|
@ -84,6 +84,7 @@ public enum Message {
|
||||
PROPERTYMAPPING_CANNOT_DETERMINE_SOURCE_PROPERTY_FROM_TARGET("The type of parameter \"%s\" has no property named \"%s\". Please define the source property explicitly."),
|
||||
PROPERTYMAPPING_CANNOT_DETERMINE_SOURCE_PARAMETER_FROM_TARGET("No property named \"%s\" exists in source parameter(s). Please define the source explicitly."),
|
||||
PROPERTYMAPPING_NO_SUITABLE_COLLECTION_OR_MAP_CONSTRUCTOR( "%s does not have an accessible copy or no-args constructor." ),
|
||||
PROPERTYMAPPING_EXPRESSION_AND_CONDITION_QUALIFIED_BY_NAME_BOTH_DEFINED( "Expression and condition qualified by name are both defined in @Mapping, either define an expression or a condition qualified by name." ),
|
||||
|
||||
CONVERSION_LOSSY_WARNING( "%s has a possibly lossy conversion from %s to %s.", Diagnostic.Kind.WARNING ),
|
||||
CONVERSION_LOSSY_ERROR( "Can't map %s. It has a possibly lossy conversion from %s to %s." ),
|
||||
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package org.mapstruct.ap.test.bugs._3413;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
* @author Muhammad Usama
|
||||
*/
|
||||
@Mapper
|
||||
public interface Erroneous3413Mapper {
|
||||
Erroneous3413Mapper INSTANCE = Mappers.getMapper( Erroneous3413Mapper.class );
|
||||
|
||||
@Mapping(target = "", expression = "", conditionQualifiedByName = "")
|
||||
ToPOJO map(FromPOJO fromPOJO);
|
||||
|
||||
class FromPOJO {
|
||||
private String value;
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
class ToPOJO {
|
||||
private String value;
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package org.mapstruct.ap.test.bugs._3413;
|
||||
|
||||
import org.mapstruct.ap.testutil.IssueKey;
|
||||
import org.mapstruct.ap.testutil.ProcessorTest;
|
||||
import org.mapstruct.ap.testutil.WithClasses;
|
||||
import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
|
||||
import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
|
||||
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
|
||||
|
||||
/**
|
||||
* @author Muhammad Usama
|
||||
*/
|
||||
@IssueKey("3413")
|
||||
public class Issue3413Test {
|
||||
@ProcessorTest
|
||||
@WithClasses(Erroneous3413Mapper.class)
|
||||
@ExpectedCompilationOutcome(
|
||||
value = CompilationResult.FAILED,
|
||||
diagnostics = {
|
||||
@Diagnostic(
|
||||
kind = javax.tools.Diagnostic.Kind.ERROR,
|
||||
line = 19,
|
||||
message = "Expression and condition qualified by name are both defined in @Mapping, " +
|
||||
"either define an expression or a condition qualified by name."
|
||||
)
|
||||
}
|
||||
)
|
||||
void errorExpectedBecauseExpressionAndConditionQualifiedByNameCannotCoExists() {
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user