Java Code Examples for com.sun.source.util.DocTrees#getSourcePositions()

The following examples show how to use com.sun.source.util.DocTrees#getSourcePositions() . 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: FindLocalUsagesQuery.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: T4994049.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public boolean run(DocletEnvironment root) {
    DocTrees trees = root.getDocTrees();

    SourcePositions sourcePositions = trees.getSourcePositions();
    for (TypeElement klass : ElementFilter.typesIn(root.getIncludedElements())) {
        for (ExecutableElement method : getMethods(klass)) {
            if (method.getSimpleName().toString().equals("tabbedMethod")) {
                TreePath path = trees.getPath(method);
                CompilationUnitTree cu = path.getCompilationUnit();
                long pos = sourcePositions.getStartPosition(cu, path.getLeaf());
                LineMap lineMap = cu.getLineMap();
                long columnNumber = lineMap.getColumnNumber(pos);
                if (columnNumber == 9) {
                    System.out.println(columnNumber + ": OK!");
                    return true;
                } else {
                    System.err.println(columnNumber + ": wrong tab expansion");
                    return false;
                }
            }
        }
    }
    return false;
}
 
Example 3
Source File: FindLocalUsagesQuery.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@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 4
Source File: JavadocCompletionQuery.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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 5
Source File: JavadocConverter.java    From j2objc with Apache License 2.0 5 votes vote down vote up
private JavadocConverter(Element element, DocCommentTree docComment, String source,
    DocTrees docTrees, CompilationUnitTree unit, boolean reportWarnings) {
  this.element = element;
  this.docComment = docComment;
  this.source = source;
  this.docSourcePositions = docTrees.getSourcePositions();
  this.unit = unit;
  this.reportWarnings = reportWarnings;
}
 
Example 6
Source File: Test.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
Checker(DocTrees trees) {
    this.trees = trees;
    srcPosns = trees.getSourcePositions();
}
 
Example 7
Source File: Test.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
Checker(DocTrees trees) {
    this.trees = trees;
    srcPosns = trees.getSourcePositions();
}
 
Example 8
Source File: Test.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
Checker(DocTrees trees) {
    this.trees = trees;
    srcPosns = trees.getSourcePositions();
}
 
Example 9
Source File: Test.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
Checker(DocTrees trees) {
    this.trees = trees;
    srcPosns = trees.getSourcePositions();
}
 
Example 10
Source File: Test.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
Checker(DocTrees trees) {
    this.trees = trees;
    srcPosns = trees.getSourcePositions();
}
 
Example 11
Source File: Test.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
Checker(DocTrees trees) {
    this.trees = trees;
    srcPosns = trees.getSourcePositions();
}
 
Example 12
Source File: Test.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
Checker(DocTrees trees) {
    this.trees = trees;
    srcPosns = trees.getSourcePositions();
}
 
Example 13
Source File: Test.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
Checker(DocTrees trees) {
    this.trees = trees;
    srcPosns = trees.getSourcePositions();
}