/** * Returns start column of the given sub-{@code Tree} of this object's * {@code CompilationUnitTree}, climbing the associated {@code TreePath} until a value other than * {@link javax.tools.Diagnostic.NOPOS} is found. * * <p>This method will return {@link javax.tools.Diagnostic.NOPOS} if that value is returned * by a call to {@link SourcePositions#getStartPosition} for every node in the {@link TreePath} * provided. * * @throws IllegalArgumentException if the node provided is not a sub-{@code Tree} of this * object's {@code CompilationUnitTree}. */ long getNodeStartColumn(Tree node) { long startPosition = getNodeStartPosition(node); return startPosition == NOPOS ? NOPOS : lineMap.getColumnNumber(startPosition); }
/** * Returns end column of the given sub-{@code Tree} of this object's {@code CompilationUnitTree}. * climbing the associated {@code TreePath} until a value other than * {@link javax.tools.Diagnostic.NOPOS} is found. * * <p>This method will return {@link javax.tools.Diagnostic.NOPOS} if that value is returned * by a call to {@link SourcePositions#getEndPosition} for every node in the {@link TreePath} * provided. * * @throws IllegalArgumentException if the node provided is not a sub-{@code Tree} of this * object's {@code CompilationUnitTree}. */ long getNodeEndColumn(Tree node) { long endPosition = getNodeEndPosition(node); return endPosition == NOPOS ? NOPOS : lineMap.getColumnNumber(endPosition); }
/** * Returns start column of the given sub-{@code Tree} of this object's * {@code CompilationUnitTree}, climbing the associated {@code TreePath} until a value other than * {@link javax.tools.Diagnostic.NOPOS} is found. * * <p>This method will return {@link javax.tools.Diagnostic.NOPOS} if that value is returned * by a call to {@link SourcePositions#getStartPosition} for every node in the {@link TreePath} * provided. * * @throws IllegalArgumentException if the node provided is not a sub-{@code Tree} of this * object's {@code CompilationUnitTree}. */ long getNodeStartColumn(Tree node) { long startPosition = getNodeStartPosition(node); return startPosition == NOPOS ? NOPOS : lineMap.getColumnNumber(startPosition); }
/** * Returns start column of the given sub-{@code Tree} of this object's * {@code CompilationUnitTree}, climbing the associated {@code TreePath} until a value other than * {@link javax.tools.Diagnostic.NOPOS} is found. * * <p>This method will return {@link javax.tools.Diagnostic.NOPOS} if that value is returned * by a call to {@link SourcePositions#getStartPosition} for every node in the {@link TreePath} * provided. * * @throws IllegalArgumentException if the node provided is not a sub-{@code Tree} of this * object's {@code CompilationUnitTree}. */ long getNodeStartColumn(Tree node) { long startPosition = getNodeStartPosition(node); return startPosition == NOPOS ? NOPOS : lineMap.getColumnNumber(startPosition); }
/** * Returns end column of the given sub-{@code Tree} of this object's {@code CompilationUnitTree}. * climbing the associated {@code TreePath} until a value other than * {@link javax.tools.Diagnostic.NOPOS} is found. * * <p>This method will return {@link javax.tools.Diagnostic.NOPOS} if that value is returned * by a call to {@link SourcePositions#getEndPosition} for every node in the {@link TreePath} * provided. * * @throws IllegalArgumentException if the node provided is not a sub-{@code Tree} of this * object's {@code CompilationUnitTree}. */ long getNodeEndColumn(Tree node) { long endPosition = getNodeEndPosition(node); return endPosition == NOPOS ? NOPOS : lineMap.getColumnNumber(endPosition); }
/** * Returns end column of the given sub-{@code Tree} of this object's {@code CompilationUnitTree}. * climbing the associated {@code TreePath} until a value other than * {@link javax.tools.Diagnostic.NOPOS} is found. * * <p>This method will return {@link javax.tools.Diagnostic.NOPOS} if that value is returned * by a call to {@link SourcePositions#getEndPosition} for every node in the {@link TreePath} * provided. * * @throws IllegalArgumentException if the node provided is not a sub-{@code Tree} of this * object's {@code CompilationUnitTree}. */ long getNodeEndColumn(Tree node) { long endPosition = getNodeEndPosition(node); return endPosition == NOPOS ? NOPOS : lineMap.getColumnNumber(endPosition); }
private final MethodArgument[] composeArguments(List<? extends Tree> args, List<? extends Tree> argTypes) { int n = args.size(); MethodArgument[] arguments = new MethodArgument[n]; for (int i = 0; i < n; i++) { Tree var = args.get(i); long startOffset = positions.getStartPosition(tree, var); long endOffset = positions.getEndPosition(tree, var); arguments[i] = new MethodArgument(var.toString(), (argTypes.size() > i) ? argTypes.get(i).toString() : "", positionDelegate.createPosition( (int) startOffset, (int) lineMap.getLineNumber(startOffset), (int) lineMap.getColumnNumber(startOffset)), positionDelegate.createPosition( (int) endOffset, (int) lineMap.getLineNumber(endOffset), (int) lineMap.getColumnNumber(endOffset))); } return arguments; }
public Pos(CompilationUnitTree cu, long pos) { this(cu.getLineMap().getLineNumber(pos), cu.getLineMap().getColumnNumber(pos)); } }
private final MethodArgument[] composeArguments(List<? extends Tree> args, List<? extends Tree> argTypes) { int n = args.size(); MethodArgument[] arguments = new MethodArgument[n]; for (int i = 0; i < n; i++) { Tree var = args.get(i); long startOffset = positions.getStartPosition(tree, var); long endOffset = positions.getEndPosition(tree, var); if (startOffset == Diagnostic.NOPOS || endOffset == Diagnostic.NOPOS) { return new MethodArgument[] {}; } arguments[i] = new MethodArgument(var.toString(), (argTypes.size() > i) ? argTypes.get(i).toString() : "", positionDelegate.createPosition( (int) startOffset, (int) lineMap.getLineNumber(startOffset), (int) lineMap.getColumnNumber(startOffset)), positionDelegate.createPosition( (int) endOffset, (int) lineMap.getLineNumber(endOffset), (int) lineMap.getColumnNumber(endOffset))); } return arguments; }
if (lineMap != null) { line = (int) lineMap.getLineNumber(startPos); column = (int) lineMap.getColumnNumber(startPos);
@Override public MethodArgument[] visitMethod(MethodTree node, Object p) { if (methodInvocation || !(offset >= lineMap.getLineNumber(positions.getStartPosition(tree, node)) && (offset <= lineMap.getLineNumber(positions.getEndPosition(tree, node))))) { return super.visitMethod(node, p); } List<? extends VariableTree> args = node.getParameters(); List<? extends TypeParameterTree> argTypes = node.getTypeParameters(); int n = args.size(); arguments = new MethodArgument[n]; for (int i = 0; i < n; i++) { VariableTree var = args.get(i); long startOffset = positions.getStartPosition(tree, var); long endOffset = positions.getEndPosition(tree, var); arguments[i] = new MethodArgument(var.getName().toString(), var.getType().toString(), positionDelegate.createPosition( (int) startOffset, (int) lineMap.getLineNumber(startOffset), (int) lineMap.getColumnNumber(startOffset)), positionDelegate.createPosition( (int) endOffset, (int) lineMap.getLineNumber(endOffset), (int) lineMap.getColumnNumber(endOffset))); } return arguments; //return composeArguments(args, argTypes); }
Position getPos(int pos) { if (pos == -1) { return new Position(-1, -1); } if (nonNull(this.lineMap)) { long lineNumber = this.lineMap.getLineNumber(pos); long columnNumber = this.lineMap.getColumnNumber(pos); return new Position(lineNumber, columnNumber); } int line = 1; try { final List<LineRange> ranges = getRanges(this.getFile()); for (final LineRange r : ranges) { if (r.contains(pos)) { return new Position(line, pos + 1); } final Integer last = r.getEndPos(); pos -= last; line++; } return new Position(-1, -1); } catch (IOException e) { throw new UncheckedIOException(e); } }
(int) startOffset, (int) lineMap.getLineNumber(startOffset), (int) lineMap.getColumnNumber(startOffset)), positionDelegate.createPosition( (int) endOffset,
pos, (int) lineMap.getLineNumber(pos), (int) lineMap.getColumnNumber(pos) ); pos = (int) sp.getEndPosition(cu, node); pos, (int) lineMap.getLineNumber(pos), (int) lineMap.getColumnNumber(pos) ); Tree identifier; pos, (int) lineMap.getLineNumber(pos), (int) lineMap.getColumnNumber(pos) ); if (getStartPosFromMethodLength) { pos, (int) lineMap.getLineNumber(pos), (int) lineMap.getColumnNumber(pos) );
pos, (int) lineMap.getLineNumber(pos), (int) lineMap.getColumnNumber(pos) ); pos = (int) sp.getEndPosition(cu, node); pos, (int) lineMap.getLineNumber(pos), (int) lineMap.getColumnNumber(pos) ); Tree identifier; pos, (int) lineMap.getLineNumber(pos), (int) lineMap.getColumnNumber(pos) ); if (getStartPosFromMethodLength) { pos, (int) lineMap.getLineNumber(pos), (int) lineMap.getColumnNumber(pos) );
LineMap lm = compUnit.getLineMap(); if(token.getLine()==1) { token.setColumn(token.getColumn()+(int)lm.getColumnNumber(pos)-1);
public SourcePosition findSourcePosition(Element element) { while (element instanceof DecoratedElement) { element = ((DecoratedElement) element).getDelegate(); } if (element instanceof ElementAdaptor) { return ((ElementAdaptor)element).getSourcePosition(); } TreePath path = this.trees.getPath(element); if (path != null) { CompilationUnitTree cu = path.getCompilationUnit(); SourcePositions positions = this.trees.getSourcePositions(); long position = positions.getStartPosition(cu, path.getLeaf()); long line = cu.getLineMap().getLineNumber(position); long column = cu.getLineMap().getColumnNumber(position); return new SourcePosition(path, cu.getSourceFile(), position, line, column); } else { return null; } }
public SourcePosition findSourcePosition(Element element) { while (element instanceof DecoratedElement) { element = ((DecoratedElement) element).getDelegate(); } if (element instanceof ElementAdaptor) { return ((ElementAdaptor)element).getSourcePosition(); } TreePath path = this.trees.getPath(element); if (path != null) { CompilationUnitTree cu = path.getCompilationUnit(); SourcePositions positions = this.trees.getSourcePositions(); long position = positions.getStartPosition(cu, path.getLeaf()); long line = cu.getLineMap().getLineNumber(position); long column = cu.getLineMap().getColumnNumber(position); return new SourcePosition(path, cu.getSourceFile(), position, line, column); } else { return null; } }