aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2013-05-23 12:50:59 +0200
committerReinier Zwitserloot <reinier@zwitserloot.com>2013-06-16 13:20:53 +0200
commit4e521c558ed7355244dd1cb9c8d94bd5a9cb462d (patch)
treed3349b808f9b5aa07c0f5b27c484a98e2ce616d4 /src/core
parentbf43dc747791f9bbf953cfea8200fac478f62d80 (diff)
downloadlombok-4e521c558ed7355244dd1cb9c8d94bd5a9cb462d.tar.gz
lombok-4e521c558ed7355244dd1cb9c8d94bd5a9cb462d.tar.bz2
lombok-4e521c558ed7355244dd1cb9c8d94bd5a9cb462d.zip
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.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java21
-rw-r--r--src/core/lombok/javac/handlers/JavacHandlerUtil.java13
2 files changed, 34 insertions, 0 deletions
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");