diff options
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | src/core/lombok/javac/handlers/JavacHandlerUtil.java | 24 | ||||
-rw-r--r-- | src/delombok/lombok/delombok/FormatPreferences.java | 7 |
3 files changed, 31 insertions, 1 deletions
@@ -9,6 +9,7 @@ Robbert Jan Grootjans <grootjans@gmail.com> Roel Spilker <r.spilker@gmail.com> Sander Koning <askoning@gmail.com> Taiki Sugawara <buzz.taiki@gmail.com> +Peter Grant <petercgrant@users.noreply.github.com> By adding your name to this list, you grant full and irrevocable copyright and patent indemnity to Project Lombok and all use of Project Lombok, and you certify that you have the right to do so for all commits you add to Project Lombok. diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java index 8a8c5acd..bf364641 100644 --- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java +++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java @@ -893,6 +893,7 @@ public class JavacHandlerUtil { } addSuppressWarningsAll(method.mods, typeNode, method.pos, getGeneratedBy(method), typeNode.getContext()); + addGenerated(method.mods, typeNode, method.pos, getGeneratedBy(method), typeNode.getContext()); type.defs = type.defs.append(method); typeNode.add(method, Kind.METHOD); @@ -908,6 +909,7 @@ public class JavacHandlerUtil { public static JavacNode injectType(JavacNode typeNode, final JCClassDecl type) { JCClassDecl typeDecl = (JCClassDecl) typeNode.get(); addSuppressWarningsAll(type.mods, typeNode, type.pos, getGeneratedBy(type), typeNode.getContext()); + addGenerated(type.mods, typeNode, type.pos, getGeneratedBy(type), typeNode.getContext()); typeDecl.defs = typeDecl.defs.append(type); return typeNode.add(type, Kind.TYPE); } @@ -965,7 +967,27 @@ public class JavacHandlerUtil { annotation.pos = pos; mods.annotations = mods.annotations.append(annotation); } - + + public static void addGenerated(JCModifiers mods, JavacNode node, int pos, JCTree source, Context context) { + if (!LombokOptionsFactory.getDelombokOptions(context).getFormatPreferences().generateGenerated()) return; + for (JCAnnotation ann : mods.annotations) { + JCTree annType = ann.getAnnotationType(); + Name lastPart = null; + if (annType instanceof JCIdent) lastPart = ((JCIdent) annType).name; + else if (annType instanceof JCFieldAccess) lastPart = ((JCFieldAccess) annType).name; + + if (lastPart != null && lastPart.contentEquals("Generated")) return; + } + JavacTreeMaker maker = node.getTreeMaker(); + JCExpression generatedType = chainDots(node, "javax", "annotation", "Generated"); + JCExpression lombokLiteral = maker.Literal("lombok"); + generatedType.pos = pos; + lombokLiteral.pos = pos; + JCAnnotation annotation = recursiveSetGeneratedBy(maker.Annotation(generatedType, List.<JCExpression>of(lombokLiteral)), source, context); + annotation.pos = pos; + mods.annotations = mods.annotations.append(annotation); + } + private static List<JCTree> addAllButOne(List<JCTree> defs, int idx) { ListBuffer<JCTree> out = new ListBuffer<JCTree>(); int i = 0; diff --git a/src/delombok/lombok/delombok/FormatPreferences.java b/src/delombok/lombok/delombok/FormatPreferences.java index 9bd668a5..caacc246 100644 --- a/src/delombok/lombok/delombok/FormatPreferences.java +++ b/src/delombok/lombok/delombok/FormatPreferences.java @@ -33,6 +33,7 @@ public final class FormatPreferences { private final boolean generateConstructorProperties; private final boolean generateSuppressWarnings, danceAroundIdeChecks, generateDelombokComment, javaLangAsFqn; final Map<String, String> rawMap; + private final boolean generateGenerated; static final Map<String, String> KEYS; @@ -46,6 +47,7 @@ public final class FormatPreferences { keys.put("danceAroundIdeChecks", "Either 'generate' or 'skip'. generate means: Lombok will intentionally obfuscate some generated code to avoid IDE warnings. Default: 'generate'"); keys.put("generateDelombokComment", "Either 'generate' or 'skip'. generate means: Any file modified by delombok will have a comment stating this at the top. Default: 'generate'"); keys.put("javaLangAsFQN", "Either 'generate' or 'skip'. generate means: Any generated reference to java.lang classes are prefixed with `java.lang.`. Default: 'generate'"); + keys.put("generated", "Either 'generate' or 'skip'. generate means: All lombok-generated methods get a @Generated(\"lombok\") annotation. Default: 'generate'"); KEYS = Collections.unmodifiableMap(keys); } @@ -85,6 +87,7 @@ public final class FormatPreferences { this.danceAroundIdeChecks = unrollBoolean(preferences, "danceAroundIdeChecks", "generate", "skip", true); this.generateDelombokComment = unrollBoolean(preferences, "generateDelombokComment", "generate", "skip", true); this.javaLangAsFqn = unrollBoolean(preferences, "javaLangAsFQN", "generate", "skip", true); + this.generateGenerated = unrollBoolean(preferences, "generated", "generate", "skip", true); } private static boolean unrollBoolean(Map<String, String> preferences, String name, String trueStr, String falseStr, boolean defaultVal) { @@ -131,4 +134,8 @@ public final class FormatPreferences { public boolean generateConstructorProperties() { return generateConstructorProperties; } + + public boolean generateGenerated() { + return generateGenerated; + } } |