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; }
fixBuilder.replace(first.tree(), sb.toString()); SuggestedFix fix = fixBuilder.build(); LineMap lineMap = state.getPath().getCompilationUnit().getLineMap();
/** Creates a new instance of MethodArgumentsScanner */ public MethodArgumentsScanner(int offset, CompilationUnitTree tree, SourcePositions positions, boolean methodInvocation, AST2Bytecode.OperationCreationDelegate positionDelegate) { this.offset = offset; this.tree = tree; this.positions = positions; this.lineMap = tree.getLineMap(); this.methodInvocation = methodInvocation; this.positionDelegate = positionDelegate; }
public ExpressionScanner(int lineNumber, CompilationUnitTree tree, SourcePositions positions) { this.tree = tree; this.lineNumber = lineNumber; this.positions = positions; this.lineMap = tree.getLineMap(); }
/** Creates a new instance of MethodArgumentsScanner */ public MethodArgumentsScanner(int offset, CompilationUnitTree tree, SourcePositions positions, boolean methodInvocation, AST2Bytecode.OperationCreationDelegate positionDelegate) { this.offset = offset; this.tree = tree; this.positions = positions; this.lineMap = tree.getLineMap(); this.methodInvocation = methodInvocation; this.positionDelegate = positionDelegate; }
public ExpressionScanner(int lineNumber, int statementStart, int statementEnd, CompilationUnitTree tree, SourcePositions positions) { this.tree = tree; this.lineNumber = lineNumber; this.statementStart = statementStart; this.statementEnd = statementEnd; this.positions = positions; this.lineMap = tree.getLineMap(); }
TreeContext(CompilationUnitTree compilationUnit, Trees trees) { this.compilationUnit = compilationUnit; this.trees = trees; this.sourcePositions = trees.getSourcePositions(); this.lineMap = compilationUnit.getLineMap(); }
TreeContext(CompilationUnitTree compilationUnit, Trees trees) { this.compilationUnit = compilationUnit; this.trees = trees; this.sourcePositions = trees.getSourcePositions(); this.lineMap = compilationUnit.getLineMap(); }
TreeContext(CompilationUnitTree compilationUnit, Trees trees) { this.compilationUnit = compilationUnit; this.trees = trees; this.sourcePositions = trees.getSourcePositions(); this.lineMap = compilationUnit.getLineMap(); }
public Pos(CompilationUnitTree cu, long pos) { this(cu.getLineMap().getLineNumber(pos), cu.getLineMap().getColumnNumber(pos)); } }
private static Source analyzeUnit(CompilationUnitTree cut, Set<File> errorFiles) throws IOException { LineMap lineMap = cut.getLineMap(); URI uri = cut.getSourceFile().toUri(); File file = new File(uri.normalize()); String path = file.getCanonicalPath(); Source source = new Source(path, lineMap); if (errorFiles.contains(file)) { source.hasCompileError = true; } SourceContext context = new SourceContext(source); analyzeCompilationUnitTree(context, cut); source.resetLineRange(); return source; }
/** * 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; } }
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);
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);
private void add(Tree node, Trees trees) { CompilationUnitTree unit = getCurrentPath().getCompilationUnit(); SourcePositions positions = trees.getSourcePositions(); LineMap lineMap = unit.getLineMap(); if (lineMap == null) { return; } long startPos = positions.getStartPosition(unit, node); long endPos = positions.getEndPosition(unit, node); if (startPos == NOPOS || endPos == NOPOS) { return; } long endLineNum = lineMap.getLineNumber(endPos); long startLineNum = lineMap.getLineNumber(startPos); long startLineStartPos = lineMap.getStartPosition(startLineNum); regions.computeIfAbsent(unit, __ -> new HashSet<>()) .add(IndexRegion.create(startLineNum, endLineNum, startLineStartPos)); }
@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) + ")"; } };