protected Tag(CompilationUnitTree unitTree, SourcePositions srcPos, Tree r) { this.sp = srcPos.getStartPosition(unitTree,r); this.ep = srcPos.getEndPosition(unitTree,r); }
private static int getOldIndent(DiffContext diffContext, Tree t) { int offset = (int) diffContext.trees.getSourcePositions().getStartPosition(diffContext.origUnit, t); if (offset < 0) return -1; while (offset > 0 && diffContext.origText.charAt(offset - 1) != '\n') offset--; int indent = 0; while (offset < diffContext.origText.length()) { char c = diffContext.origText.charAt(offset++); if (c == '\t') { indent += diffContext.style.getTabSize(); } else if (c == '\n' || !Character.isWhitespace(c)) { break; } else { indent++; } } return indent; }
private void add(Element e) { TreePath p = getCurrentPath(); long pos = this.pos.getStartPosition(p.getCompilationUnit(), p.getLeaf()); if(pos==-1) return; Set<TreePath> trees = result.get(e); if(trees==null) result.put(e,trees=new HashSet<TreePath>()); trees.add(p); }
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) + ")"; } };
private void addHighlightFor(Tree t) { int start = (int) info.getTrees().getSourcePositions().getStartPosition(info.getCompilationUnit(), t); int end = (int) info.getTrees().getSourcePositions().getEndPosition(info.getCompilationUnit(), t); highlights.add(new int[] {start, end}); }
private void insideArrayAccess(Env env) throws IOException { int offset = env.getOffset(); ArrayAccessTree aat = (ArrayAccessTree) env.getPath().getLeaf(); SourcePositions sourcePositions = env.getSourcePositions(); CompilationUnitTree root = env.getRoot(); int aaTextStart = (int) sourcePositions.getEndPosition(root, aat.getExpression()); if (aaTextStart != Diagnostic.NOPOS) { Tree expr = unwrapErrTree(aat.getIndex()); if (expr == null || offset <= (int) sourcePositions.getStartPosition(root, expr)) { String aatText = env.getController().getText().substring(aaTextStart, offset); int bPos = aatText.indexOf('['); //NOI18N if (bPos > -1) { localResult(env); addValueKeywords(env); } } } }
(int) info.getTrees().getSourcePositions().getStartPosition(cu, tree.getLeaf()), (int) info.getTrees().getSourcePositions().getEndPosition(cu, tree.getLeaf()) }); Token t = v.tree2Token.get(u.tree.getLeaf());
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 int getElementPosition( final Element e, final Tree t ) { return (int) trees.getSourcePositions().getStartPosition( trees.getPath( e ). getCompilationUnit(), t ); }
long getStartPos(TreePath p) { SourcePositions sp = trees.getSourcePositions(); return sp.getStartPosition(p.getCompilationUnit(), p.getLeaf()); }
public static String getArgumentSource(CompilationInfo cinfo, ExpressionTree exprTree) { long end = cinfo.getTrees().getSourcePositions().getEndPosition(cinfo.getCompilationUnit(), exprTree); long start = cinfo.getTrees().getSourcePositions().getStartPosition(cinfo.getCompilationUnit(), exprTree); return cinfo.getText().substring((int)start, (int)end); } }
private static int findLastBracketImpl(Tree tree, CompilationUnitTree cu, SourcePositions positions, Document doc) { int start = (int)positions.getStartPosition(cu, tree); int end = (int)positions.getEndPosition(cu, tree);
private void insideCompoundAssignment(Env env) throws IOException { int offset = env.getOffset(); CompoundAssignmentTree cat = (CompoundAssignmentTree) env.getPath().getLeaf(); SourcePositions sourcePositions = env.getSourcePositions(); CompilationUnitTree root = env.getRoot(); int catTextStart = (int) sourcePositions.getEndPosition(root, cat.getVariable()); if (catTextStart != Diagnostic.NOPOS) { Tree expr = unwrapErrTree(cat.getExpression()); if (expr == null || offset <= (int) sourcePositions.getStartPosition(root, expr)) { String catText = env.getController().getText().substring(catTextStart, offset); int eqPos = catText.indexOf('='); //NOI18N if (eqPos > -1) { localResult(env); addValueKeywords(env); } } } }
return null; Tree t = treePath.getLeaf(); int start = (int) info.getTrees().getSourcePositions().getStartPosition(info.getCompilationUnit(), t); int end = (int) info.getTrees().getSourcePositions().getEndPosition(info.getCompilationUnit(), t);
SourcePositions positions = treeUtils.getSourcePositions(); AnnotationTree annotationTree = (AnnotationTree) path.getLeaf(); AssignmentTree assignTree = (AssignmentTree) annotationTree.getArguments().get(0); long pos = positions.getStartPosition(unitTree, exprTree); lines.add(lineMap.getLineNumber(pos)); } else { NewArrayTree valuesTree = (NewArrayTree) exprTree; for (ExpressionTree valueTree : valuesTree.getInitializers()) { long pos = positions.getStartPosition(unitTree, valueTree); lines.add(lineMap.getLineNumber(pos));
@Override Integer run(CompilationController controller, MethodTree methodTree, ExecutableElement methodElement) { return (int) controller.getTrees().getSourcePositions().getStartPosition( controller.getCompilationUnit(), methodTree); } }.execute();
long getStartPos(TreePath p) { SourcePositions sp = trees.getSourcePositions(); return sp.getStartPosition(p.getCompilationUnit(), p.getLeaf()); }
/** * This method returns the part of the syntax tree to be highlighted. */ public static TextSpan getUnderlineSpan(CompilationInfo info, Tree tree) { SourcePositions srcPos = info.getTrees().getSourcePositions(); int startOffset = (int) srcPos.getStartPosition(info.getCompilationUnit(), tree); int endOffset = (int) srcPos.getEndPosition(info.getCompilationUnit(), tree); return new TextSpan(startOffset, endOffset); }
private static Token<JavaTokenId> findIdentifierSpanImpl(CompilationInfo info, Tree decl, Tree lastLeft, List<? extends Tree> firstRight, String name, CompilationUnitTree cu, SourcePositions positions) { int declStart = (int) positions.getStartPosition(cu, decl); int start = lastLeft != null ? (int)positions.getEndPosition(cu, lastLeft) : declStart; int end = (int)positions.getEndPosition(cu, decl); continue; int proposedEnd = (int)positions.getStartPosition(cu, t); start = (int) positions.getStartPosition(cu, decl);
switch(path.getLeaf().getKind()) { case VARIABLE: el = trees.getElement(path); if (TreeUtilities.CLASS_TREE_KINDS.contains(parent.getLeaf().getKind())) { boolean isStatic = ((VariableTree)path.getLeaf()).getModifiers().getFlags().contains(Modifier.STATIC); for(Tree member : ((ClassTree)parent.getLeaf()).getMembers()) { if (member.getKind() == Tree.Kind.VARIABLE && sourcePositions.getStartPosition(path.getCompilationUnit(), member) >= pos && (isStatic || !((VariableTree)member).getModifiers().getFlags().contains(Modifier.STATIC))) { el = trees.getElement(new TreePath(parent, member)); case ENHANCED_FOR_LOOP: EnhancedForLoopTree efl = (EnhancedForLoopTree)path.getLeaf(); if (sourcePositions.getEndPosition(path.getCompilationUnit(), efl.getExpression()) >= pos) { el = trees.getElement(new TreePath(path, efl.getVariable())); if (el != null) {