use of com.sun.source.util.SourcePositions in project checker-framework by typetools.
the class SourceChecker method detailedMsgTextPositionString.
/**
* For the given tree, compute the source positions for that tree. Return a "tuple"-like string
* (e.g. "( 1, 200 )" ) that contains the start and end position of the tree in the current
* compilation unit. Used only by the -Adetailedmsgtext output format.
*
* @param tree tree to locate within the current compilation unit
* @param currentRoot the current compilation unit
* @return a tuple string representing the range of characters that tree occupies in the source
* file, or the empty string if {@code tree} is null
*/
private String detailedMsgTextPositionString(Tree tree, CompilationUnitTree currentRoot) {
if (tree == null) {
return "";
}
SourcePositions sourcePositions = trees.getSourcePositions();
long start = sourcePositions.getStartPosition(currentRoot, tree);
long end = sourcePositions.getEndPosition(currentRoot, tree);
return "( " + start + ", " + end + " )";
}
use of com.sun.source.util.SourcePositions in project checker-framework by typetools.
the class SourceChecker method treeToFilePositionString.
/**
* For the given tree, compute the source positions for that tree. Return a "tuple" like string
* (e.g. "( 1, 200 )" ) that contains the start and end position of the tree in the current
* compilation unit.
*
* @param tree tree to locate within the current compilation unit
* @param currentRoot the current compilation unit
* @param processingEnv the current processing environment
* @return a tuple string representing the range of characters that tree occupies in the source
* file
*/
public String treeToFilePositionString(Tree tree, CompilationUnitTree currentRoot, ProcessingEnvironment processingEnv) {
if (tree == null) {
return null;
}
SourcePositions sourcePositions = trees.getSourcePositions();
long start = sourcePositions.getStartPosition(currentRoot, tree);
long end = sourcePositions.getEndPosition(currentRoot, tree);
return "( " + start + ", " + end + " )";
}
use of com.sun.source.util.SourcePositions in project btrace by btraceio.
the class VerifierVisitor method reportError.
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;
}
Aggregations