Java Code Examples for com.sun.source.util.DocTrees#getElement()
The following examples show how to use
com.sun.source.util.DocTrees#getElement() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RenameTransformer.java From netbeans with Apache License 2.0 | 6 votes |
@Override public DocTree visitReference(ReferenceTree node, Element elementToFind) { DocTreePath currentDocPath = getCurrentDocPath(); DocTrees trees = workingCopy.getDocTrees(); Element el = trees.getElement(currentDocPath); ExpressionTree classReference = workingCopy.getTreeUtilities().getReferenceClass(currentDocPath); if((el == null || !(el.equals(elementToFind) || isMethodMatch(el))) && classReference != null) { el = trees.getElement(new TreePath(getCurrentPath(), classReference)); } if (el != null && (el.equals(elementToFind) || isMethodMatch(el))) { ReferenceTree newRef; Name memberName = workingCopy.getTreeUtilities().getReferenceName(currentDocPath); List<? extends Tree> methodParameters = workingCopy.getTreeUtilities().getReferenceParameters(currentDocPath); if(el.getKind().isClass() || el.getKind().isInterface()) { newRef = make.Reference(make.setLabel(classReference, newName), memberName, methodParameters); } else { newRef = make.Reference(classReference, newName, methodParameters); } rewrite(currentDocPath.getTreePath().getLeaf(), node, newRef); } return super.visitReference(node, elementToFind); }
Example 2
Source File: FindLocalUsagesQuery.java From netbeans with Apache License 2.0 | 6 votes |
@Override public DocTree visitReference(ReferenceTree node, Element p) { DocTrees trees = info.getDocTrees(); Element el = trees.getElement(getCurrentPath()); if (el != null && el.equals(toFind)) { int[] span = treeUtils.findNameSpan(getCurrentPath().getDocComment(), node); if(span != null) { try { MutablePositionRegion region = createRegion(doc, span[0], span[1]); usages.add(region); } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } } } return super.visitReference(node, p); }
Example 3
Source File: FindLocalUsagesQuery.java From netbeans with Apache License 2.0 | 6 votes |
@Override public DocTree visitIdentifier(com.sun.source.doctree.IdentifierTree node, Element p) { DocTrees trees = info.getDocTrees(); Element el = trees.getElement(getCurrentPath()); if (el != null && el.equals(toFind)) { DocSourcePositions sp = trees.getSourcePositions(); CompilationUnitTree cut = info.getCompilationUnit(); DocCommentTree docComment = getCurrentPath().getDocComment(); long start = sp.getStartPosition(cut, docComment, node); long end = sp.getEndPosition(cut, docComment, node); if(start != Diagnostic.NOPOS && end != Diagnostic.NOPOS) { try { MutablePositionRegion region = createRegion(doc, (int)start, (int)end); usages.add(region); } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } } } return super.visitIdentifier(node, p); }
Example 4
Source File: ElementJavadoc.java From netbeans with Apache License 2.0 | 5 votes |
private void appendReference(StringBuilder sb, ReferenceTree ref, List<? extends DocTree> label, TreePath docPath, DocCommentTree doc, DocTrees trees) { String sig = ref.getSignature(); if (sig != null && sig.length() > 0) { if (sig.charAt(0) == '#') { //NOI18N sig = sig.substring(1); } sig = sig.replace('#', '.'); //NOI18N } Element element = trees.getElement(DocTreePath.getPath(docPath, doc, ref)); if (element != null) { createLink(sb, element, label == null || label.isEmpty() ? sig : inlineTags(label, docPath, doc, trees, null)); //NOI18N } else { sb.append(label == null || label.isEmpty() ? sig : inlineTags(label, docPath, doc, trees, null)); } }
Example 5
Source File: RenameTransformer.java From netbeans with Apache License 2.0 | 5 votes |
@Override public DocTree visitIdentifier(com.sun.source.doctree.IdentifierTree node, Element elementToFind) { DocTreePath currentDocPath = getCurrentDocPath(); DocTrees trees = workingCopy.getDocTrees(); Element el = trees.getElement(currentDocPath); if (el != null && (el.equals(elementToFind))) { com.sun.source.doctree.IdentifierTree newIdent = make.DocIdentifier(newName); rewrite(currentDocPath.getTreePath().getLeaf(), node, newIdent); } return super.visitIdentifier(node, elementToFind); }
Example 6
Source File: FindLocalUsagesQuery.java From netbeans with Apache License 2.0 | 5 votes |
@Override public DocTree visitText(TextTree node, Element p) { if(searchComment) { DocTrees trees = info.getDocTrees(); DocSourcePositions sourcePositions = trees.getSourcePositions(); DocTreePath currentDocPath = getCurrentPath(); if(toFind.getKind() == ElementKind.PARAMETER) { VariableElement var = (VariableElement) toFind; Element method = trees.getElement(currentDocPath); if(!var.getEnclosingElement().equals(method)) { return super.visitText(node, p); } } String text = node.getBody(); String name = toFind.getSimpleName().toString(); if(text.contains(name)) { int start = (int) sourcePositions.getStartPosition(info.getCompilationUnit(), currentDocPath.getDocComment(), node); int length = name.length(); int offset = -1; do { offset = text.indexOf(name, ++offset); if(offset != -1) { try { MutablePositionRegion region = createRegion(doc, start + offset, start + offset + length); comments.add(region); } catch(BadLocationException ex) { Exceptions.printStackTrace(ex); } } } while (offset != -1); } } return super.visitText(node, p); }
Example 7
Source File: JavadocCompletionQuery.java From netbeans with Apache License 2.0 | 5 votes |
private boolean resolveContext(CompilationInfo javac, JavadocContext jdctx) throws IOException { jdctx.doc = javac.getDocument(); // find class context: class, method, ... DocTrees trees = javac.getDocTrees(); TreePath javadocFor = JavadocCompletionUtils.findJavadoc(javac, this.caretOffset); if (javadocFor == null) { return false; } jdctx.javadocFor = javadocFor; DocCommentTree docCommentTree = trees.getDocCommentTree(javadocFor); if (docCommentTree == null) { return false; } jdctx.comment = docCommentTree; Element elm = trees.getElement(javadocFor); if (elm == null) { return false; } jdctx.handle = ElementHandle.create(elm); jdctx.commentFor = elm; jdctx.jdts = JavadocCompletionUtils.findJavadocTokenSequence(javac, this.caretOffset); if (jdctx.jdts == null) { return false; } jdctx.positions = (DocSourcePositions) trees.getSourcePositions(); return jdctx.positions != null; }
Example 8
Source File: JavadocHelper.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private String getThrownException(JavacTask task, TreePath rootOn, DocCommentTree comment, ThrowsTree tt) { DocTrees trees = DocTrees.instance(task); Element exc = trees.getElement(new DocTreePath(new DocTreePath(rootOn, comment), tt.getExceptionName())); return exc != null ? exc.toString() : null; }