-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fixes #3116] Add multi round support for mapstruct
- Loading branch information
Showing
3 changed files
with
24 additions
and
26 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
44 changes: 23 additions & 21 deletions
44
src/bindings/mapstruct/lombok/mapstruct/NotifierHider.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 |
---|---|---|
@@ -1,35 +1,37 @@ | ||
package lombok.mapstruct; | ||
|
||
import java.lang.reflect.Field; | ||
import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; | ||
|
||
import javax.lang.model.element.AnnotationMirror; | ||
import javax.lang.model.type.TypeMirror; | ||
import java.util.List; | ||
|
||
import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; | ||
|
||
/** | ||
* 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) { | ||
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) {} | ||
|
||
@Override | ||
public boolean isTypeComplete(final TypeMirror typeMirror) { | ||
final List<? extends AnnotationMirror> annotationMirrors = typeMirror.getAnnotationMirrors(); | ||
if (annotationMirrors == null || annotationMirrors.isEmpty()) { | ||
return true; | ||
} | ||
|
||
try { | ||
Class<?> data = Class.forName("lombok.launch.AnnotationProcessorHider$AstModificationNotifierData"); | ||
lombokInvoked = data.getField("lombokInvoked"); | ||
return lombokInvoked.getBoolean(null); | ||
} catch (Exception e) {} | ||
|
||
for (final AnnotationMirror annotationMirror : annotationMirrors) { | ||
final String annotationName = String.valueOf(annotationMirror); | ||
// check for ClaimingProcessor's SupportedAnnotationTypes | ||
if (annotationName.startsWith("@lombok.")) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
|
||
} | ||
} | ||
} |
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