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.
This commit is contained in:
Reinier Zwitserloot committed 2013-06-16 13:20:53 +02:00
1 parent bf43dc7477
commit 4e521c558e
2 files changed
+34

No files matched your search

@@ -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) {
@@ -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");