#1650 cannot find symbol nested mapping mappingtarget (#1671)

* #1650 reproducer

* #1650 fix cannot-find-symbol

* #1650 reproducer, extended
This commit is contained in:
Sjaak Derksen 2018-12-20 21:12:37 +01:00 committed by GitHub
parent 8edc6f82aa
commit 743361ca45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 147 additions and 1 deletions

View File

@ -9,7 +9,8 @@
<#import '../macro/CommonMacros.ftl' as lib >
<@lib.handleExceptions>
<#if includeSourceNullCheck>
if ( <#if sourcePresenceCheckerReference?? >${sourcePresenceCheckerReference}<#else>${sourceReference} != null</#if> ) {
<@lib.sourceLocalVarAssignment/>
if ( <#if sourcePresenceCheckerReference?? >${sourcePresenceCheckerReference}<#else><#if sourceLocalVarName??>${sourceLocalVarName}<#else>${sourceReference}</#if> != null</#if> ) {
<@assignToExistingTarget/>
<@lib.handleAssignment/>;
}

View File

@ -0,0 +1,18 @@
/*
* 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._1650;
public class A {
private B b;
public B getB() {
return b;
}
public void setB(B b) {
this.b = b;
}
}

View File

@ -0,0 +1,27 @@
/*
* 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._1650;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.factory.Mappers;
@Mapper
public interface AMapper {
AMapper INSTANCE = Mappers.getMapper( AMapper.class );
@Mapping(source = "b.c", target = "cPrime")
APrime toAPrime(A a, @MappingTarget APrime mappingTarget);
CPrime toCPrime(C c, @MappingTarget CPrime mappingTarget);
@Mapping(source = "b.c", target = "cPrime")
APrime toAPrime(A a);
CPrime toCPrime(C c);
}

View File

@ -0,0 +1,19 @@
/*
* 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._1650;
public class APrime {
private CPrime cPrime;
public CPrime getcPrime() {
return cPrime;
}
public void setcPrime(CPrime cPrime) {
this.cPrime = cPrime;
}
}

View File

@ -0,0 +1,18 @@
/*
* 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._1650;
public class B {
private C c;
public C getC() {
return c;
}
public void setC(C c) {
this.c = c;
}
}

View File

@ -0,0 +1,9 @@
/*
* 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._1650;
public class C {
}

View File

@ -0,0 +1,9 @@
/*
* 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._1650;
public class CPrime {
}

View File

@ -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._1650;
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.runner.AnnotationProcessorTestRunner;
import static org.assertj.core.api.Assertions.assertThat;
@IssueKey("1650")
@RunWith(AnnotationProcessorTestRunner.class)
@WithClasses({
AMapper.class,
A.class,
B.class,
C.class,
APrime.class,
CPrime.class
})
public class Issue1650Test {
@Test
public void shouldCompile() {
A a = new A();
a.setB( new B() );
a.getB().setC( new C() );
APrime aPrime = new APrime();
// update mapping
AMapper.INSTANCE.toAPrime( a, aPrime );
assertThat( aPrime.getcPrime() ).isNotNull();
// create mapping
APrime aPrime1 = AMapper.INSTANCE.toAPrime( a );
assertThat( aPrime1.getcPrime() ).isNotNull();
}
}