Java Code Examples for com.sun.source.util.Trees#getScope()

The following examples show how to use com.sun.source.util.Trees#getScope() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RenameTransformer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 2
Source File: CreateMethodFix.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 3
Source File: JavadocCompletionQuery.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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)*/));
            }
        }
    }
}
 
Example 4
Source File: JavadocCompletionQuery.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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)*/));
            }
        }
    }
}
 
Example 5
Source File: TestGetScope.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Void visitIdentifier(IdentifierTree t, Trees trees) {
    System.err.println("visitIdentifier: " + t);
    trees.getScope(getCurrentPath());
    return null;
}
 
Example 6
Source File: TestGetScope.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Void visitIdentifier(IdentifierTree t, Trees trees) {
    System.err.println("visitIdentifier: " + t);
    trees.getScope(getCurrentPath());
    return null;
}
 
Example 7
Source File: TestGetScope.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Void visitIdentifier(IdentifierTree t, Trees trees) {
    System.err.println("visitIdentifier: " + t);
    trees.getScope(getCurrentPath());
    return null;
}
 
Example 8
Source File: TestGetScope.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Void visitIdentifier(IdentifierTree t, Trees trees) {
    System.err.println("visitIdentifier: " + t);
    trees.getScope(getCurrentPath());
    return null;
}
 
Example 9
Source File: TestGetScope.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Void visitIdentifier(IdentifierTree t, Trees trees) {
    System.err.println("visitIdentifier: " + t);
    trees.getScope(getCurrentPath());
    return null;
}
 
Example 10
Source File: TestGetScope.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Void visitIdentifier(IdentifierTree t, Trees trees) {
    System.err.println("visitIdentifier: " + t);
    trees.getScope(getCurrentPath());
    return null;
}
 
Example 11
Source File: TestGetScope.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Void visitIdentifier(IdentifierTree t, Trees trees) {
    System.err.println("visitIdentifier: " + t);
    trees.getScope(getCurrentPath());
    return null;
}
 
Example 12
Source File: TestGetScope.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Void visitIdentifier(IdentifierTree t, Trees trees) {
    System.err.println("visitIdentifier: " + t);
    trees.getScope(getCurrentPath());
    return null;
}