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


Java Trees.getScope方法代码示例

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


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

示例1: visitClass

import com.sun.source.util.Trees; //导入方法依赖的package包/类
@Override
public Tree visitClass(ClassTree tree, final Element p) {
    final TreePath currentPath = getCurrentPath();
    renameDeclIfMatch(getCurrentPath(), tree, p);
    Element el = workingCopy.getTrees().getElement(currentPath);
    if (el != null && el.getEnclosedElements().contains(p)) {
        Trees trees = workingCopy.getTrees();
        Scope scope = trees.getScope(trees.getPath(p));
        shadowed = workingCopy.getElementUtilities().getLocalMembersAndVars(scope, new ElementUtilities.ElementAcceptor() {

            @Override
            public boolean accept(Element element, TypeMirror type) {
                return !element.equals(p) && element.getKind().equals(p.getKind()) && element.getSimpleName().contentEquals(newName);
            }
        });
    }
    Tree value = super.visitClass(tree, p);
    shadowed = null;
    return value;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:RenameTransformer.java

示例2: createDefaultMethodBody

import com.sun.source.util.Trees; //导入方法依赖的package包/类
private static BlockTree createDefaultMethodBody(WorkingCopy wc, TreePath targetTree, TypeMirror returnType, String name) {
    TreeUtilities tu = wc.getTreeUtilities();
    TypeElement targetClazz = (TypeElement)wc.getTrees().getElement(targetTree);
    StatementTree st = tu.parseStatement("{class ${abstract " + (returnType != null ? returnType.toString() : "void") + " " + ("<init>".equals(name) ? targetClazz.getSimpleName() : name) + "();}}", new SourcePositions[1]); //NOI18N
    Trees trees = wc.getTrees();
    List<? extends Tree> members = ((ClassTree) targetTree.getLeaf()).getMembers();
    Scope scope = members.isEmpty() ? trees.getScope(targetTree) : trees.getScope(new TreePath(targetTree, members.get(0)));
    tu.attributeTree(st, scope);
    Tree first = null;
    for(Tree t : ((ClassTree)((BlockTree)st).getStatements().get(0)).getMembers()) {
        if (t.getKind() == Tree.Kind.METHOD && !"<init>".contentEquals(((MethodTree)t).getName())) { //NOI19N
            first = t;
            break;
        }
    }
    ExecutableElement ee = (ExecutableElement) wc.getTrees().getElement(new TreePath(targetTree, first));
    return GeneratorUtilities.get(wc).createAbstractMethodImplementation(targetClazz, ee).getBody();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:CreateMethodFix.java

示例3: addInnerClasses

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

示例4: addPackageContent

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

示例5: typeToImport

import com.sun.source.util.Trees; //导入方法依赖的package包/类
private static TypeMirror typeToImport(CompilationInfo info, TreePath tp, TypeMirror origin) {
    if (tp.getLeaf().getKind() == Tree.Kind.MEMBER_SELECT) {
        MemberSelectTree mst = (MemberSelectTree) tp.getLeaf();
        if (mst.getExpression().getKind() == Tree.Kind.IDENTIFIER) {
            ClassIndex index = info.getClasspathInfo().getClassIndex();
            Types types = info.getTypes();
            Trees trees = info.getTrees();
            Scope scope = trees.getScope(tp);
            for (ElementHandle<TypeElement> teHandle : index.getDeclaredTypes(((IdentifierTree)mst.getExpression()).getName().toString(), ClassIndex.NameKind.SIMPLE_NAME, EnumSet.allOf(ClassIndex.SearchScope.class))) {
                TypeElement te = teHandle.resolve(info);
                if (te != null && trees.isAccessible(scope, te)) {
                    TypeMirror toImport = te.asType();
                    if (types.isSubtype(toImport, origin)) {
                        return toImport;
                    }
                }
            }
        }
    }
    return origin;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:JavaCompletionItem.java

示例6: visitIdentifier

import com.sun.source.util.Trees; //导入方法依赖的package包/类
@Override
public Void visitIdentifier(IdentifierTree t, Trees trees) {
    System.err.println("visitIdentifier: " + t);
    trees.getScope(getCurrentPath());
    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:TestGetScope.java


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