private static String createMessage( MethodTree tree, ImmutableList<MemberWithIndex> overloads, Map<MemberWithIndex, Integer> groups, LineMap lineMap, MemberWithIndex current) { String ungroupedLines = overloads.stream() .filter(o -> !groups.get(o).equals(groups.get(current))) .map(t -> lineMap.getLineNumber(((JCTree) t.tree()).getStartPosition())) .map(String::valueOf) .collect(joining(", ")); MethodSymbol symbol = ASTHelpers.getSymbol(tree); String name = symbol.isConstructor() ? "Constructor overloads" : String.format("Overloads of '%s'", symbol.getSimpleName()); return String.format( "%s are not grouped together; found ungrouped overloads on line(s): %s", name, ungroupedLines); } }
private Boolean reportError(String msg, Tree node) { SourcePositions srcPos = verifier.getSourcePositions(); CompilationUnitTree compUnit = verifier.getCompilationUnit(); if (compUnit != null) { long pos = srcPos.getStartPosition(compUnit, node); long line = compUnit.getLineMap().getLineNumber(pos); String name = compUnit.getSourceFile().getName(); msg = String.format("%s:%d:%s", name, line, Messages.get(msg)); verifier.getMessager().printMessage(Diagnostic.Kind.ERROR, msg, getElement(node)); } else { verifier.getMessager().printMessage(Diagnostic.Kind.ERROR, msg); } return Boolean.FALSE; }
public Void visitMethod(MethodTree arg0, Void arg1) { long startPosition = sourcePositions.getStartPosition(compilationUnitTree, arg0); long startLine = lineMap.getLineNumber(startPosition); long endPosition = sourcePositions.getEndPosition(compilationUnitTree, arg0); long endLine = lineMap.getLineNumber(endPosition);
private boolean isCurrentTree(Tree aTree) { int startLine = (int) lineMap.getLineNumber(positions.getStartPosition(tree, aTree)); int endLine = (int) lineMap.getLineNumber(positions.getEndPosition(tree, aTree)); return startLine <= lineNumber && lineNumber <= endLine; }
private boolean isCurrentTree(Tree aTree) { int startLine = (int) lineMap.getLineNumber(positions.getStartPosition(tree, aTree)); if (startLine == Diagnostic.NOPOS) { return false; } int endLine = (int) lineMap.getLineNumber(positions.getEndPosition(tree, aTree)); if (endLine == Diagnostic.NOPOS) { return false; } return startLine <= lineNumber && lineNumber <= endLine; }
/** * Returns end line 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 getNodeEndLine(Tree node) { long endPosition = getNodeEndPosition(node); return endPosition == NOPOS ? NOPOS : lineMap.getLineNumber(endPosition); }
/** * Returns start line 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 getNodeStartLine(Tree node) { long startPosition = getNodeStartPosition(node); return startPosition == NOPOS ? NOPOS : lineMap.getLineNumber(startPosition); }
/** * Returns end line 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 getNodeEndLine(Tree node) { long endPosition = getNodeEndPosition(node); return endPosition == NOPOS ? NOPOS : lineMap.getLineNumber(endPosition); }
/** * Returns start line 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 getNodeStartLine(Tree node) { long startPosition = getNodeStartPosition(node); return startPosition == NOPOS ? NOPOS : lineMap.getLineNumber(startPosition); }
/** * Returns start line 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 getNodeStartLine(Tree node) { long startPosition = getNodeStartPosition(node); return startPosition == NOPOS ? NOPOS : lineMap.getLineNumber(startPosition); }
/** * Returns end line 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 getNodeEndLine(Tree node) { long endPosition = getNodeEndPosition(node); return endPosition == NOPOS ? NOPOS : lineMap.getLineNumber(endPosition); }
public Pos(CompilationUnitTree cu, long pos) { this(cu.getLineMap().getLineNumber(pos), cu.getLineMap().getColumnNumber(pos)); } }
/** * Maps a symbol to its source location. */ private JExpression loc(Tree t) { long pos = trees.getSourcePositions().getStartPosition(cut, t); return JExpr.lit((int)cut.getLineMap().getLineNumber(pos)); }
private Boolean reportError(String msg, Tree node) { SourcePositions srcPos = verifier.getSourcePositions(); CompilationUnitTree compUnit = verifier.getCompilationUnit(); if (compUnit != null) { long pos = srcPos.getStartPosition(compUnit, node); long line = compUnit.getLineMap().getLineNumber(pos); String name = compUnit.getSourceFile().getName(); msg = String.format("%s:%d:%s", name, line, Messages.get(msg)); verifier.getMessager().printMessage(Diagnostic.Kind.ERROR, msg); } else { verifier.getMessager().printMessage(Diagnostic.Kind.ERROR, msg); } return Boolean.FALSE; } }
private Boolean reportError(String msg, Tree node) { SourcePositions srcPos = verifier.getSourcePositions(); CompilationUnitTree compUnit = verifier.getCompilationUnit(); if (compUnit != null) { long pos = srcPos.getStartPosition(compUnit, node); long line = compUnit.getLineMap().getLineNumber(pos); String name = compUnit.getSourceFile().getName(); msg = String.format("%s:%d:%s", name, line, Messages.get(msg)); verifier.getMessager().printMessage(Diagnostic.Kind.ERROR, msg); } else { verifier.getMessager().printMessage(Diagnostic.Kind.ERROR, msg); } return Boolean.FALSE; } }
@Override public void run(CompilationController compilationController) throws Exception { compilationController.toPhase(Phase.ELEMENTS_RESOLVED); Trees trees = compilationController.getTrees(); CompilationUnitTree compilationUnitTree = compilationController.getCompilationUnit(); List<? extends Tree> typeDecls = compilationUnitTree.getTypeDecls(); for (Tree tree : typeDecls) { Element element = trees.getElement(trees.getPath(compilationUnitTree, tree)); if (element != null && element.getKind() == ElementKind.CLASS && element.getSimpleName().contentEquals(fo.getName())) { long pos = trees.getSourcePositions().getStartPosition(compilationUnitTree, tree); line[0] = compilationUnitTree.getLineMap().getLineNumber(pos); break; } } } }, true);
public void run(CompilationController compilationController) throws Exception { compilationController.toPhase(Phase.ELEMENTS_RESOLVED); Trees trees = compilationController.getTrees(); CompilationUnitTree compilationUnitTree = compilationController.getCompilationUnit(); List<?extends Tree> typeDecls = compilationUnitTree.getTypeDecls(); for (Tree tree : typeDecls) { Element element = trees.getElement(trees.getPath(compilationUnitTree, tree)); if (element != null && element.getKind() == ElementKind.CLASS && element.getSimpleName().contentEquals(fo.getName())){ long pos = trees.getSourcePositions().getStartPosition(compilationUnitTree, tree); line[0] = compilationUnitTree.getLineMap().getLineNumber(pos); break; } } } }, true);
@Override public void run(CompilationController compilationController) throws Exception { compilationController.toPhase(Phase.ELEMENTS_RESOLVED); Trees trees = compilationController.getTrees(); CompilationUnitTree compilationUnitTree = compilationController.getCompilationUnit(); List<? extends Tree> typeDecls = compilationUnitTree.getTypeDecls(); for (Tree tree : typeDecls) { Element element = trees.getElement(trees.getPath(compilationUnitTree, tree)); if (element != null && element.getKind() == ElementKind.CLASS && element.getSimpleName().contentEquals(fo.getName())) { long pos = trees.getSourcePositions().getStartPosition(compilationUnitTree, tree); line[0] = compilationUnitTree.getLineMap().getLineNumber(pos); break; } } } }, true);
public String toString() { if (treePath == null) return name + " (Unknown Source)"; // just like stack trace, we just print the file name and // not the whole path. The idea is that the package name should // provide enough clue on which directory it lives. CompilationUnitTree compilationUnit = treePath.getCompilationUnit(); Trees trees = Trees.instance(env); long startPosition = trees.getSourcePositions().getStartPosition(compilationUnit, treePath.getLeaf()); return name + "(" + compilationUnit.getSourceFile().getName() + ":" + compilationUnit.getLineMap().getLineNumber(startPosition) + ")"; } };
public String toString() { if (treePath == null) return name + " (Unknown Source)"; // just like stack trace, we just print the file name and // not the whole path. The idea is that the package name should // provide enough clue on which directory it lives. CompilationUnitTree compilationUnit = treePath.getCompilationUnit(); Trees trees = Trees.instance(env); long startPosition = trees.getSourcePositions().getStartPosition(compilationUnit, treePath.getLeaf()); return name + "(" + compilationUnit.getSourceFile().getName() + ":" + compilationUnit.getLineMap().getLineNumber(startPosition) + ")"; } };