mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#3786: Improve error message when mapping non-iterable to array
This commit is contained in:
parent
c08ba4ca7e
commit
39551242d7
@ -555,6 +555,11 @@ public class MethodRetrievalProcessor implements ModelElementProcessor<Void, Lis
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( !parameterType.isIterableOrStreamType() && resultType.isArrayType() ) {
|
||||
messager.printMessage( method, Message.RETRIEVAL_NON_ITERABLE_TO_ARRAY );
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( parameterType.isPrimitive() ) {
|
||||
messager.printMessage( method, Message.RETRIEVAL_PRIMITIVE_PARAMETER );
|
||||
return false;
|
||||
|
@ -175,6 +175,7 @@ public enum Message {
|
||||
RETRIEVAL_ITERABLE_TO_NON_ITERABLE( "Can't generate mapping method from iterable type from java stdlib to non-iterable type." ),
|
||||
RETRIEVAL_MAPPING_HAS_TARGET_TYPE_PARAMETER( "Can't generate mapping method that has a parameter annotated with @TargetType." ),
|
||||
RETRIEVAL_NON_ITERABLE_TO_ITERABLE( "Can't generate mapping method from non-iterable type to iterable type from java stdlib." ),
|
||||
RETRIEVAL_NON_ITERABLE_TO_ARRAY( "Can't generate mapping method from non-iterable type to array." ),
|
||||
RETRIEVAL_PRIMITIVE_PARAMETER( "Can't generate mapping method with primitive parameter type." ),
|
||||
RETRIEVAL_PRIMITIVE_RETURN( "Can't generate mapping method with primitive return type." ),
|
||||
RETRIEVAL_TYPE_VAR_SOURCE( "Can't generate mapping method for a generic type variable source." ),
|
||||
|
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* 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._3786;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface ErroneousByteArrayMapper {
|
||||
byte[] map( String something );
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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._3786;
|
||||
|
||||
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 Ben Zegveld
|
||||
*/
|
||||
@IssueKey( "3786" )
|
||||
public class Issue3786Test {
|
||||
|
||||
@WithClasses( ErroneousByteArrayMapper.class )
|
||||
@ProcessorTest
|
||||
@ExpectedCompilationOutcome(
|
||||
value = CompilationResult.FAILED,
|
||||
diagnostics = {
|
||||
@Diagnostic(
|
||||
type = ErroneousByteArrayMapper.class,
|
||||
kind = javax.tools.Diagnostic.Kind.ERROR,
|
||||
line = 12,
|
||||
message = "Can't generate mapping method from non-iterable type to array."
|
||||
)
|
||||
}
|
||||
)
|
||||
void byteArrayReturnTypeShouldGiveInaccessibleContructorError() {
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user