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 <N extends Node> N setPos(JCTree node, N astNode) { if (astNode != null && node != null) { int start = node.pos; Integer end_ = endPosTable.get(node); if (node instanceof JCUnary) end_ = node.getEndPosition(endPosTable); int end = end_ == null ? node.getEndPosition(endPosTable) : end_; if (start != com.sun.tools.javac.util.Position.NOPOS && end != com.sun.tools.javac.util.Position.NOPOS) { astNode.setPosition(new Position(start, end)); } } return astNode; }
<T extends Node> T posify(T node) { int start = startPos(); int end = Math.max(start, currentPos()); node.setPosition(new Position(start, end)); return node; }
private <N extends Node> N setPos(JCTree node, N astNode) { if (astNode != null && node != null) { int start = node.pos; Integer end_ = endPosTable.get(node); if (node instanceof JCUnary) end_ = node.getEndPosition(endPosTable); int end = end_ == null ? node.getEndPosition(endPosTable) : end_; if (start != com.sun.tools.javac.util.Position.NOPOS && end != com.sun.tools.javac.util.Position.NOPOS) { astNode.setPosition(new Position(start, end)); } } return astNode; }
public boolean logBlockComment(String text) { if (text.startsWith("/*")) text = text.substring(2); if (text.endsWith("*/")) text = text.substring(0, text.length() - 2); Comment c = new Comment().astBlockComment(true).astContent(text); c.setPosition(new Position(startPos(), currentPos())); source.registerComment(getContext(), c); return true; }
Identifier createIdentifierIfNeeded(Node identifier, int pos) { if (identifier instanceof Identifier) return (Identifier)identifier; Identifier i = new Identifier(); i.setPosition(new Position(pos, pos)); DanglingNodes.addDanglingNode(i, identifier); return i; }
void positionSpan(Node target, org.parboiled.Node<Node> start, org.parboiled.Node<Node> end) { if (target == null || start == null || end == null) return; target.setPosition(new Position(start.getStartIndex(), end.getEndIndex())); } }
void positionSpan(Node target, org.parboiled.Node<Node> start, org.parboiled.Node<Node> end) { if (target == null || start == null || end == null) return; target.setPosition(new Position(start.getStartIndex(), end.getEndIndex())); } }
Modifiers createModifiersIfNeeded(Node modifiers, int pos) { if (modifiers instanceof Modifiers) return (Modifiers)modifiers; Modifiers m = new Modifiers(); m.setPosition(new Position(pos, pos)); DanglingNodes.addDanglingNode(m, modifiers); return m; }
public boolean logBlockComment(String text) { if (text.startsWith("/*")) text = text.substring(2); if (text.endsWith("*/")) text = text.substring(0, text.length() - 2); Comment c = new Comment().astBlockComment(true).astContent(text); c.setPosition(new Position(startPos(), currentPos())); source.registerComment(getContext(), c); return true; }
public Node createIdentifier(String text, org.parboiled.Node<Node> rawIdentifier) { Identifier id = new Identifier(); if (text != null) id.astValue(text); int start = rawIdentifier.getStartIndex(); int end = Math.max(start, rawIdentifier.getEndIndex()); id.setPosition(new Position(start, end)); return id; }
public Node createIdentifier(String text, org.parboiled.Node<Node> rawIdentifier) { Identifier id = new Identifier(); if (text != null) id.astValue(text); int start = rawIdentifier.getStartIndex(); int end = Math.max(start, rawIdentifier.getEndIndex()); id.setPosition(new Position(start, end)); return id; }
public Node createDimension(Node dimExpr, org.parboiled.Node<Node> arrayOpen) { ArrayDimension d = new ArrayDimension().rawDimension(dimExpr); if (arrayOpen != null) d.setPosition(new Position(arrayOpen.getStartIndex(), currentPos())); return d; }
public Node createDimension(Node dimExpr, org.parboiled.Node<Node> arrayOpen) { ArrayDimension d = new ArrayDimension().rawDimension(dimExpr); if (arrayOpen != null) d.setPosition(new Position(arrayOpen.getStartIndex(), currentPos())); return d; }
private lombok.ast.Modifiers toModifiers(int modifiers, Annotation[] annotations, int start, int end) { lombok.ast.Modifiers m = new lombok.ast.Modifiers(); for (KeywordModifier mod : KeywordModifier.fromReflectModifiers(modifiers)) m.astKeywords().addToEnd(mod); fillList(annotations, m.rawAnnotations()); m.setPosition(new Position(start, end)); return m; }
@Override public void visitAnnotationMethodDeclaration(AnnotationMethodDeclaration node) { lombok.ast.AnnotationMethodDeclaration decl = new lombok.ast.AnnotationMethodDeclaration(); decl.astMethodName(toIdentifier(node.selector, node.sourceStart, node.sourceEnd)); decl.astJavadoc((lombok.ast.Comment) toTree(node.javadoc)); decl.astModifiers(toModifiers(node.modifiers, node.annotations, node.modifiersSourceStart, node.declarationSourceStart)); decl.astReturnTypeReference((lombok.ast.TypeReference) toTree(node.returnType)); decl.astDefaultValue((lombok.ast.Expression) toTree(node.defaultValue)); setConversionPositionInfo(decl, "signature", toPosition(node.sourceStart, node.sourceEnd)); setConversionPositionInfo(decl, "extendedDimensions", new Position(node.extendedDimensions, -1)); decl.setPosition(toPosition(node.declarationSourceStart, node.declarationSourceEnd)); set(node, decl); }
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 createAnnotationDeclaration(Node modifiers, Node name, List<Node> members, org.parboiled.Node<Node> typeOpen, org.parboiled.Node<Node> typeClose) { Node typeBody = createNormalTypeBody(members); if (typeOpen != null && typeClose != null) { typeBody.setPosition(new Position(typeOpen.getStartIndex(), typeClose.getEndIndex())); } AnnotationDeclaration decl = new AnnotationDeclaration().astName(createIdentifierIfNeeded(name, currentPos())).rawBody(typeBody); if (modifiers != null) decl.astModifiers(createModifiersIfNeeded(modifiers, currentPos())); return posify(decl); }
public Node createAnnotationDeclaration(Node modifiers, Node name, List<Node> members, org.parboiled.Node<Node> typeOpen, org.parboiled.Node<Node> typeClose) { Node typeBody = createNormalTypeBody(members); if (typeOpen != null && typeClose != null) { typeBody.setPosition(new Position(typeOpen.getStartIndex(), typeClose.getEndIndex())); } AnnotationDeclaration decl = new AnnotationDeclaration().astName(createIdentifierIfNeeded(name, currentPos())).rawBody(typeBody); if (modifiers != null) decl.astModifiers(createModifiersIfNeeded(modifiers, currentPos())); return posify(decl); }
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)); }