#2515 add ambiguous constructors to ambiguous constructor error message

This commit is contained in:
Bas Claessen 2021-08-14 09:06:54 +02:00 committed by GitHub
parent 0d8729767b
commit 06c416043c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 4 deletions

View File

@ -26,6 +26,7 @@ import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.ElementFilter;
@ -699,7 +700,14 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
method.getExecutable(),
GENERAL_AMBIGUOUS_CONSTRUCTORS,
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;
}

View File

@ -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_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_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_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 ),

View File

@ -29,8 +29,10 @@ public class ErroneousConstructorTest {
kind = javax.tools.Diagnostic.Kind.ERROR,
line = 17,
message = "Ambiguous constructors found for creating org.mapstruct.ap.test.constructor.erroneous" +
".ErroneousAmbiguousConstructorsMapper.PersonWithMultipleConstructors. Either declare parameterless " +
"constructor or annotate the default constructor with an annotation named @Default."
".ErroneousAmbiguousConstructorsMapper.PersonWithMultipleConstructors: " +
"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() {