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


Java CompilationInfo.getTreeUtilities方法代码示例

本文整理汇总了Java中org.netbeans.api.java.source.CompilationInfo.getTreeUtilities方法的典型用法代码示例。如果您正苦于以下问题:Java CompilationInfo.getTreeUtilities方法的具体用法?Java CompilationInfo.getTreeUtilities怎么用?Java CompilationInfo.getTreeUtilities使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.netbeans.api.java.source.CompilationInfo的用法示例。


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

示例1: run

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
@Override
public List<Fix> run(CompilationInfo compilationInfo, String diagnosticKey, int offset, TreePath treePath, Data<Void> data) {
    if (treePath.getLeaf().getKind() == Kind.METHOD) {
        MethodTree mt = (MethodTree) treePath.getLeaf();
        TreePath parentPath = treePath.getParentPath();
        ClassTree ct = (ClassTree) parentPath.getLeaf();
        Trees trees = compilationInfo.getTrees();
        Types types = compilationInfo.getTypes();
        TreeUtilities tu = compilationInfo.getTreeUtilities();
        TypeMirror type = types.erasure(trees.getTypeMirror(treePath));
        if (!Utilities.isValidType(type)) {
            return null;
        }
        for (Tree member : ct.getMembers()) {
            TreePath memberPath = new TreePath(parentPath, member);
            if (member.getKind() == Kind.METHOD && "<init>".contentEquals(((MethodTree)member).getName()) //NOI18N
                    && !tu.isSynthetic(memberPath) && types.isSameType(types.erasure(trees.getTypeMirror(memberPath)), type)) {
                return null;
            }
        }
        RenameConstructorFix fix = new RenameConstructorFix(compilationInfo.getSnapshot().getSource(), TreePathHandle.create(treePath, compilationInfo), offset, mt.getName(), ct.getSimpleName());
        return Collections.<Fix>singletonList(fix);
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:RenameConstructor.java

示例2: addInnerClasses

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
private void addInnerClasses(TypeElement te, EnumSet<ElementKind> kinds, DeclaredType baseType, Set<? extends Element> toExclude, String prefix, int substitutionOffset, JavadocContext jdctx) {
    CompilationInfo controller = jdctx.javac;
    Element srcEl = jdctx.handle.resolve(controller);
    Elements elements = controller.getElements();
    Types types = controller.getTypes();
    Trees trees = controller.getTrees();
    TreeUtilities tu = controller.getTreeUtilities();
    TreePath docpath = srcEl != null ? trees.getPath(srcEl) : null;
    Scope scope = docpath != null ? trees.getScope(docpath) : tu.scopeFor(caretOffset);
    for (Element e : controller.getElementUtilities().getMembers(te.asType(), null)) {
        if ((e.getKind().isClass() || e.getKind().isInterface()) && (toExclude == null || !toExclude.contains(e))) {
            String name = e.getSimpleName().toString();
                if (Utilities.startsWith(name, prefix) && (Utilities.isShowDeprecatedMembers() || !elements.isDeprecated(e)) && trees.isAccessible(scope, (TypeElement)e) && isOfKindAndType(e.asType(), e, kinds, baseType, scope, trees, types)) {
                    items.add(JavadocCompletionItem.createTypeItem(jdctx.javac, (TypeElement) e, substitutionOffset, null, elements.isDeprecated(e)/*, isOfSmartType(env, e.asType(), smartTypes)*/));
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:JavadocCompletionQuery.java

示例3: addPackageContent

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
private void addPackageContent(PackageElement pe, EnumSet<ElementKind> kinds, DeclaredType baseType, Set<? extends Element> toExclude, String prefix, int substitutionOffset, JavadocContext jdctx) {
    CompilationInfo controller = jdctx.javac;
    Element srcEl = jdctx.handle.resolve(controller);
    Elements elements = controller.getElements();
    Types types = controller.getTypes();
    Trees trees = controller.getTrees();
    TreeUtilities tu = controller.getTreeUtilities();
    ElementUtilities eu = controller.getElementUtilities();
    TreePath docpath = srcEl != null ? trees.getPath(srcEl) : null;
    Scope scope = docpath != null ? trees.getScope(docpath) : tu.scopeFor(caretOffset);
    for(Element e : pe.getEnclosedElements()) {
        if ((e.getKind().isClass() || e.getKind().isInterface()) && (toExclude == null || !toExclude.contains(e))) {
            String name = e.getSimpleName().toString();
                if (Utilities.startsWith(name, prefix) && (Utilities.isShowDeprecatedMembers() || !elements.isDeprecated(e))
                    && trees.isAccessible(scope, (TypeElement)e)
                    && isOfKindAndType(e.asType(), e, kinds, baseType, scope, trees, types)
                    && !Utilities.isExcluded(eu.getElementName(e, true))) {
                    items.add(JavadocCompletionItem.createTypeItem(jdctx.javac, (TypeElement) e, substitutionOffset, null, elements.isDeprecated(e)/*, isOfSmartType(env, e.asType(), smartTypes)*/));
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:JavadocCompletionQuery.java

示例4: findUsages

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
public void findUsages(Element element, CompilationInfo info, Document doc, boolean searchComment) {
    this.info = info;
    this.usages = new HashSet<>();
    this.comments = new HashSet<>();
    this.toFind = element;
    this.doc = doc;
    this.searchComment = searchComment;
    this.treeUtils = info.getTreeUtilities();
    this.sp = info.getTrees().getSourcePositions();
    this.docScanner = new DocTreePathScannerImpl();
    
    scan(info.getCompilationUnit(), null);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:FindLocalUsagesQuery.java

示例5: widenToElementBounds

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
private TreePath widenToElementBounds(CompilationInfo cInfo, BaseDocument doc, int[] bounds) {
    SourcePositions sp = cInfo.getTrees().getSourcePositions();
    TreeUtilities tu = cInfo.getTreeUtilities();
    int startOffset = getLineStart(doc, bounds[0]);
    int endOffset = getLineEnd(doc, bounds[1]);
    while (true) {
        TokenSequence<JavaTokenId> ts = SourceUtils.getJavaTokenSequence(cInfo.getTokenHierarchy(), startOffset);
        if (ts != null && (ts.moveNext() || ts.movePrevious())) {
            if (ts.offset() < startOffset && ts.token().id() != JavaTokenId.WHITESPACE) {
                startOffset = getLineStart(doc, ts.offset());
                continue;
            }
        }
        ts = SourceUtils.getJavaTokenSequence(cInfo.getTokenHierarchy(), endOffset);
        if (ts != null && (ts.moveNext() || ts.movePrevious())) {
            if (ts.offset() < endOffset && ts.token().id() != JavaTokenId.WHITESPACE) {
                endOffset = getLineEnd(doc, ts.offset() + ts.token().length());
                continue;
            }
        }
        boolean finish = true;
        TreePath tp = tu.pathFor(startOffset);
        while (tp != null) {
            Tree leaf = tp.getLeaf();
            List<? extends Tree> children = null;
            switch (leaf.getKind()) {
                case BLOCK:
                    if (endOffset < sp.getEndPosition(tp.getCompilationUnit(), leaf)) {
                        children = ((BlockTree) leaf).getStatements();
                    }
                    break;
                case CLASS:
                case INTERFACE:
                case ANNOTATION_TYPE:
                case ENUM:
                    if (endOffset < sp.getEndPosition(tp.getCompilationUnit(), leaf)) {
                        children = ((ClassTree) leaf).getMembers();
                    }
                    break;
            }
            if (children != null) {
                for (Tree tree : children) {
                    int startPos = (int) sp.getStartPosition(tp.getCompilationUnit(), tree);
                    int endPos = (int) sp.getEndPosition(tp.getCompilationUnit(), tree);
                    if (endPos > startOffset) {
                        if (startPos < startOffset) {
                            startOffset = getLineStart(doc, startPos);
                            finish = false;
                        }
                        if (startPos < endOffset && endOffset < endPos) {
                            endOffset = getLineEnd(doc, endPos);
                            finish = false;
                        }
                    }
                }
                break;
            }
            tp = tp.getParentPath();
        }
        if (finish) {
            bounds[0] = startOffset;
            bounds[1] = endOffset;
            return tp;
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:67,代码来源:JavaMoveCodeElementAction.java

示例6: findDestinationOffset

import org.netbeans.api.java.source.CompilationInfo; //导入方法依赖的package包/类
private int findDestinationOffset(CompilationInfo cInfo, BaseDocument doc, int offset, boolean insideBlock) {
    TreeUtilities tu = cInfo.getTreeUtilities();
    SourcePositions sp = cInfo.getTrees().getSourcePositions();
    while (true) {
        if (offset < 0 || offset > doc.getLength()) {
            return -1;
        }
        int destinationOffset = downward ? getLineEnd(doc, offset) : getLineStart(doc, offset);
        if (doc instanceof GuardedDocument && ((GuardedDocument)doc).isPosGuarded(destinationOffset)) {
            return -1;
        }
        if (destinationOffset < doc.getLength()) {
            TokenSequence<JavaTokenId> ts = SourceUtils.getJavaTokenSequence(cInfo.getTokenHierarchy(), destinationOffset);
            if (ts != null && (ts.moveNext() || ts.movePrevious())) {
                if (ts.offset() < destinationOffset && ts.token().id() != JavaTokenId.WHITESPACE) {
                    offset = downward ? ts.offset() + ts.token().length() : ts.offset();
                    continue;
                }
            }
        }
        TreePath destinationPath = tu.pathFor(destinationOffset);
        Tree leaf = destinationPath.getLeaf();
        if (insideBlock) {
            switch (leaf.getKind()) {
                case COMPILATION_UNIT:
                    return -1;
                case BLOCK:
                    return destinationOffset;
                case IF:
                case FOR_LOOP:
                case ENHANCED_FOR_LOOP:
                case WHILE_LOOP:
                case DO_WHILE_LOOP:
                case SWITCH:
                case CASE:
                case SYNCHRONIZED:
                case TRY:
                case CATCH:
                    offset = destinationOffset + (downward ? 1 : -1);
                    break;
                default:
                    offset = downward
                            ? (int) sp.getEndPosition(destinationPath.getCompilationUnit(), leaf)
                            : (int) sp.getStartPosition(destinationPath.getCompilationUnit(), leaf);
            }
        } else {
            switch (leaf.getKind()) {
                case COMPILATION_UNIT:
                    return -1;
                case CLASS:
                case INTERFACE:
                case ANNOTATION_TYPE:
                case ENUM:
                    return destinationOffset;
                default:
                    offset = downward
                            ? (int) sp.getEndPosition(destinationPath.getCompilationUnit(), leaf)
                            : (int) sp.getStartPosition(destinationPath.getCompilationUnit(), leaf);
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:63,代码来源:JavaMoveCodeElementAction.java


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