Merge branch 'kanchev1-fix-lombok-mapstruct-binding-handling-multiple-processor-rounds'

This commit is contained in:
Reinier Zwitserloot committed 2024-10-17 23:51:59 +02:00
commit 43d96ab699
3 files changed
+18 -27

No files matched your search

+1
View File
@@ -1,6 +1,7 @@
Lombok contributors in alphabetical order:
Adam Juraszek <juriad@gmail.com>
Aleksandar Kanchev <136312841+kanchev1@users.noreply.github.com>
Aleksandr Zhelezniak <lekan1992@gmail.com>
Amine Touzani <ttzn.dev@gmail.com>
Andre Brait <andrebrait@gmail.com>
@@ -1,34 +1,29 @@
package lombok.mapstruct;
import java.lang.reflect.Field;
import javax.lang.model.type.TypeMirror;
import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.type.TypeMirror;
import java.util.List;
/**
* Report to MapStruct that a type is completed when there aren't any Lombok annotations left on it. Lombok annotations
* are removed whenever a class is processed. This way, annotations which require multiple rounds to process are also
* correctly handled, and MapStruct processing will be delayed until Lombok completely finishes processing required types.
*/
class NotifierHider {
public static class AstModificationNotifier implements AstModifyingAnnotationProcessor {
private static Field lombokInvoked;
@Override public boolean isTypeComplete(TypeMirror type) {
@Override
public boolean isTypeComplete(TypeMirror typeMirror) {
if (System.getProperty("lombok.disable") != null) return true;
return isLombokInvoked();
}
private static boolean isLombokInvoked() {
if (lombokInvoked != null) {
try {
return lombokInvoked.getBoolean(null);
} catch (Exception e) {}
return true;
List<? extends AnnotationMirror> annotationMirrors = typeMirror.getAnnotationMirrors();
if (annotationMirrors == null || annotationMirrors.isEmpty()) return true;
for (AnnotationMirror annotationMirror : annotationMirrors) {
String annotationName = String.valueOf(annotationMirror);
if (annotationName.startsWith("@lombok.")) return false;
}
try {
Class<?> data = Class.forName("lombok.launch.AnnotationProcessorHider$AstModificationNotifierData");
lombokInvoked = data.getField("lombokInvoked");
return lombokInvoked.getBoolean(null);
} catch (Exception e) {}
return true;
}
}
@@ -39,10 +39,6 @@ import sun.misc.Unsafe;
class AnnotationProcessorHider {
public static class AstModificationNotifierData {
public volatile static boolean lombokInvoked = false;
}
public static class AnnotationProcessor extends AbstractProcessor {
private final AbstractProcessor instance = createWrappedInstance();
@@ -60,7 +56,6 @@ class AnnotationProcessorHider {
@Override public void init(ProcessingEnvironment processingEnv) {
disableJava9SillyWarning();
AstModificationNotifierData.lombokInvoked = true;
instance.init(processingEnv);
super.init(processingEnv);
}