Skip to content

Commit bd3a48c

Browse files
committed
Add fixes for running the GemProcessor on Java 18+
1 parent cce0702 commit bd3a48c

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

processor/src/main/java/org/mapstruct/tools/gem/processor/GemInfo.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
*/
66
package org.mapstruct.tools.gem.processor;
77

8+
import java.util.Arrays;
89
import java.util.List;
910
import java.util.Set;
1011
import java.util.stream.Collectors;
12+
import javax.lang.model.element.Element;
1113

1214
public class GemInfo {
1315

@@ -22,16 +24,18 @@ public class GemInfo {
2224
private final String builderImplName;
2325

2426
private final List<GemValueInfo> gemValueInfos;
27+
private final Element[] originatingElements;
2528

2629
public GemInfo(String gemPackageName, String annotationName, String annotationFqn,
27-
List<GemValueInfo> gemValueInfos) {
30+
List<GemValueInfo> gemValueInfos, Element... originatingElements) {
2831
this.gemPackageName = gemPackageName;
2932
this.gemName = annotationName + "Gem";
3033
this.annotationName = annotationName;
3134
this.annotationFqn = annotationFqn;
3235
this.gemValueInfos = gemValueInfos;
3336
this.builderName = BUILDER_NAME + ( BUILDER_NAME.equals( annotationName ) ? "_" : "" );
3437
this.builderImplName = BUILDER_IMPL_NAME + ( BUILDER_IMPL_NAME.equals( annotationName ) ? "_" : "" );
38+
this.originatingElements = Arrays.copyOf( originatingElements, originatingElements.length );
3539
}
3640

3741
public String getGemName() {
@@ -71,6 +75,10 @@ public String getBuilderImplName() {
7175
return builderImplName;
7276
}
7377

78+
public Element[] getOriginatingElements() {
79+
return originatingElements;
80+
}
81+
7482
private boolean isNotSamePackage(GemValueType valueType ) {
7583
return !valueType.getPacakage().equals( gemPackageName );
7684
}

processor/src/main/java/org/mapstruct/tools/gem/processor/GemProcessor.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,14 @@ private void addGemInfo(AnnotationMirror gemDefinitionMirror, Element definingEl
105105
List<GemValueInfo> gemValueInfos = methods.stream()
106106
.map( e -> new GemValueInfo( e.getSimpleName().toString(), e.getReturnType() ) )
107107
.collect( Collectors.toList() );
108-
GemInfo gemInfo = new GemInfo( gemPackage, gemName, gemFqn, gemValueInfos );
108+
GemInfo gemInfo = new GemInfo(
109+
gemPackage,
110+
gemName,
111+
gemFqn,
112+
gemValueInfos,
113+
definingElement,
114+
gemDeclaredType.asElement()
115+
);
109116
gemInfos.add( gemInfo );
110117
}
111118

@@ -183,11 +190,12 @@ else if (String.class.getName().equals( fqn ) ) {
183190
}
184191

185192
private void write( ) {
186-
TypeElement gemElement = processingEnv.getElementUtils()
187-
.getTypeElement( "org.annotationhelper.GemDefinitions" );
188193
for ( GemInfo gemInfo : gemInfos ) {
189194
try (Writer writer = processingEnv.getFiler()
190-
.createSourceFile( gemInfo.getGemPackageName() + "." + gemInfo.getGemName(), gemElement )
195+
.createSourceFile(
196+
gemInfo.getGemPackageName() + "." + gemInfo.getGemName(),
197+
gemInfo.getOriginatingElements()
198+
)
191199
.openWriter()) {
192200
Configuration cfg = new Configuration( new Version( "2.3.21" ) );
193201
cfg.setClassForTemplateLoading( GemProcessor.class, "/" );

0 commit comments

Comments
 (0)