From 5a5f465a0433bef33ddb1260c338b26e1598501c Mon Sep 17 00:00:00 2001 From: Peter Grant Date: Mon, 26 Jan 2015 13:41:07 -0800 Subject: [i623] Added javac impl of javax.annotation.Generated --- .../lombok/javac/handlers/JavacHandlerUtil.java | 24 +++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/core') 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.of(lombokLiteral)), source, context); + annotation.pos = pos; + mods.annotations = mods.annotations.append(annotation); + } + private static List addAllButOne(List defs, int idx) { ListBuffer out = new ListBuffer(); int i = 0; -- cgit