From 4e521c558ed7355244dd1cb9c8d94bd5a9cb462d Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Thu, 23 May 2013 12:50:59 +0200 Subject: Added injectType methods to Eclipse/JavacHandlerUtil, which we'll need to inject the created $Builder type. Inspired by Philipp Eichhorn's work in lombok-pg. --- .../lombok/eclipse/handlers/EclipseHandlerUtil.java | 21 +++++++++++++++++++++ .../lombok/javac/handlers/JavacHandlerUtil.java | 13 +++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java index dc99dabf..f9295150 100644 --- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java +++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java @@ -1289,6 +1289,27 @@ public class EclipseHandlerUtil { type.add(method, Kind.METHOD); } + /** + * Adds an inner type (class, interface, enum) to the given type. Cannot inject top-level types. + * + * @param typeNode parent type to inject new type into + * @param type New type (class, interface, etc) to inject. + */ + public static void injectType(final EclipseNode typeNode, final TypeDeclaration type) { + type.annotations = createSuppressWarningsAll(type, type.annotations); + TypeDeclaration parent = (TypeDeclaration) typeNode.get(); + + if (parent.memberTypes == null) { + parent.memberTypes = new TypeDeclaration[] { type }; + } else { + TypeDeclaration[] newArray = new TypeDeclaration[parent.memberTypes.length + 1]; + System.arraycopy(parent.memberTypes, 0, newArray, 0, parent.memberTypes.length); + newArray[parent.memberTypes.length] = type; + parent.memberTypes = newArray; + } + typeNode.add(type, Kind.TYPE); + } + private static final char[] ALL = "all".toCharArray(); public static Annotation[] createSuppressWarningsAll(ASTNode source, Annotation[] originalAnnotationArray) { diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java index 7cbaa5ac..2577befb 100644 --- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java +++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java @@ -801,6 +801,19 @@ public class JavacHandlerUtil { typeNode.add(method, Kind.METHOD); } + /** + * Adds an inner type (class, interface, enum) to the given type. Cannot inject top-level types. + * + * @param typeNode parent type to inject new type into + * @param type New type (class, interface, etc) to inject. + */ + public static void injectType(final JavacNode typeNode, final JCClassDecl type) { + JCClassDecl typeDecl = (JCClassDecl) typeNode.get(); + addSuppressWarningsAll(type.mods, typeNode, type.pos, getGeneratedBy(type)); + typeDecl.defs = typeDecl.defs.append(type); + typeNode.add(type, Kind.TYPE); + } + private static void addSuppressWarningsAll(JCModifiers mods, JavacNode node, int pos, JCTree source) { TreeMaker maker = node.getTreeMaker(); JCExpression suppressWarningsType = chainDots(node, "java", "lang", "SuppressWarnings"); -- cgit