当前位置: 首页>>代码示例>>Java>>正文


Java DocTrees类代码示例

本文整理汇总了Java中com.sun.source.util.DocTrees的典型用法代码示例。如果您正苦于以下问题:Java DocTrees类的具体用法?Java DocTrees怎么用?Java DocTrees使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DocTrees类属于com.sun.source.util包,在下文中一共展示了DocTrees类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: visitReference

import com.sun.source.util.DocTrees; //导入依赖的package包/类
@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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:RenameTransformer.java

示例2: visitReference

import com.sun.source.util.DocTrees; //导入依赖的package包/类
@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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:FindLocalUsagesQuery.java

示例3: visitIdentifier

import com.sun.source.util.DocTrees; //导入依赖的package包/类
@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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:FindLocalUsagesQuery.java

示例4: run

import com.sun.source.util.DocTrees; //导入依赖的package包/类
public boolean run(DocletEnvironment root) {
    DocTrees docTrees = root.getDocTrees();
    System.out.println("classes:" + ElementFilter.typesIn(root.getIncludedElements()));

    Element klass = ElementFilter.typesIn(root.getIncludedElements()).iterator().next();
    String text = "";
    try {
        DocCommentTree dcTree = docTrees.getDocCommentTree(klass, overviewpath);
        text = dcTree.getFullBody().toString();
    } catch (IOException ioe) {
        throw new Error(ioe);
    }

    if (text.length() < 64)
        System.err.println("text: '" + text + "'");
    else
        System.err.println("text: '"
                + text.substring(0, 20)
                + "..."
                + text.substring(text.length() - 20)
                + "'");
    return text.startsWith("ABC") && text.endsWith("XYZ");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:Test.java

示例5: run

import com.sun.source.util.DocTrees; //导入依赖的package包/类
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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:T4994049.java

示例6: run

import com.sun.source.util.DocTrees; //导入依赖的package包/类
public boolean run(DocletEnvironment root) {
        DocTrees trees = root.getDocTrees();
        TypeElement cd = ElementFilter.typesIn(root.getIncludedElements()).iterator().next();
        DocCommentTree docCommentTree = trees.getDocCommentTree(cd);
        List<? extends DocTree> tags = docCommentTree.getBody();

        for (int i = 0; i < tags.size(); i++) {
            System.out.println(tags.get(0).getKind());
//            if (!tags[i].name().equals(expectedTags[i]) ||
//                        !tags[i].text().equals(expectedText[i])) {
//                throw new Error("Tag \"" + tags[i] + "\" not as expected");
//            }
        }

        return true;
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:InlineTagsWithBraces.java

示例7: runFileObjectTest

import com.sun.source.util.DocTrees; //导入依赖的package包/类
/**
 * Tests DocTrees.getDocCommentTree(FileObject fo).
 *
 * @param htmlfileName the file to be parsed
 * @throws Exception when an error occurs.
 */
public void runFileObjectTest(String htmlfileName) throws Exception {
    List<File> javaFiles =  Collections.emptyList();

    List<File> otherFiles = new ArrayList<>();
    otherFiles.add(new File(testSrc, htmlfileName));

    try (StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null)) {
        Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(javaFiles);
        Iterable<? extends JavaFileObject> others = fm.getJavaFileObjectsFromFiles(otherFiles);

        final JavacTask t = javac.getTask(null, fm, null, null, null, fos);
        final DocTrees trees = DocTrees.instance(t);

        StringWriter sw = new StringWriter();

        printer.print(trees.getDocCommentTree(others.iterator().next()), sw);
        String found = sw.toString();
        String expected = getExpected(otherFiles.iterator().next().toPath());
        astcheck(otherFiles.toString(), expected, found);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:DocCommentTreeApiTester.java

示例8: run

import com.sun.source.util.DocTrees; //导入依赖的package包/类
public boolean run(DocletEnvironment root) {
    DocTrees docTrees = root.getDocTrees();
    System.out.println("classes:" + root.getIncludedClasses());

    Element klass = root.getIncludedClasses().iterator().next();
    String text = "";
    try {
        DocCommentTree dcTree = docTrees.getDocCommentTree(klass, overviewpath);
        text = dcTree.getFullBody().toString();
    } catch (IOException ioe) {
        throw new Error(ioe);
    }

    if (text.length() < 64)
        System.err.println("text: '" + text + "'");
    else
        System.err.println("text: '"
                + text.substring(0, 20)
                + "..."
                + text.substring(text.length() - 20)
                + "'");
    return text.startsWith("ABC") && text.endsWith("XYZ");
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:24,代码来源:Test.java

示例9: run

import com.sun.source.util.DocTrees; //导入依赖的package包/类
public boolean run(DocletEnvironment root) {
    DocTrees trees = root.getDocTrees();

    SourcePositions sourcePositions = trees.getSourcePositions();
    for (TypeElement klass : root.getIncludedClasses()) {
        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;
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:25,代码来源:T4994049.java

示例10: run

import com.sun.source.util.DocTrees; //导入依赖的package包/类
public boolean run(DocletEnvironment root) {
        DocTrees trees = root.getDocTrees();
        TypeElement cd = root.getIncludedClasses().iterator().next();
        DocCommentTree docCommentTree = trees.getDocCommentTree(cd);
        List<? extends DocTree> tags = docCommentTree.getBody();

        for (int i = 0; i < tags.size(); i++) {
            System.out.println(tags.get(0).getKind());
//            if (!tags[i].name().equals(expectedTags[i]) ||
//                        !tags[i].text().equals(expectedText[i])) {
//                throw new Error("Tag \"" + tags[i] + "\" not as expected");
//            }
        }

        return true;
    }
 
开发者ID:campolake,项目名称:openjdk9,代码行数:17,代码来源:InlineTagsWithBraces.java

示例11: run

import com.sun.source.util.DocTrees; //导入依赖的package包/类
void run() throws Exception {
    List<File> files = new ArrayList<File>();
    File testSrc = new File(System.getProperty("test.src"));
    for (File f: testSrc.listFiles()) {
        if (f.isFile() && f.getName().endsWith(".java"))
            files.add(f);
    }

    JavacTool javac = JavacTool.create();
    StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null);

    Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files);

    JavacTask t = javac.getTask(null, fm, null, null, null, fos);
    DocTrees trees = DocTrees.instance(t);

    Iterable<? extends CompilationUnitTree> units = t.parse();

    DeclScanner ds = new DeclScanner(trees);
    for (CompilationUnitTree unit: units) {
        ds.scan(unit, null);
    }

    if (errors > 0)
        throw new Exception(errors + " errors occurred");
}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:27,代码来源:DocTreePathScannerTest.java

示例12: appendReference

import com.sun.source.util.DocTrees; //导入依赖的package包/类
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));
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:ElementJavadoc.java

示例13: getReferenceClass

import com.sun.source.util.DocTrees; //导入依赖的package包/类
/**Find the type (the part before {@code #}) that is being referenced by the given {@link ReferenceTree}.
     * 
     * @param path the leaf must be {@link ReferenceTree}
     * @return the referred type, or {@code null} if none.
     * @since 0.124
     */
    public @CheckForNull ExpressionTree getReferenceClass(@NonNull DocTreePath path) {
        TreePath tp = path.getTreePath();
        DCReference ref = (DCReference) path.getLeaf();
        
        ((DocTrees) this.info.getTrees()).getElement(path);
//        was:
//        ((JavacTrees) this.info.getTrees()).ensureDocReferenceAttributed(tp, ref);
        
        return (ExpressionTree) ref.qualifierExpression;
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:TreeUtilities.java

示例14: getReferenceParameters

import com.sun.source.util.DocTrees; //导入依赖的package包/类
/**Find the parameters that are specified in the given {@link ReferenceTree}.
     * 
     * @param path the leaf must be {@link ReferenceTree}
     * @return the parameters for the referred method, or {@code null} if none.
     * @since 0.124
     */
    public @CheckForNull List<? extends Tree> getReferenceParameters(@NonNull DocTreePath path) {
        TreePath tp = path.getTreePath();
        DCReference ref = (DCReference) path.getLeaf();
        
        ((DocTrees) this.info.getTrees()).getElement(path);
//        was:
//        ((JavacTrees) this.info.getTrees()).ensureDocReferenceAttributed(tp, ref);
        
        return ref.paramTypes;
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:TreeUtilities.java

示例15: scan

import com.sun.source.util.DocTrees; //导入依赖的package包/类
@Override
public Tree scan(Tree tree, Element p) {
    if(p == null && handle == null) {
        p = docHandle != null? ((DocTrees)workingCopy.getTrees()).getElement(docHandle.resolve(workingCopy))
                                                   : handle.resolveElement(workingCopy);
    }
    return super.scan(tree, p);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:RenameTransformer.java


注:本文中的com.sun.source.util.DocTrees类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。