Skip to content

Commit

Permalink
Revert "[fixes #3116] Add multi round support for mapstruct":
Browse files Browse the repository at this point in the history
This reverts commit 04c9755.

The nature of the fix is to simply scan the TypeMirror for 'lombok shenanigans'; if it finds them, the type is not complete; if there are none, the type is.

This fundamentally does not work - lombok shenanigans may remain even if lombok is done (`@lombok.NonNull` for example), and lombok shenanigans don't just appear as annotations on the type; they can appear in many forms: Annotations on local var decls, or even method calls to `Lombok.safeDeNull` or whatnot. safeDenull is made up, but we might add it someday. `@Getter` on a field isn't though, and suffers from the same problem.
  • Loading branch information
rzwitserloot committed Nov 15, 2024
1 parent 3394b6e commit 0338705
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
1 change: 0 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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>
Expand Down
36 changes: 20 additions & 16 deletions src/bindings/mapstruct/lombok/mapstruct/NotifierHider.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
package lombok.mapstruct;

import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor;
import java.lang.reflect.Field;

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.
*/
import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor;

class NotifierHider {
public static class AstModificationNotifier implements AstModifyingAnnotationProcessor {
@Override
public boolean isTypeComplete(TypeMirror typeMirror) {
private static Field lombokInvoked;

@Override public boolean isTypeComplete(TypeMirror type) {
if (System.getProperty("lombok.disable") != null) 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;
return isLombokInvoked();
}

private static boolean isLombokInvoked() {
if (lombokInvoked != null) {
try {
return lombokInvoked.getBoolean(null);
} catch (Exception e) {}
return true;
}

try {
Class<?> data = Class.forName("lombok.launch.AnnotationProcessorHider$AstModificationNotifierData");
lombokInvoked = data.getField("lombokInvoked");
return lombokInvoked.getBoolean(null);
} catch (Exception e) {}
return true;
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/launch/lombok/launch/AnnotationProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@

class AnnotationProcessorHider {

public static class AstModificationNotifierData {
public volatile static boolean lombokInvoked = false;
}

public static class AnnotationProcessor extends AbstractProcessor {
private final AbstractProcessor instance = createWrappedInstance();

Expand All @@ -56,6 +60,7 @@ public static class AnnotationProcessor extends AbstractProcessor {

@Override public void init(ProcessingEnvironment processingEnv) {
disableJava9SillyWarning();
AstModificationNotifierData.lombokInvoked = true;
instance.init(processingEnv);
super.init(processingEnv);
}
Expand Down

0 comments on commit 0338705

Please sign in to comment.