/** * @deprecated Do not use. Use {@link GeneratorUtilities#importComments(com.sun.source.tree.Tree, com.sun.source.tree.CompilationUnitTree) } instead. */ @Deprecated public void collect(TokenSequence<JavaTokenId> ts, CompilationInfo ci) { GeneratorUtilities.importComments(ci, ci.getCompilationUnit(), ci.getCompilationUnit()); }
private Matcher(CompilationInfo info) { this.info = info; this.root = new TreePath(info.getCompilationUnit()); this.options.add(Options.ALLOW_GO_DEEPER); }
public Set<Token> findUsages(Element element, CompilationInfo info, Document doc) { this.info = info; this.usages = new HashSet<Token>(); this.toFind = element; this.doc = doc; scan(info.getCompilationUnit(), null); return usages; }
private long startOf(List<? extends Tree> trees) { if (trees.isEmpty()) return -1; return sourcePositions.getStartPosition(info.getCompilationUnit(), trees.get(0)); }
@Override public Void scan(DocTree node, Void p) { if ( node != null && positions.getStartPosition(javac.getCompilationUnit(), docComment, node) <= offset && positions.getEndPosition(javac.getCompilationUnit(), docComment, node) >= offset) { return super.scan(node, p); } return null; } @Override public Void visitReference(ReferenceTree node, Void p) {
@Override public Void scan(DocTree node, Void p) { if ( node != null && positions.getStartPosition(javac.getCompilationUnit(), docComment, node) <= offset && positions.getEndPosition(javac.getCompilationUnit(), docComment, node) >= offset) { return super.scan(node, p); } return null; } @Override public Void visitReference(ReferenceTree node, Void p) {
private String getPackageName(CompilationInfo cinfo) { Element e = cinfo.getTrees().getElement(new TreePath(cinfo.getCompilationUnit())); if (e != null && e.getKind() == ElementKind.PACKAGE) { return ((PackageElement) e).getQualifiedName().toString(); } return null; }
public AssignComments(final CompilationInfo info, final Tree commentMapTarget, final TokenSequence<JavaTokenId> seq, final SourcePositions positions) { this(info, commentMapTarget, seq, info.getCompilationUnit(), positions); }
/** * Computes all unresolved (not imported) {@link Element}s referenced by * all javadocs of all class members of the passed java context {@code javac}. * * @param javac a java context to search for all top level classes and * all their members * @return names that have to be resoved (imported). */ public static Set<String> computeUnresolvedImports(CompilationInfo javac) { UnresolvedImportScanner scanner = new UnresolvedImportScanner(javac); scanner.scan(javac.getCompilationUnit(), null); return scanner.unresolved; }
/** * 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); }
public static String getBodyText(CompilationInfo cinfo, MethodTree tree) { SourcePositions sp = cinfo.getTrees().getSourcePositions(); BlockTree body = tree.getBody(); int start = (int) sp.getStartPosition(cinfo.getCompilationUnit(), body); int end = (int) sp.getEndPosition(cinfo.getCompilationUnit(), body); // get body text from source text return cinfo.getText().substring(start, end); }
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}); }
/**Returns tokens for a given tree. Uses specified {@link SourcePositions}. */ public TokenSequence<JavaTokenId> tokensFor(Tree tree, SourcePositions sourcePositions) { int start = (int)sourcePositions.getStartPosition(info.getCompilationUnit(), tree); int end = (int)sourcePositions.getEndPosition(info.getCompilationUnit(), tree); return info.getTokenHierarchy().tokenSequence(JavaTokenId.language()).subSequence(start, end); }
@Override public Void visitParam(ParamTree node, Void p) { //XXX: getElement for the param's identifier??? if ( node.getName() != null && positions.getStartPosition(javac.getCompilationUnit(), docComment, node.getName()) <= offset && positions.getEndPosition(javac.getCompilationUnit(), docComment, node.getName()) >= offset) { result[0] = findNameTokenOfParamTag(offset, getJavadocTS(javac, offset)); return null; } return super.visitParam(node, p); } @Override public Void visitSee(SeeTree node, Void p) {
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); } }
public Object run(CompilationInfo cinfo) { for (ImportTree importTree : cinfo.getCompilationUnit().getImports()) { if(importTree.getQualifiedIdentifier().getKind() == Tree.Kind.MEMBER_SELECT) { MemberSelectTree memSelectTree = (MemberSelectTree)importTree.getQualifiedIdentifier(); if(getFQN(cinfo, memSelectTree).equals(fqn)) { return true; } } } return false; } }, getFileObject());
@Override public Void visitParam(ParamTree node, Void p) { //XXX: getElement for the param's identifier??? if ( node.getName() != null && positions.getStartPosition(javac.getCompilationUnit(), docComment, node.getName()) <= offset && positions.getEndPosition(javac.getCompilationUnit(), docComment, node.getName()) >= offset) { result[0] = paramElementFor(trees.getElement(tp), node); return null; } return super.visitParam(node, p); } @Override public Void visitSee(SeeTree node, Void p) {
public void moveToEnd(Tree t) { if (t == null) { return ; } long end = sourcePositions.getEndPosition(info.getCompilationUnit(), t); if (end == (-1)) return ; if (t.getKind() == Kind.ARRAY_TYPE) { moveToEnd(((ArrayTypeTree) t).getType()); return ; } moveToOffset(end); }
@Override public Void visitIdentifier(IdentifierTree tree, Void v) { if (findUsages) { Element el = info.getTrees().getElement(getCurrentPath()); if (variableElement != null && variableElement.equals(el)) { int pos = (int) info.getTrees().getSourcePositions().getStartPosition(info.getCompilationUnit(), tree); usagesPositions.add(pos); } } return super.visitIdentifier(tree, v); }
@Override public Void visitParam(ParamTree node, Void p) { if ( node.getName() != null && toFind.equals(paramElementFor(trees.getElement(forElement), node))) { handleUsage((int) trees.getSourcePositions().getStartPosition(javac.getCompilationUnit(), docComment, node.getName())); return null; } return super.visitParam(node, p); } @Override public Void visitSee(SeeTree node, Void p) {