mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#2515 add ambiguous constructors to ambiguous constructor error message
This commit is contained in:
parent
0d8729767b
commit
06c416043c
@ -26,6 +26,7 @@ import javax.lang.model.element.AnnotationValue;
|
|||||||
import javax.lang.model.element.Element;
|
import javax.lang.model.element.Element;
|
||||||
import javax.lang.model.element.ExecutableElement;
|
import javax.lang.model.element.ExecutableElement;
|
||||||
import javax.lang.model.element.Modifier;
|
import javax.lang.model.element.Modifier;
|
||||||
|
import javax.lang.model.element.VariableElement;
|
||||||
import javax.lang.model.type.DeclaredType;
|
import javax.lang.model.type.DeclaredType;
|
||||||
import javax.lang.model.type.TypeMirror;
|
import javax.lang.model.type.TypeMirror;
|
||||||
import javax.lang.model.util.ElementFilter;
|
import javax.lang.model.util.ElementFilter;
|
||||||
@ -699,7 +700,14 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
|
|||||||
method.getExecutable(),
|
method.getExecutable(),
|
||||||
GENERAL_AMBIGUOUS_CONSTRUCTORS,
|
GENERAL_AMBIGUOUS_CONSTRUCTORS,
|
||||||
type,
|
type,
|
||||||
Strings.join( constructors, ", " )
|
constructors.stream()
|
||||||
|
.map( ExecutableElement::getParameters )
|
||||||
|
.map( ps -> ps.stream()
|
||||||
|
.map( VariableElement::asType )
|
||||||
|
.map( String::valueOf )
|
||||||
|
.collect( Collectors.joining( ", ", type.getName() + "(", ")" ) )
|
||||||
|
)
|
||||||
|
.collect( Collectors.joining( ", " ) )
|
||||||
);
|
);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -125,7 +125,7 @@ public enum Message {
|
|||||||
GENERAL_AMBIGUOUS_MAPPING_METHOD( "Ambiguous mapping methods found for mapping %s to %s: %s. See " + FAQ_AMBIGUOUS_URL + " for more info." ),
|
GENERAL_AMBIGUOUS_MAPPING_METHOD( "Ambiguous mapping methods found for mapping %s to %s: %s. See " + FAQ_AMBIGUOUS_URL + " for more info." ),
|
||||||
GENERAL_AMBIGUOUS_FACTORY_METHOD( "Ambiguous factory methods found for creating %s: %s. See " + FAQ_AMBIGUOUS_URL + " for more info." ),
|
GENERAL_AMBIGUOUS_FACTORY_METHOD( "Ambiguous factory methods found for creating %s: %s. See " + FAQ_AMBIGUOUS_URL + " for more info." ),
|
||||||
GENERAL_AMBIGUOUS_PRESENCE_CHECK_METHOD( "Ambiguous presence check methods found for checking %s: %s. See " + FAQ_AMBIGUOUS_URL + " for more info." ),
|
GENERAL_AMBIGUOUS_PRESENCE_CHECK_METHOD( "Ambiguous presence check methods found for checking %s: %s. See " + FAQ_AMBIGUOUS_URL + " for more info." ),
|
||||||
GENERAL_AMBIGUOUS_CONSTRUCTORS( "Ambiguous constructors found for creating %s. Either declare parameterless constructor or annotate the default constructor with an annotation named @Default." ),
|
GENERAL_AMBIGUOUS_CONSTRUCTORS( "Ambiguous constructors found for creating %s: %s. Either declare parameterless constructor or annotate the default constructor with an annotation named @Default." ),
|
||||||
GENERAL_CONSTRUCTOR_PROPERTIES_NOT_MATCHING_PARAMETERS( "Incorrect @ConstructorProperties for %s. The size of the @ConstructorProperties does not match the number of constructor parameters" ),
|
GENERAL_CONSTRUCTOR_PROPERTIES_NOT_MATCHING_PARAMETERS( "Incorrect @ConstructorProperties for %s. The size of the @ConstructorProperties does not match the number of constructor parameters" ),
|
||||||
GENERAL_UNSUPPORTED_DATE_FORMAT_CHECK( "No dateFormat check is supported for types %s, %s" ),
|
GENERAL_UNSUPPORTED_DATE_FORMAT_CHECK( "No dateFormat check is supported for types %s, %s" ),
|
||||||
GENERAL_VALID_DATE( "Given date format \"%s\" is valid.", Diagnostic.Kind.NOTE ),
|
GENERAL_VALID_DATE( "Given date format \"%s\" is valid.", Diagnostic.Kind.NOTE ),
|
||||||
|
@ -29,8 +29,10 @@ public class ErroneousConstructorTest {
|
|||||||
kind = javax.tools.Diagnostic.Kind.ERROR,
|
kind = javax.tools.Diagnostic.Kind.ERROR,
|
||||||
line = 17,
|
line = 17,
|
||||||
message = "Ambiguous constructors found for creating org.mapstruct.ap.test.constructor.erroneous" +
|
message = "Ambiguous constructors found for creating org.mapstruct.ap.test.constructor.erroneous" +
|
||||||
".ErroneousAmbiguousConstructorsMapper.PersonWithMultipleConstructors. Either declare parameterless " +
|
".ErroneousAmbiguousConstructorsMapper.PersonWithMultipleConstructors: " +
|
||||||
"constructor or annotate the default constructor with an annotation named @Default."
|
"PersonWithMultipleConstructors(java.lang.String), " +
|
||||||
|
"PersonWithMultipleConstructors(java.lang.String, int). Either declare parameterless constructor " +
|
||||||
|
"or annotate the default constructor with an annotation named @Default."
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
public void shouldUseMultipleConstructors() {
|
public void shouldUseMultipleConstructors() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user