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 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 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 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(); } };
@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); }
@NonNull @Override public Location resolve() { lombok.ast.Position pos = mNode.getPosition(); return Location.create(mFile, null /*contents*/, pos.getStart(), pos.getEnd()); }
@Override public boolean visitInstanceOf(InstanceOf node) { int start = posOfStructure(node, "instanceof", true); int end = node.getPosition().getEnd(); return set(node, setPos(start, end, treeMaker.TypeTest( toExpression(node.astObjectReference()), toExpression(node.astTypeReference())))); }
private List<JCCase> addCase(List<JCCase> cases, JCExpression currentPat, Node currentNode, List<JCStatement> stats) { JCStatement last = stats.last(); int start = currentNode.getPosition().getStart(); int end = last == null ? currentNode.getPosition().getEnd() : endPosTable.get(last); cases = cases.append(setPos(start, end, treeMaker.Case(currentPat, stats))); return cases; }
private List<JCCase> addCase(List<JCCase> cases, JCExpression currentPat, Node currentNode, List<JCStatement> stats) { JCStatement last = stats.last(); int start = currentNode.getPosition().getStart(); int end = last == null ? currentNode.getPosition().getEnd() : endPosTable.get(last); cases = cases.append(setPos(start, end, treeMaker.Case(currentPat, stats))); return cases; }
@Override public boolean visitSelect(Select node) { int start = posOfStructure(node.astIdentifier(), ".", true); int end = node.getPosition().getEnd(); return set(node, setPos(start, end, treeMaker.Select(toExpression(node.astOperand()), toName(node.astIdentifier())))); }
@Override public boolean visitInlineIfExpression(InlineIfExpression node) { int start = posOfStructure(node, "?", true); int end = node.getPosition().getEnd(); return set(node, setPos(start, end, treeMaker.Conditional( toExpression(node.astCondition()), toExpression(node.astIfTrue()), toExpression(node.astIfFalse())))); }
@Override public boolean visitAnnotation(Annotation node) { int start = node.getPosition().getStart(); int end = node.getPosition().getEnd(); // Newer javacs //int end = node.astAnnotationTypeReference().getPosition().getEnd(); // Older javacs return set(node, setPos(start, end, treeMaker.Annotation(toTree(node.astAnnotationTypeReference()), toList(JCExpression.class, node.astElements())))); }
@Override public boolean visitAnnotation(Annotation node) { int start = node.getPosition().getStart(); int end = node.getPosition().getEnd(); // Newer javacs //int end = node.astAnnotationTypeReference().getPosition().getEnd(); // Older javacs return set(node, setPos(start, end, treeMaker.Annotation(toTree(node.astAnnotationTypeReference()), toList(JCExpression.class, node.astElements())))); }
private JCExpression chain(Iterable<Identifier> parts) { JCExpression previous = null; for (Identifier part : parts) { Name next = toName(part); if (previous == null) { previous = setPos(part, treeMaker.Ident(next)); } else { previous = setPos(posOfStructure(part, ".", true), part.getPosition().getEnd(), treeMaker.Select(previous, next)); } } return previous; }
@Override public boolean visitImportDeclaration(ImportDeclaration node) { JCExpression name = chain(node.astParts()); if (node.astStarImport()) { int start, end; Position jcDotStarPos = getConversionPositionInfo(node, ".*"); start = jcDotStarPos == null ? posOfStructure(node, ".", true) : jcDotStarPos.getStart(); end = jcDotStarPos == null ? posOfStructure(node, "*", false) : jcDotStarPos.getEnd(); name = setPos(start, end, treeMaker.Select(name, table.asterisk)); } return posSet(node, treeMaker.Import(name, node.astStaticImport())); }
@Override public String process(Source source, Node in) throws ConversionProblem { SourceFormatter formatter = new TextFormatter(); in.accept(new SourcePrinter(formatter)); for (ParseProblem x : source.getProblems()) { formatter.addError(x.getPosition().getStart(), x.getPosition().getEnd(), x.getMessage()); } return formatter.finish(); } };
@Override public String process(Source source, Node in) throws ConversionProblem { SourceFormatter formatter = new HtmlFormatter(source.getRawInput()); in.accept(new SourcePrinter(formatter)); for (ParseProblem x : source.getProblems()) { formatter.addError(x.getPosition().getStart(), x.getPosition().getEnd(), x.getMessage()); } return formatter.finish(); } };
@Override public String process(Source source, Node in) throws ConversionProblem { SourceFormatter formatter = new HtmlFormatter(source.getRawInput()); in.accept(new SourcePrinter(formatter)); for (ParseProblem x : source.getProblems()) { formatter.addError(x.getPosition().getStart(), x.getPosition().getEnd(), x.getMessage()); } return formatter.finish(); } };
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())); }
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)); }