public static CompilationUnit upToTop(Node node) { while (node != null && !(node instanceof CompilationUnit)) node = node.getParent(); return (CompilationUnit) node; } }
public T finish() { node.accept(visitor); return node; } }
/** * Sets the position of {@code node} to {@code position}, and then does the same for all of {@code node}'s children, recursively. */ public static Node setAllPositions(Node node, Position position) { node.setPosition(position); for (Node child : node.getChildren()) setAllPositions(child, position); return node; }
@Override public boolean visitNode(Node node) { if (node.isGenerated()) return false; int startPos = node.getPosition().getStart(); Node current = startPosMap.get(startPos); if (current == null || !(current instanceof JavadocContainer)) { startPosMap.put(startPos, node); } return false; } });
private void addToMap(Node positionNode, Node linked) { if (positionNode == null) return; int start = positionNode.getPosition().getStart(); if (start == -1) return; if (linked instanceof JavadocContainer || !nodePositions.containsKey(start)) { nodePositions.put(start, linked); } }
private void checkStaticChain(Modifiers modifiers) { if (!modifiers.isStatic()) return; Node p = modifiers.getParent(); while (p != null) { if (p instanceof CompilationUnit) return; if (p instanceof TypeDeclaration) { Modifiers pMods = ((TypeDeclaration)p).astModifiers(); if (!pMods.isStatic()) { modifiers.getParent().addMessage(error(MODIFIERS_STATIC_CHAIN, "This declaration is (effectively) static; static declarations or only legal in top-level and static declarations.")); } } p = p.getParent(); } }
return null; Node parent = sibling.getParent(); if (parent == null) { return null; Iterator<Node> iterator = parent.getChildren().iterator(); while (iterator.hasNext()) { if (iterator.next() == sibling) {
for (lombok.ast.Node rootNode : compilationUnit.getChildren()) { if (rootNode instanceof ImportDeclaration) { ImportDeclaration importDeclaration = (ImportDeclaration) rootNode;
private void checkDeclarationsAsDirectChild(Node n, Node c) { if (c instanceof VariableDeclaration) { c.addMessage(error(DECLARATION_NOT_ALLOWED, "Variable declarations only make sense in the context of a block.")); } if (c instanceof TypeDeclaration) { c.addMessage(error(DECLARATION_NOT_ALLOWED, "Type declarations only make sense in the context of a block or other type.")); } }
private <N extends lombok.ast.Node> N setPosition(ASTNode node, N lombokNode) { lombokNode.setPosition(toPosition(node.sourceStart, node.sourceEnd)); return lombokNode; }
/** * NB: Do not simply pass the result of {@code parseX} to this method; parsing is extremely slow. Instead, parse a template once, * and then pass this one result every time. The template will never modify the original. */ @SuppressWarnings("unchecked") public static <N extends Node> Template<N> of(N source) throws AstException { return new Template<N>((N) source.copy()); }
@Override public boolean replace(Node replacement) throws AstException { if (this.getParent() == null) return false; return this.parent.replaceChild(this, replacement); }
@Override public void unparent() { if (this.parent != null) this.parent.detach(this); }
private void addToMap(Node positionNode, Node linked) { if (positionNode == null) return; int start = positionNode.getPosition().getStart(); if (start == -1) return; if (linked instanceof JavadocContainer || !nodePositions.containsKey(start)) { nodePositions.put(start, linked); } }
private void checkStaticChain(Modifiers modifiers) { if (!modifiers.isStatic()) return; Node p = modifiers.getParent(); while (p != null) { if (p instanceof CompilationUnit) return; if (p instanceof TypeDeclaration) { Modifiers pMods = ((TypeDeclaration)p).astModifiers(); if (!pMods.isStatic()) { modifiers.getParent().addMessage(error(MODIFIERS_STATIC_CHAIN, "This declaration is (effectively) static; static declarations or only legal in top-level and static declarations.")); } } p = p.getParent(); } }
Node parent = node.getParent(); if (parent instanceof Select) { Node grandParent = parent.getParent(); if (grandParent instanceof Select) { Select select = (Select) grandParent; Statement statement = getParentOfType(argument, Statement.class, false); if (statement != null) { ListIterator<Node> iterator = statement.getParent().getChildren().listIterator(); while (iterator.hasNext()) { if (iterator.next() == statement) {
@Override public boolean visitNode(Node node) { if (node.isGenerated()) return false; int startPos = node.getPosition().getStart(); Node current = startPosMap.get(startPos); if (current == null || !(current instanceof JavadocContainer)) { startPosMap.put(startPos, node); } return false; } });
for (lombok.ast.Node subclass : body.getChildren()) { if (subclass instanceof ClassDeclaration) { String className = ((ClassDeclaration) subclass).astName().astValue(); for (lombok.ast.Node innerBody : subclass.getChildren()) { if (innerBody instanceof NormalTypeBody) { for (lombok.ast.Node field : innerBody.getChildren()) { if (field instanceof VariableDeclaration) { for (lombok.ast.Node child : field.getChildren()) { if (child instanceof VariableDefinition) { VariableDefinition def =
private void checkDeclarationsAsDirectChild(Node n, Node c) { if (c instanceof VariableDeclaration) { c.addMessage(error(DECLARATION_NOT_ALLOWED, "Variable declarations only make sense in the context of a block.")); } if (c instanceof TypeDeclaration) { c.addMessage(error(DECLARATION_NOT_ALLOWED, "Type declarations only make sense in the context of a block or other type.")); } }
<T extends Node> T posify(T node) { int start = startPos(); int end = Math.max(start, currentPos()); node.setPosition(new Position(start, end)); return node; }