Skip to content

Commit 0338705

Browse files
committed
Revert "[fixes #3116] Add multi round support for mapstruct":
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.
1 parent 3394b6e commit 0338705

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

AUTHORS

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
Lombok contributors in alphabetical order:
22

33
Adam Juraszek <juriad@gmail.com>
4-
Aleksandar Kanchev <136312841+kanchev1@users.noreply.github.com>
54
Aleksandr Zhelezniak <lekan1992@gmail.com>
65
Amine Touzani <ttzn.dev@gmail.com>
76
Andre Brait <andrebrait@gmail.com>

src/bindings/mapstruct/lombok/mapstruct/NotifierHider.java

+20-16
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
11
package lombok.mapstruct;
22

3-
import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor;
3+
import java.lang.reflect.Field;
44

5-
import javax.lang.model.element.AnnotationMirror;
65
import javax.lang.model.type.TypeMirror;
7-
import java.util.List;
86

9-
/**
10-
* Report to MapStruct that a type is completed when there aren't any Lombok annotations left on it. Lombok annotations
11-
* are removed whenever a class is processed. This way, annotations which require multiple rounds to process are also
12-
* correctly handled, and MapStruct processing will be delayed until Lombok completely finishes processing required types.
13-
*/
7+
import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor;
8+
149
class NotifierHider {
1510
public static class AstModificationNotifier implements AstModifyingAnnotationProcessor {
16-
@Override
17-
public boolean isTypeComplete(TypeMirror typeMirror) {
11+
private static Field lombokInvoked;
12+
13+
@Override public boolean isTypeComplete(TypeMirror type) {
1814
if (System.getProperty("lombok.disable") != null) return true;
19-
List<? extends AnnotationMirror> annotationMirrors = typeMirror.getAnnotationMirrors();
20-
if (annotationMirrors == null || annotationMirrors.isEmpty()) return true;
21-
22-
for (AnnotationMirror annotationMirror : annotationMirrors) {
23-
String annotationName = String.valueOf(annotationMirror);
24-
if (annotationName.startsWith("@lombok.")) return false;
15+
return isLombokInvoked();
16+
}
17+
18+
private static boolean isLombokInvoked() {
19+
if (lombokInvoked != null) {
20+
try {
21+
return lombokInvoked.getBoolean(null);
22+
} catch (Exception e) {}
23+
return true;
2524
}
2625

26+
try {
27+
Class<?> data = Class.forName("lombok.launch.AnnotationProcessorHider$AstModificationNotifierData");
28+
lombokInvoked = data.getField("lombokInvoked");
29+
return lombokInvoked.getBoolean(null);
30+
} catch (Exception e) {}
2731
return true;
2832
}
2933
}

src/launch/lombok/launch/AnnotationProcessor.java

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939

4040
class AnnotationProcessorHider {
4141

42+
public static class AstModificationNotifierData {
43+
public volatile static boolean lombokInvoked = false;
44+
}
45+
4246
public static class AnnotationProcessor extends AbstractProcessor {
4347
private final AbstractProcessor instance = createWrappedInstance();
4448

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

5761
@Override public void init(ProcessingEnvironment processingEnv) {
5862
disableJava9SillyWarning();
63+
AstModificationNotifierData.lombokInvoked = true;
5964
instance.init(processingEnv);
6065
super.init(processingEnv);
6166
}

0 commit comments

Comments
 (0)