aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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");