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


Java DocTreePath类代码示例

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


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

示例1: create

import com.sun.source.util.DocTreePath; //导入依赖的package包/类
/**
 * Factory method for creating {@link DocTreePathHandle}.
 *
 * @param docTreePath for which the {@link DocTreePathHandle} should be created.
 * @param javac
 * @return a new {@link DocTreePathHandle}
 * @throws java.lang.IllegalArgumentException if arguments are not supported
 */
public static DocTreePathHandle create(final DocTreePath docTreePath, CompilationInfo javac) throws IllegalArgumentException {
    Parameters.notNull("docTreePath", docTreePath);
    Parameters.notNull("javac", javac);

    TreePathHandle treePathHandle = TreePathHandle.create(docTreePath.getTreePath(), javac);
    if(treePathHandle.getFileObject() == null) {
        return null;
    }
    int position = (int) ((DCTree) docTreePath.getLeaf()).getSourcePosition((DCTree.DCDocComment)docTreePath.getDocComment());
    if (position == (-1)) {
        DocTree docTree = docTreePath.getLeaf();
        if(docTree == docTreePath.getDocComment()) {
            return new DocTreePathHandle(new DocCommentDelegate(treePathHandle));
        }
        int index = listChildren(docTreePath.getParentPath().getLeaf()).indexOf(docTree);
        assert index != (-1);
        return new DocTreePathHandle(new CountingDelegate(treePathHandle, index, docTreePath.getLeaf().getKind()));
    }
    Position pos = createPositionRef(treePathHandle.getFileObject(), position, Bias.Forward);
    return new DocTreePathHandle(new DocTreeDelegate(pos, new DocTreeDelegate.KindPath(docTreePath), treePathHandle));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:DocTreePathHandle.java

示例2: resolve

import com.sun.source.util.DocTreePath; //导入依赖的package包/类
/**
 * Resolves an {@link TreePath} from the {@link TreePathHandle}.
 *
 * @param javac representing the
 * {@link javax.tools.CompilationTask}
 * @return resolved subclass of {@link Element} or null if the element
 * does not exist on the classpath/sourcepath of
 * {@link javax.tools.CompilationTask}.
 * @throws IllegalArgumentException when this {@link TreePathHandle} is
 * not created for a source represented by the compilationInfo.
 */
public DocTreePath resolve(final CompilationInfo javac) throws IllegalArgumentException {
    assert javac != null;
    TreePath treePath = treePathHandle.resolve(javac);
    if(treePath == null) {
        throw new IllegalArgumentException("treePathHandle.resolve(compilationInfo) returned null for treePathHandle " + treePathHandle);    //NOI18N
    }
    DocTreePath tp = null;
    DocCommentTree doc = javac.getDocTrees().getDocCommentTree(treePath);
    if (doc == null) {
        // no doc comment for the TreePath
        return null;
    }
    int pos = position.getOffset();
    tp = resolvePathForPos(javac, treePath, doc, pos + 1);
    if (tp != null) {
        return tp;
    }
    tp = resolvePathForPos(javac, treePath, doc, pos);
    return tp;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:DocTreePathHandle.java

示例3: getChild

import com.sun.source.util.DocTreePath; //导入依赖的package包/类
private static DocTreePath getChild(@NonNull DocCommentTree t, final int index) {
    final DocTreePath[] result = new DocTreePath[1];

    t.accept(new DocTreePathScanner<DocTreePath, Void>() {
        int count = 0;
        @Override
        public DocTreePath scan(DocTree node, Void p) {
            if(index == count) {
                result[0] = getCurrentPath();
            }
            return null;
        }
    }, null);

    return result[0];
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:DocTreePathHandle.java

示例4: referenceEmbeddedSourceNodes

import com.sun.source.util.DocTreePath; //导入依赖的package包/类
private static Iterable<? extends TreePath> referenceEmbeddedSourceNodes(CompilationInfo info, DocTreePath ref) {
    List<TreePath> result = new ArrayList<TreePath>();
    
    if (info.getTreeUtilities().getReferenceClass(ref) != null) {
        result.add(new TreePath(ref.getTreePath(), info.getTreeUtilities().getReferenceClass(ref)));
    }
    
    List<? extends Tree> params = info.getTreeUtilities().getReferenceParameters(ref);
    
    if (params != null) {
        for (Tree et : params) {
            result.add(new TreePath(ref.getTreePath(), et));
        }
    }
    
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:JavadocImports.java

示例5: visitReference

import com.sun.source.util.DocTreePath; //导入依赖的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

示例6: handleJavadoc

import com.sun.source.util.DocTreePath; //导入依赖的package包/类
private void handleJavadoc(TreePath el) {
    if(el != null) {
        switch(el.getLeaf().getKind()) {
            case METHOD:
            case ANNOTATION_TYPE:
            case CLASS:
            case ENUM:
            case INTERFACE:
            case VARIABLE:
                DocCommentTree docCommentTree = info.getDocTrees().getDocCommentTree(el);
                if(docCommentTree != null) {
                    DocTreePath docTreePath = new DocTreePath(el, docCommentTree);
                    docScanner.scan(docTreePath, null);
                }
            default:
                break;
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:FindLocalUsagesQuery.java

示例7: getTag

import com.sun.source.util.DocTreePath; //导入依赖的package包/类
private DocTreePath getTag(final JavadocContext jdctx, final int offset) {
    final DocTreePath[] result = new DocTreePath[1];
    final int normalizedOffset = skipWhitespacesBackwards(jdctx, offset);
    new DocTreePathScanner<Void, Void>() {
        @Override public Void scan(DocTree node, Void p) {
            if (   node != null
                && jdctx.positions.getStartPosition(jdctx.javac.getCompilationUnit(), jdctx.comment, node) <= normalizedOffset
                && jdctx.positions.getEndPosition(jdctx.javac.getCompilationUnit(), jdctx.comment, node) >= normalizedOffset) {
                result[0] = new DocTreePath(getCurrentPath(), node);
                return super.scan(node, p);
            }
            
            return null;
        }
    }.scan(new DocTreePath(jdctx.javadocFor, jdctx.comment), null);
    
    return result[0];
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:JavadocCompletionQuery.java

示例8: insideTag

import com.sun.source.util.DocTreePath; //导入依赖的package包/类
private void insideTag(DocTreePath tag, JavadocContext jdctx) {
    switch (tag.getLeaf().getKind()) {
        case IDENTIFIER:
            if (tag.getParentPath() == null || tag.getParentPath().getLeaf().getKind() != Kind.PARAM)
                break;
            tag = tag.getParentPath();
            //intentional fall-through:
        case PARAM:
            insideParamTag(tag, jdctx);
            break;
        case SEE: case THROWS: case VALUE:
        case LINK: case LINK_PLAIN://XXX: was only unclosed???
            insideSeeTag(tag, jdctx);
            break;
        case REFERENCE:
            insideReference(tag, jdctx);
            break;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:JavadocCompletionQuery.java

示例9: completeParamName

import com.sun.source.util.DocTreePath; //导入依赖的package包/类
private void completeParamName(DocTreePath tag, String prefix, int substitutionOffset, JavadocContext jdctx) {
    if (EXECUTABLE.contains(jdctx.commentFor.getKind())) {
        List<? extends DocTree> blockTags = jdctx.comment.getBlockTags();
        ExecutableElement method = (ExecutableElement) jdctx.commentFor;
        for (VariableElement param : method.getParameters()) {
            String name = param.getSimpleName().toString();

            if (!containsParam(blockTags, name) && name.startsWith(prefix)) {
                items.add(JavadocCompletionItem.createNameItem(name, substitutionOffset));
            }
        }
        
        completeTypeVarName(jdctx.commentFor, prefix, substitutionOffset);
    } else if (jdctx.commentFor.getKind().isClass() || jdctx.commentFor.getKind().isInterface()) {
        completeTypeVarName(jdctx.commentFor, prefix, substitutionOffset);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:JavadocCompletionQuery.java

示例10: visitDocComment

import com.sun.source.util.DocTreePath; //导入依赖的package包/类
@Override
public Void visitDocComment(DocCommentTree node, List<ErrorDescription> errors) {
    DocTreePath currentDocPath = getCurrentPath();
    Void value = super.visitDocComment(node, errors);
    DocSourcePositions sp = (DocSourcePositions) javac.getTrees().getSourcePositions();

    while (!tagStack.isEmpty()) {
        StartElementTree startTree = tagStack.pop();
        Name tagName = startTree.getName();
        HtmlTag tag = HtmlTag.get(tagName);
        if (tag.endKind == HtmlTag.EndKind.REQUIRED) {
            int s = (int) sp.getStartPosition(javac.getCompilationUnit(), currentDocPath.getDocComment(), startTree);
            int e = (int) sp.getEndPosition(javac.getCompilationUnit(), currentDocPath.getDocComment(), startTree);
            errors.add(ErrorDescriptionFactory.forSpan(ctx, s, e, TAG_START_UNMATCHED(tagName)));
        }
    }
    return value;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:Analyzer.java

示例11: checkParamsDocumented

import com.sun.source.util.DocTreePath; //导入依赖的package包/类
private void checkParamsDocumented(List<? extends Element> list, List<? extends Tree> trees, DocTreePath docTreePath, Set<String> inheritedParams, List<ErrorDescription> errors) {
    if(foundInheritDoc) return;
    for (int i = 0; i < list.size() && i < trees.size(); i++) {
        if(ctx.isCanceled()) { return; }
        Element e = list.get(i);
        Tree t = trees.get(i);
        if (!foundParams.contains(e) && !inheritedParams.contains(e.getSimpleName().toString())) {
            boolean isTypeParam = e.getKind() == ElementKind.TYPE_PARAMETER;
            CharSequence paramName = (isTypeParam)
                    ? "<" + e.getSimpleName() + ">"
                    : e.getSimpleName();
            DocTreePathHandle dtph = DocTreePathHandle.create(docTreePath, javac);
            if (dtph != null) {
                errors.add(ErrorDescriptionFactory.forTree(ctx, t, MISSING_PARAM_DESC(paramName), AddTagFix.createAddParamTagFix(dtph, e.getSimpleName().toString(), isTypeParam, i).toEditorFix()));
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:Analyzer.java

示例12: checkThrowsDocumented

import com.sun.source.util.DocTreePath; //导入依赖的package包/类
private void checkThrowsDocumented(List<? extends TypeMirror> list, List<? extends ExpressionTree> trees, DocTreePath docTreePath, Set<String> inheritedThrows, List<ErrorDescription> errors) {
    if(foundInheritDoc) return;
    for (int i = 0; i < list.size(); i++) {
        if(ctx.isCanceled()) { return; }
        TypeMirror e = list.get(i);
        Tree t = trees.get(i);
        Types types = javac.getTypes();
        if (!foundThrows.contains(e) && !inheritedThrows.contains(e.toString())
                && (!(types.isAssignable(e, javac.getElements().getTypeElement("java.lang.Error").asType())
            || types.isAssignable(e, javac.getElements().getTypeElement("java.lang.RuntimeException").asType())))) {
            boolean found = false;
            for (TypeMirror typeMirror : foundThrows) {
                if(types.isAssignable(typeMirror, e)) {
                    found = true;
                    break;
                }
            }
            if(!found) {
                DocTreePathHandle dtph = DocTreePathHandle.create(docTreePath, javac);
                if(dtph != null) {
                    errors.add(ErrorDescriptionFactory.forTree(ctx, t, NbBundle.getMessage(Analyzer.class, "MISSING_THROWS_DESC", e.toString()), AddTagFix.createAddThrowsTagFix(dtph, e.toString(), i).toEditorFix()));
                }
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:Analyzer.java

示例13: performRewrite

import com.sun.source.util.DocTreePath; //导入依赖的package包/类
@Override
protected void performRewrite(TransformationContext ctx) throws Exception {
    WorkingCopy javac = ctx.getWorkingCopy();
    DocTreePath path = dtph.resolve(javac);
    if(path == null) {
        LOG.log(Level.WARNING, "Cannot resolve DocTreePathHandle: {0}", dtph);
        return;
    }
    DocCommentTree docComment = path.getDocComment();
    TreeMaker make = javac.getTreeMaker();
    final List<DocTree> blockTags = new LinkedList<DocTree>();
    for (DocTree docTree : docComment.getBlockTags()) {
        if (docTree != path.getLeaf()) {
            blockTags.add(docTree);
        }
    }
    DocCommentTree newDoc = make.DocComment(docComment.getFirstSentence(), docComment.getBody(), blockTags);
    Tree tree = ctx.getPath().getLeaf();
    javac.rewrite(tree, docComment, newDoc);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:RemoveTagFix.java

示例14: visitThrows

import com.sun.source.util.DocTreePath; //导入依赖的package包/类
@Override
public Void visitThrows(ThrowsTree tree, Void ignore) {
    ReferenceTree exName = tree.getExceptionName();
    Element ex = env.trees.getElement(new DocTreePath(getCurrentPath(), exName));
    if (ex == null) {
        env.messages.error(REFERENCE, tree, "dc.ref.not.found");
    } else if (isThrowable(ex.asType())) {
        switch (env.currElement.getKind()) {
            case CONSTRUCTOR:
            case METHOD:
                if (isCheckedException(ex.asType())) {
                    ExecutableElement ee = (ExecutableElement) env.currElement;
                    checkThrowsDeclared(exName, ex.asType(), ee.getThrownTypes());
                }
                break;
            default:
                env.messages.error(REFERENCE, tree, "dc.invalid.throws");
        }
    } else {
        env.messages.error(REFERENCE, tree, "dc.invalid.throws");
    }
    warnIfEmpty(tree, tree.getDescription());
    return scan(tree.getDescription(), ignore);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:Checker.java

示例15: visitThrows

import com.sun.source.util.DocTreePath; //导入依赖的package包/类
@Override @DefinedBy(Api.COMPILER_TREE)
public Void visitThrows(ThrowsTree tree, Void ignore) {
    ReferenceTree exName = tree.getExceptionName();
    Element ex = env.trees.getElement(new DocTreePath(getCurrentPath(), exName));
    if (ex == null) {
        env.messages.error(REFERENCE, tree, "dc.ref.not.found");
    } else if (isThrowable(ex.asType())) {
        switch (env.currElement.getKind()) {
            case CONSTRUCTOR:
            case METHOD:
                if (isCheckedException(ex.asType())) {
                    ExecutableElement ee = (ExecutableElement) env.currElement;
                    checkThrowsDeclared(exName, ex.asType(), ee.getThrownTypes());
                }
                break;
            default:
                env.messages.error(REFERENCE, tree, "dc.invalid.throws");
        }
    } else {
        env.messages.error(REFERENCE, tree, "dc.invalid.throws");
    }
    warnIfEmpty(tree, tree.getDescription());
    return scan(tree.getDescription(), ignore);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:Checker.java


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