mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
parent
3bffe96983
commit
7c62aec281
@ -721,30 +721,33 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
|
|||||||
sourceRef = getSourceRef( method.getSourceParameters().get( 0 ), targetPropertyName );
|
sourceRef = getSourceRef( method.getSourceParameters().get( 0 ), targetPropertyName );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( sourceRef.isValid() ) {
|
if ( sourceRef != null ) {
|
||||||
|
// sourceRef == null is not considered an error here
|
||||||
|
if ( sourceRef.isValid() ) {
|
||||||
|
|
||||||
// targetProperty == null can occur: we arrived here because we want as many errors
|
// targetProperty == null can occur: we arrived here because we want as many errors
|
||||||
// as possible before we stop analysing
|
// as possible before we stop analysing
|
||||||
propertyMapping = new PropertyMappingBuilder()
|
propertyMapping = new PropertyMappingBuilder()
|
||||||
.mappingContext( ctx )
|
.mappingContext( ctx )
|
||||||
.sourceMethod( method )
|
.sourceMethod( method )
|
||||||
.target( targetPropertyName, targetReadAccessor, targetWriteAccessor )
|
.target( targetPropertyName, targetReadAccessor, targetWriteAccessor )
|
||||||
.sourcePropertyName( mapping.getSourceName() )
|
.sourcePropertyName( mapping.getSourceName() )
|
||||||
.sourceReference( sourceRef )
|
.sourceReference( sourceRef )
|
||||||
.selectionParameters( mapping.getSelectionParameters() )
|
.selectionParameters( mapping.getSelectionParameters() )
|
||||||
.formattingParameters( mapping.getFormattingParameters() )
|
.formattingParameters( mapping.getFormattingParameters() )
|
||||||
.existingVariableNames( existingVariableNames )
|
.existingVariableNames( existingVariableNames )
|
||||||
.dependsOn( mapping.getDependsOn() )
|
.dependsOn( mapping.getDependsOn() )
|
||||||
.defaultValue( mapping.getDefaultValue() )
|
.defaultValue( mapping.getDefaultValue() )
|
||||||
.defaultJavaExpression( mapping.getDefaultJavaExpression() )
|
.defaultJavaExpression( mapping.getDefaultJavaExpression() )
|
||||||
.mirror( mapping.getMirror() )
|
.mirror( mapping.getMirror() )
|
||||||
.options( mapping )
|
.options( mapping )
|
||||||
.build();
|
.build();
|
||||||
handledTargets.add( targetPropertyName );
|
handledTargets.add( targetPropertyName );
|
||||||
unprocessedSourceParameters.remove( sourceRef.getParameter() );
|
unprocessedSourceParameters.remove( sourceRef.getParameter() );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
errorOccured = true;
|
errorOccured = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// remaining are the mappings without a 'source' so, 'only' a date format or qualifiers
|
// remaining are the mappings without a 'source' so, 'only' a date format or qualifiers
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* 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._2077;
|
||||||
|
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.Mapping;
|
||||||
|
import org.mapstruct.ReportingPolicy;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Sjaak Derksen
|
||||||
|
*/
|
||||||
|
@Mapper( unmappedTargetPolicy = ReportingPolicy.ERROR )
|
||||||
|
public interface Issue2077ErroneousMapper {
|
||||||
|
|
||||||
|
Issue2077ErroneousMapper INSTANCE = Mappers.getMapper( Issue2077ErroneousMapper.class );
|
||||||
|
|
||||||
|
@Mapping(target = "s1", defaultValue = "xyz" )
|
||||||
|
Target map(String source);
|
||||||
|
|
||||||
|
class Target {
|
||||||
|
|
||||||
|
private String s1;
|
||||||
|
|
||||||
|
public String getS1() {
|
||||||
|
return s1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setS1(String s1) {
|
||||||
|
this.s1 = s1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* 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._2077;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mapstruct.ap.testutil.IssueKey;
|
||||||
|
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;
|
||||||
|
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
|
||||||
|
|
||||||
|
import static javax.tools.Diagnostic.Kind.ERROR;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Sjaak Derksen
|
||||||
|
*/
|
||||||
|
@IssueKey("2077")
|
||||||
|
@RunWith(AnnotationProcessorTestRunner.class)
|
||||||
|
public class Issue2077Test {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@WithClasses(Issue2077ErroneousMapper.class)
|
||||||
|
@ExpectedCompilationOutcome(
|
||||||
|
value = CompilationResult.FAILED,
|
||||||
|
diagnostics = {
|
||||||
|
@Diagnostic(type = Issue2077ErroneousMapper.class,
|
||||||
|
kind = ERROR,
|
||||||
|
line = 22,
|
||||||
|
message = "Unmapped target property: \"s1\".")
|
||||||
|
}
|
||||||
|
)
|
||||||
|
public void shouldNotCompile() {
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user