Java Code Examples for lombok.javac.JavacNode#add()
The following examples show how to use
lombok.javac.JavacNode#add() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavacHandlerUtil.java From EasyMPermission with MIT License | 5 votes |
private static JavacNode injectField(JavacNode typeNode, JCVariableDecl field, boolean addGenerated) { JCClassDecl type = (JCClassDecl) typeNode.get(); if (addGenerated) { addSuppressWarningsAll(field.mods, typeNode, field.pos, getGeneratedBy(field), typeNode.getContext()); addGenerated(field.mods, typeNode, field.pos, getGeneratedBy(field), typeNode.getContext()); } List<JCTree> insertAfter = null; List<JCTree> insertBefore = type.defs; while (insertBefore.tail != null) { if (insertBefore.head instanceof JCVariableDecl) { JCVariableDecl f = (JCVariableDecl) insertBefore.head; if (isEnumConstant(f) || isGenerated(f)) { insertAfter = insertBefore; insertBefore = insertBefore.tail; continue; } } break; } List<JCTree> fieldEntry = List.<JCTree>of(field); fieldEntry.tail = insertBefore; if (insertAfter == null) { type.defs = fieldEntry; } else { insertAfter.tail = fieldEntry; } return typeNode.add(field, Kind.FIELD); }
Example 2
Source File: JavacHandlerUtil.java From EasyMPermission with MIT License | 5 votes |
/** * Adds the given new method declaration to the provided type AST Node. * Can also inject constructors. * * Also takes care of updating the JavacAST. */ public static void injectMethod(JavacNode typeNode, JCMethodDecl method) { JCClassDecl type = (JCClassDecl) typeNode.get(); if (method.getName().contentEquals("<init>")) { //Scan for default constructor, and remove it. int idx = 0; for (JCTree def : type.defs) { if (def instanceof JCMethodDecl) { if ((((JCMethodDecl)def).mods.flags & Flags.GENERATEDCONSTR) != 0) { JavacNode tossMe = typeNode.getNodeFor(def); if (tossMe != null) tossMe.up().removeChild(tossMe); type.defs = addAllButOne(type.defs, idx); if (type.sym != null && type.sym.members_field != null) { type.sym.members_field.remove(((JCMethodDecl)def).sym); } break; } } idx++; } } 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); }
Example 3
Source File: JavacHandlerUtil.java From EasyMPermission with MIT License | 5 votes |
/** * 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. * @return */ 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); }