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


Java ReferenceTree类代码示例

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


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

示例1: visitReference

import com.sun.source.doctree.ReferenceTree; //导入依赖的package包/类
@Override
public Void visitReference(ReferenceTree node, Void p) {
    //TODO: should use formatting settings:
    DCReference refNode = (DCReference) node;
    if (refNode.qualifierExpression != null) {
        print(refNode.qualifierExpression);
    }
    if (refNode.memberName != null) {
        print("#");
        print(refNode.memberName);
    }
    if (refNode.paramTypes != null) {
        print("(");
        boolean first = true;
        for (Tree param : refNode.paramTypes) {
            if (!first) print(", ");
            print(param.toString());
            first = false;
        }
        print(")");
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:VeryPretty.java

示例2: visitReference

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

示例3: visitReference

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

示例4: visitThrows

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

示例5: visitThrows

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

示例6: checkReference

import com.sun.source.doctree.ReferenceTree; //导入依赖的package包/类
void checkReference(ReferenceTree tree, List<? extends DocTree> label) {
    String sig = tree.getSignature();

    Element found = trees.getElement(new DocTreePath(getCurrentPath(), tree));
    if (found == null) {
        System.err.println(sig + " NOT FOUND");
    } else {
        System.err.println(sig + " found " + found.getKind() + " " + found);
    }

    String expect = "UNKNOWN";
    if (label.size() > 0 && label.get(0) instanceof TextTree)
        expect = ((TextTree) label.get(0)).getBody();

    if (!expect.equalsIgnoreCase(found == null ? "bad" : found.getKind().name())) {
        error(tree, "Unexpected value found: " + found +", expected: " + expect);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:ReferenceTest.java

示例7: appendReference

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

示例8: rewriteChildren

import com.sun.source.doctree.ReferenceTree; //导入依赖的package包/类
protected final LinkTree rewriteChildren(LinkTree tree) {
    LinkTree value = tree;
    List<? extends DocTree> label = translateDoc(tree.getLabel());
    ReferenceTree ref = (ReferenceTree) translate(tree.getReference());
    if (label != tree.getLabel() || ref != tree.getReference()) {
        value = make.Link(ref, label);
    }
    return value;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:ImmutableDocTreeTranslator.java

示例9: visitSee

import com.sun.source.doctree.ReferenceTree; //导入依赖的package包/类
@Override
public Void visitSee(SeeTree node, Void p) {
    printTagName(node);
    boolean first = true;
    boolean needSep = true;
    for (DocTree t: node.getReference()) {
        if (needSep) print(" ");
        needSep = (first && (t instanceof ReferenceTree));
        first = false;
        print((DCTree)t);
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:VeryPretty.java

示例10: Reference

import com.sun.source.doctree.ReferenceTree; //导入依赖的package包/类
public ReferenceTree Reference(ExpressionTree qualExpr, CharSequence member, List<? extends Tree> paramTypes) {
    com.sun.tools.javac.util.List<JCTree> paramTypesList = null;
    if (paramTypes != null) {
        ListBuffer<JCTree> lbl = new ListBuffer<>();
        for (Tree t : paramTypes) {
            lbl.append((JCTree) t);
        }
        paramTypesList = lbl.toList();
    }
    return docMake.at(NOPOS).newReferenceTree("", (JCExpression) qualExpr, member != null ? (Name) names.fromString(member.toString()) : null, paramTypesList);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:TreeFactory.java

示例11: findNameSpan

import com.sun.source.doctree.ReferenceTree; //导入依赖的package包/类
/**Find span of the name in the DocTree's reference tree (see {@link #getReferenceName(com.sun.source.util.DocTreePath)}
 * identifier in the source. Returns starting and ending offset of the name in
 * the source code that was parsed (ie. {@link CompilationInfo.getText()}, which
 * may differ from the positions in the source document if it has been already
 * altered.
 * 
 * @param ref reference for which the identifier should be found
 * @return the span of the name, or null if cannot be found
 * @since 0.124
 */
public int[] findNameSpan(DocCommentTree docTree, ReferenceTree ref) {
    Name name = ((DCReference) ref).memberName;
    if (name == null || !SourceVersion.isIdentifier(name)) {
        //names like "<error>", etc.
        return null;
    }
    
    int pos = (int) info.getDocTrees().getSourcePositions().getStartPosition(info.getCompilationUnit(), docTree, ref);
    
    if (pos < 0)
        return null;
    
    TokenSequence<JavaTokenId> tokenSequence = info.getTokenHierarchy().tokenSequence(JavaTokenId.language());
    
    tokenSequence.move(pos);
    
    if (!tokenSequence.moveNext() || tokenSequence.token().id() != JavaTokenId.JAVADOC_COMMENT) return null;
    
    TokenSequence<JavadocTokenId> jdocTS = tokenSequence.embedded(JavadocTokenId.language());
    
    jdocTS.move(pos);
    
    boolean wasNext;
    
    while ((wasNext = jdocTS.moveNext()) && jdocTS.token().id() != JavadocTokenId.HASH)
        ;
    
    if (wasNext && jdocTS.moveNext()) {
        if (jdocTS.token().id() == JavadocTokenId.IDENT &&
            name.contentEquals(jdocTS.token().text())) {
            return new int[] {
                jdocTS.offset(),
                jdocTS.offset() + jdocTS.token().length()
            };
        }
    }
    
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:50,代码来源:TreeUtilities.java

示例12: visitReference

import com.sun.source.doctree.ReferenceTree; //导入依赖的package包/类
@Override
public Void visitReference(ReferenceTree tree, Void ignore) {
    String sig = tree.getSignature();
    if (sig.contains("<") || sig.contains(">"))
        env.messages.error(REFERENCE, tree, "dc.type.arg.not.allowed");

    Element e = env.trees.getElement(getCurrentPath());
    if (e == null)
        env.messages.error(REFERENCE, tree, "dc.ref.not.found");
    return super.visitReference(tree, ignore);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:Checker.java

示例13: checkThrowsDeclared

import com.sun.source.doctree.ReferenceTree; //导入依赖的package包/类
private void checkThrowsDeclared(ReferenceTree tree, TypeMirror t, List<? extends TypeMirror> list) {
    boolean found = false;
    for (TypeMirror tl : list) {
        if (env.types.isAssignable(t, tl)) {
            foundThrows.add(tl);
            found = true;
        }
    }
    if (!found)
        env.messages.error(REFERENCE, tree, "dc.exception.not.thrown", t);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:Checker.java

示例14: visitValue

import com.sun.source.doctree.ReferenceTree; //导入依赖的package包/类
@Override
public Void visitValue(ValueTree tree, Void ignore) {
    ReferenceTree ref = tree.getReference();
    if (ref == null || ref.getSignature().isEmpty()) {
        if (!isConstant(env.currElement))
            env.messages.error(REFERENCE, tree, "dc.value.not.allowed.here");
    } else {
        Element e = env.trees.getElement(new DocTreePath(getCurrentPath(), ref));
        if (!isConstant(e))
            env.messages.error(REFERENCE, tree, "dc.value.not.a.constant");
    }

    markEnclosingTag(Flag.HAS_INLINE_TAG);
    return super.visitValue(tree, ignore);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:16,代码来源:Checker.java

示例15: visitProvides

import com.sun.source.doctree.ReferenceTree; //导入依赖的package包/类
@Override @DefinedBy(Api.COMPILER_TREE)
public Void visitProvides(ProvidesTree tree, Void ignore) {
    Element e = env.trees.getElement(env.currPath);
    if (e.getKind() != ElementKind.MODULE) {
        env.messages.error(REFERENCE, tree, "dc.invalid.provides");
    }
    ReferenceTree serviceType = tree.getServiceType();
    Element se = env.trees.getElement(new DocTreePath(getCurrentPath(), serviceType));
    if (se == null) {
        env.messages.error(REFERENCE, tree, "dc.service.not.found");
    }
    return super.visitProvides(tree, ignore);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:Checker.java


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