@Override public boolean visitNode(Node node) { Position p = node.getPosition(); if (p.isUnplaced()) return false; int trimmed = Math.min(whitespace.length, p.getEnd()); while (trimmed > 0 && whitespace[trimmed-1]) trimmed--; int start, end; if (p.getEnd() - p.getStart() == 0) { if (node.getParent() != null) { start = Math.min(node.getParent().getPosition().getEnd(), Math.max(node.getParent().getPosition().getStart(), p.getStart())); end = start; } else { start = p.getStart(); end = start; } } else { start = p.getStart(); end = Math.max(trimmed, start); } node.setPosition(new Position(start, end)); return false; } });
@Override public boolean isGenerated() { return position.getGeneratedBy() != null; }
private boolean isUndocumented(lombok.ast.Node block) { if (block == null) return false; if (rawInput == null) return false; lombok.ast.Position pos = block.getPosition(); if (pos.isUnplaced() || pos.size() < 3) return true; String content = rawInput.substring(pos.getStart() + 1, pos.getEnd() - 1); return content.trim().isEmpty(); } };
private void posParen(Node node, int iteration, java.util.List<Position> parenPositions, JCTree jcTree) { Position p = null; if (parenPositions.size() > iteration) p = parenPositions.get(iteration); int start = (p == null || p.isUnplaced() || p.getStart() < 0) ? node.getPosition().getStart() - 1 - iteration : p.getStart(); int end = (p == null || p.isUnplaced() || p.getEnd() < 0) ? node.getPosition().getEnd() + 1 + iteration : p.getEnd(); setPos(start, end, jcTree); }
private static <T extends ASTNode> T posParen(T in, lombok.ast.Node node) { if (in == null) return null; if (node instanceof lombok.ast.Expression) { List<Position> parensPositions = ((lombok.ast.Expression)node).astParensPositions(); if (!parensPositions.isEmpty()) { in.sourceStart = parensPositions.get(parensPositions.size() - 1).getStart(); in.sourceEnd = parensPositions.get(parensPositions.size() - 1).getEnd() - 1; } } return in; }
public Node createCatch(Node modifiers, Node type, Node varName, Node body) { VariableDefinitionEntry varNameEntry = new VariableDefinitionEntry().astName(createIdentifierIfNeeded(varName, currentPos())); if (varName != null) varNameEntry.setPosition(varName.getPosition()); VariableDefinition decl = new VariableDefinition().rawTypeReference(type).rawVariables().addToEnd( varNameEntry); if (type != null && varName != null) decl.setPosition(new Position(type.getPosition().getStart(), varName.getPosition().getEnd())); if (modifiers != null) decl.astModifiers(createModifiersIfNeeded(modifiers, currentPos())); return posify(new Catch().rawExceptionDeclaration(decl).rawBody(body)); }
public Node createUnaryPostfixExpression(Node operand, List<org.parboiled.Node<Node>> nodes, List<String> operators) { if (operators == null) return operand; Node current = operand; for (int i = 0; i < operators.size(); i++) { String op = operators.get(i); if (op == null) continue; op = op.trim(); Node prev = current; if (op.equals("++")) current = new UnaryExpression().rawOperand(current).astOperator(UnaryOperator.POSTFIX_INCREMENT); else if (op.equals("--")) current = new UnaryExpression().rawOperand(current).astOperator(UnaryOperator.POSTFIX_DECREMENT); org.parboiled.Node<Node> p = nodes.get(i); if (prev != null && !prev.getPosition().isUnplaced() && p != null) { current.setPosition(new Position(prev.getPosition().getStart(), p.getEndIndex())); } } return current; }
private static int start(lombok.ast.Node node) { if (node == null || node.getPosition().isUnplaced()) return 0; return node.getPosition().getStart(); }
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 Position getPosition(JCTree node) { if (node == null) return Position.UNPLACED; int start = node.pos; Integer end_ = null; if (endPosTable != null) end_ = endPosTable.get(node); int end = end_ == null ? node.getEndPosition(endPosTable) : end_; return new Position(start, end); }
private static int end(lombok.ast.Node node) { if (node == null || node.getPosition().isUnplaced()) return 0; return node.getPosition().getEnd() - 1; }
@Override public boolean visitVariableDeclaration(VariableDeclaration node) { List<JCVariableDecl> list = toList(JCVariableDecl.class, node.astDefinition()); JCVariableDecl last = list.get(list.size() -1); endPosTable.put(last, node.getPosition().getEnd()); return set(list); }
public Node createTypeReferencePart(org.parboiled.Node<Node> identifier, Node typeArguments) { TypeReferencePart result = new TypeReferencePart().astIdentifier(createIdentifierIfNeeded(identifier.getValue(), currentPos())); if (typeArguments instanceof TemporaryNode.TypeArguments) { for (Node arg : ((TemporaryNode.TypeArguments)typeArguments).arguments) { result.rawTypeArguments().addToEnd(arg); } } posify(result); //We only care about the end position here. return result.setPosition(new Position(identifier.getStartIndex(), result.getPosition().getEnd())); }
private void set(JCTree node, Node value) { if (result != null) throw new IllegalStateException("result is already set"); if (value != null && value.getPosition().isUnplaced()) setPos(node, value); java.util.List<Node> result = Lists.newArrayList(); if (value != null) result.add(value); this.result = result; }
@Override public void visitStringLiteralConcatenation(StringLiteralConcatenation node) { Node lombokAggregator = null; if (node.literals != null) { for (int i = 0; i < node.counter; i++) { Node lombokElemNode = toTree(node.literals[i]); if (lombokAggregator != null) { Position newPos = lombokElemNode.getPosition().withoutGeneratedBy(); lombokAggregator = new lombok.ast.BinaryExpression().astOperator(BinaryOperator.PLUS) .rawLeft(lombokAggregator).rawRight(lombokElemNode); lombokAggregator.setPosition(newPos); } else { lombokAggregator = lombokElemNode; } } } set(node, setPosition(node, lombokAggregator)); }
private static <T extends ASTNode> T posParen(T in, lombok.ast.Node node) { if (in == null) return null; if (node instanceof lombok.ast.Expression) { List<Position> parensPositions = ((lombok.ast.Expression)node).astParensPositions(); if (!parensPositions.isEmpty()) { in.sourceStart = parensPositions.get(parensPositions.size() - 1).getStart(); in.sourceEnd = parensPositions.get(parensPositions.size() - 1).getEnd() - 1; } } return in; }
private boolean isUndocumented(lombok.ast.Node block) { if (block == null) return false; if (rawInput == null) return false; lombok.ast.Position pos = block.getPosition(); if (pos.isUnplaced() || pos.size() < 3) return true; String content = rawInput.substring(pos.getStart() + 1, pos.getEnd() - 1); return content.trim().isEmpty(); } };
private void posParen(Node node, int iteration, java.util.List<Position> parenPositions, JCTree jcTree) { Position p = null; if (parenPositions.size() > iteration) p = parenPositions.get(iteration); int start = (p == null || p.isUnplaced() || p.getStart() < 0) ? node.getPosition().getStart() - 1 - iteration : p.getStart(); int end = (p == null || p.isUnplaced() || p.getEnd() < 0) ? node.getPosition().getEnd() + 1 + iteration : p.getEnd(); setPos(start, end, jcTree); }
public Node createCatch(Node modifiers, Node type, Node varName, Node body) { VariableDefinitionEntry varNameEntry = new VariableDefinitionEntry().astName(createIdentifierIfNeeded(varName, currentPos())); if (varName != null) varNameEntry.setPosition(varName.getPosition()); VariableDefinition decl = new VariableDefinition().rawTypeReference(type).rawVariables().addToEnd( varNameEntry); if (type != null && varName != null) decl.setPosition(new Position(type.getPosition().getStart(), varName.getPosition().getEnd())); if (modifiers != null) decl.astModifiers(createModifiersIfNeeded(modifiers, currentPos())); return posify(new Catch().rawExceptionDeclaration(decl).rawBody(body)); }