forked from mapstruct/mapstruct
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use correct type for the Record component read accessors
- Loading branch information
Showing
18 changed files
with
265 additions
and
29 deletions.
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
22 changes: 22 additions & 0 deletions
22
integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-1/pom.xml
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 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright MapStruct Authors. | ||
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<artifactId>recordsCrossModuleInterfaceTest</artifactId> | ||
<groupId>org.mapstruct</groupId> | ||
<version>1.0.0</version> | ||
</parent> | ||
|
||
<artifactId>records-cross-module-1</artifactId> | ||
|
||
</project> |
10 changes: 10 additions & 0 deletions
10
...rfaceTest/module-1/src/main/java/org/mapstruct/itest/records/module1/NestedInterface.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,10 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.mapstruct.itest.records.module1; | ||
|
||
public interface NestedInterface { | ||
String field(); | ||
} |
10 changes: 10 additions & 0 deletions
10
...terfaceTest/module-1/src/main/java/org/mapstruct/itest/records/module1/RootInterface.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,10 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.mapstruct.itest.records.module1; | ||
|
||
public interface RootInterface { | ||
NestedInterface nested(); | ||
} |
11 changes: 11 additions & 0 deletions
11
...ceTest/module-1/src/main/java/org/mapstruct/itest/records/module1/SourceNestedRecord.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,11 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.mapstruct.itest.records.module1; | ||
|
||
public record SourceNestedRecord( | ||
String field | ||
) implements NestedInterface { | ||
} |
11 changes: 11 additions & 0 deletions
11
...faceTest/module-1/src/main/java/org/mapstruct/itest/records/module1/SourceRootRecord.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,11 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.mapstruct.itest.records.module1; | ||
|
||
public record SourceRootRecord( | ||
SourceNestedRecord nested | ||
) implements RootInterface { | ||
} |
30 changes: 30 additions & 0 deletions
30
integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-2/pom.xml
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,30 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright MapStruct Authors. | ||
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<artifactId>recordsCrossModuleInterfaceTest</artifactId> | ||
<groupId>org.mapstruct</groupId> | ||
<version>1.0.0</version> | ||
</parent> | ||
|
||
<artifactId>records-cross-module-2</artifactId> | ||
|
||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.mapstruct</groupId> | ||
<artifactId>records-cross-module-1</artifactId> | ||
<version>1.0.0</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
18 changes: 18 additions & 0 deletions
18
...odule-2/src/main/java/org/mapstruct/itest/records/module2/RecordInterfaceIssueMapper.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,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.itest.records.module2; | ||
|
||
import org.mapstruct.itest.records.module1.SourceRootRecord; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.factory.Mappers; | ||
|
||
@Mapper | ||
public interface RecordInterfaceIssueMapper { | ||
|
||
RecordInterfaceIssueMapper INSTANCE = Mappers.getMapper(RecordInterfaceIssueMapper.class); | ||
|
||
TargetRootRecord map(SourceRootRecord source); | ||
} |
11 changes: 11 additions & 0 deletions
11
...ceTest/module-2/src/main/java/org/mapstruct/itest/records/module2/TargetNestedRecord.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,11 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.mapstruct.itest.records.module2; | ||
|
||
public record TargetNestedRecord( | ||
String field | ||
) { | ||
} |
11 changes: 11 additions & 0 deletions
11
...faceTest/module-2/src/main/java/org/mapstruct/itest/records/module2/TargetRootRecord.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,11 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.mapstruct.itest.records.module2; | ||
|
||
public record TargetRootRecord( | ||
TargetNestedRecord nested | ||
) { | ||
} |
26 changes: 26 additions & 0 deletions
26
...InterfaceTest/module-2/src/test/java/org/mapstruct/itest/records/module2/RecordsTest.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,26 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.mapstruct.itest.records.module2; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.Test; | ||
import org.mapstruct.itest.records.module1.SourceRootRecord; | ||
import org.mapstruct.itest.records.module1.SourceNestedRecord; | ||
|
||
public class RecordsTest { | ||
|
||
@Test | ||
public void shouldMap() { | ||
SourceRootRecord source = new SourceRootRecord( new SourceNestedRecord( "test" ) ); | ||
TargetRootRecord target = RecordInterfaceIssueMapper.INSTANCE.map( source ); | ||
|
||
assertThat( target ).isNotNull(); | ||
assertThat( target.nested() ).isNotNull(); | ||
assertThat( target.nested().field() ).isEqualTo( "test" ); | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/pom.xml
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,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright MapStruct Authors. | ||
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.mapstruct</groupId> | ||
<artifactId>mapstruct-it-parent</artifactId> | ||
<version>1.0.0</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>recordsCrossModuleInterfaceTest</artifactId> | ||
<packaging>pom</packaging> | ||
|
||
<modules> | ||
<module>module-1</module> | ||
<module>module-2</module> | ||
</modules> | ||
</project> |
File renamed without changes.
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
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
45 changes: 45 additions & 0 deletions
45
processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ElementAccessor.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,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.internal.util.accessor; | ||
|
||
import javax.lang.model.element.Element; | ||
import javax.lang.model.element.VariableElement; | ||
import javax.lang.model.type.TypeMirror; | ||
|
||
/** | ||
* An {@link Accessor} that wraps a {@link VariableElement}. | ||
* | ||
* @author Filip Hrisafov | ||
*/ | ||
public class ElementAccessor extends AbstractAccessor<Element> { | ||
|
||
private final AccessorType accessorType; | ||
|
||
public ElementAccessor(VariableElement variableElement) { | ||
this( variableElement, AccessorType.FIELD ); | ||
} | ||
|
||
public ElementAccessor(Element element, AccessorType accessorType) { | ||
super( element ); | ||
this.accessorType = accessorType; | ||
} | ||
|
||
@Override | ||
public TypeMirror getAccessedType() { | ||
return element.asType(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return element.toString(); | ||
} | ||
|
||
@Override | ||
public AccessorType getAccessorType() { | ||
return accessorType; | ||
} | ||
|
||
} |
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
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