-
-
Notifications
You must be signed in to change notification settings - Fork 919
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1751 Fix handling of possible builder creation methods with generic …
…signature When a method has a generic signature and the builder type is generic then the method return type does not match the builder type. Therefore check only for raw types. Add extra check for void method since a void method can't be a builder creation method
- Loading branch information
Showing
6 changed files
with
151 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
processor/src/test/java/org/mapstruct/ap/test/bugs/_1751/Holder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* 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._1751; | ||
|
||
/** | ||
* @author Filip Hrisafov | ||
*/ | ||
public class Holder<T> { | ||
|
||
private final T value; | ||
|
||
public Holder(T value) { | ||
this.value = value; | ||
} | ||
|
||
public T getValue() { | ||
return value; | ||
} | ||
|
||
// If empty is considered as a builder creation method, this method would be the build method and would | ||
// lead to a stackoverflow | ||
@SuppressWarnings("unused") | ||
public Holder<T> duplicate() { | ||
return new Holder<>( value ); | ||
} | ||
|
||
// This method should not be considered as builder creation method | ||
@SuppressWarnings("unused") | ||
public static <V> Holder<V> empty() { | ||
return new Holder<>( null ); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
processor/src/test/java/org/mapstruct/ap/test/bugs/_1751/Issue1751Mapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* 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._1751; | ||
|
||
import org.mapstruct.Mapper; | ||
import org.mapstruct.factory.Mappers; | ||
|
||
/** | ||
* @author Filip Hrisafov | ||
*/ | ||
@Mapper | ||
public interface Issue1751Mapper { | ||
|
||
Issue1751Mapper INSTANCE = Mappers.getMapper( Issue1751Mapper.class ); | ||
|
||
Target map(Source source); | ||
|
||
default Holder<Target> mapToHolder(Source source) { | ||
return new Holder<>( this.map( source ) ); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
processor/src/test/java/org/mapstruct/ap/test/bugs/_1751/Issue1751Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* 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._1751; | ||
|
||
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; | ||
|
||
/** | ||
* @author Filip Hrisafov | ||
*/ | ||
@IssueKey("1772") | ||
@RunWith(AnnotationProcessorTestRunner.class) | ||
@WithClasses({ | ||
Holder.class, | ||
Issue1751Mapper.class, | ||
Source.class, | ||
Target.class | ||
}) | ||
public class Issue1751Test { | ||
|
||
@Test | ||
public void name() { | ||
Source source = new Source(); | ||
source.setValue( "some value" ); | ||
|
||
Holder<Target> targetHolder = Issue1751Mapper.INSTANCE.mapToHolder( source ); | ||
|
||
assertThat( targetHolder.getValue() ) | ||
.extracting( Target::getValue ) | ||
.isEqualTo( "some value" ); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
processor/src/test/java/org/mapstruct/ap/test/bugs/_1751/Source.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* 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._1751; | ||
|
||
/** | ||
* @author Filip Hrisafov | ||
*/ | ||
public class Source { | ||
|
||
private String value; | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
public void setValue(String value) { | ||
this.value = value; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
processor/src/test/java/org/mapstruct/ap/test/bugs/_1751/Target.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* 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._1751; | ||
|
||
/** | ||
* @author Filip Hrisafov | ||
*/ | ||
public class Target { | ||
|
||
private String value; | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
public void setValue(String value) { | ||
this.value = value; | ||
} | ||
} |