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


Java Trees.getPath方法代码示例

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


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

示例1: visitNewClass

import com.sun.source.util.Trees; //导入方法依赖的package包/类
@Override
public Tree visitNewClass(NewClassTree node, Element p) {
    if(isCancelled.get()) {
        return null;
    }
    Trees trees = workingCopy.getTrees();
    ClassTree classTree = ((NewClassTree) node).getClassBody();
    if (classTree != null && p.getKind() == ElementKind.CONSTRUCTOR) {
        Element anonClass = workingCopy.getTrees().getElement(TreePath.getPath(workingCopy.getCompilationUnit(), classTree));
        if (anonClass == null) {
            Logger.getLogger("org.netbeans.modules.refactoring.java").log(Level.SEVERE, "FindUsages cannot resolve {0}", classTree); // NOI18N
        } else {
            for (ExecutableElement c : ElementFilter.constructorsIn(anonClass.getEnclosedElements())) {
                MethodTree t = workingCopy.getTrees().getTree(c);
                TreePath superCall = trees.getPath(workingCopy.getCompilationUnit(), ((ExpressionStatementTree) t.getBody().getStatements().get(0)).getExpression());
                Element superCallElement = trees.getElement(superCall);
                if (superCallElement != null && superCallElement.equals(p) && !workingCopy.getTreeUtilities().isSynthetic(superCall)) {
                    addUsage(superCall);
                }
            }
        }
    } else {
        addIfMatch(getCurrentPath(), node, p);
    }
    return super.visitNewClass(node, p);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:FindUsagesVisitor.java

示例2: 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

示例3: 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

示例4: process

import com.sun.source.util.Trees; //导入方法依赖的package包/类
public boolean process(Set<? extends TypeElement> annotations,
                       RoundEnvironment roundEnv) {
    new TestPathScanner<Void>() {
        @Override
        public void visit(Void t) {
        }
    };
    TypeElement currentClass = elements.getTypeElement("TypesCachesCleared");
    Trees trees = Trees.instance(processingEnv);
    TreePath path = trees.getPath(currentClass);
    new TreePathScanner<Void, Void>() {
        @Override public Void visitClass(ClassTree node, Void p) {
            trees.getElement(getCurrentPath());
            return super.visitClass(node, p);
        }
    }.scan(path, null);
    return false;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:TypesCachesCleared.java

示例5: process

import com.sun.source.util.Trees; //导入方法依赖的package包/类
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    Trees trees = Trees.instance(processingEnv);
    if (round++ == 0) {
        for (Element e: roundEnv.getRootElements()) {
            TreePath p = trees.getPath(e);
            new Scanner().scan(p, trees);
        }
    }
    return false;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:TestGetScope.java

示例6: checkChange

import com.sun.source.util.Trees; //导入方法依赖的package包/类
private boolean checkChange(CompilationController javac, PositionBounds span) throws IOException, BadLocationException {
    final int begin = span.getBegin().getOffset();
    final Trees trees = javac.getTrees();
    TreePath path = javac.getTreeUtilities().pathFor(begin + 1);
    if (path == null) {
        return false;
    }
    
    Element element = trees.getElement(path);
    if (element == null) {
        return false;
    }

    TreePath decl = trees.getPath(element);
    if (decl != null) {
        SourcePositions sourcePositions = trees.getSourcePositions();
        long declBegin = sourcePositions.getStartPosition(decl.getCompilationUnit(), decl.getLeaf());
        FileObject fo = SourceUtils.getFile(element, javac.getClasspathInfo());
        Document doc = javac.getDocument();
        GuardedSectionManager guards = GuardedSectionManager.getInstance((StyledDocument) doc);
        
        if (fo != javac.getFileObject() || guards != null && !isGuarded(guards, doc.createPosition((int) declBegin))) {
            // tree being refactored is declared outside of this file
            // or out of guarded sections. It should be safe to make change
            return true;
        }
    } else {
        // e.g. package; change is OK
            return true;
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:33,代码来源:BIGuardedBlockHandlerFactory.java

示例7: treeToType

import com.sun.source.util.Trees; //导入方法依赖的package包/类
private static TypeHelper treeToType(CompilationController cc, Tree tree, FormModel model) {
    String typeName = Object.class.getName();
    Map<String,TypeHelper> map = null;
    if (tree != null) {
        CompilationUnitTree cu = cc.getCompilationUnit();
        Trees trees = cc.getTrees();
        if (tree.getKind() == Tree.Kind.EXTENDS_WILDCARD) {
            tree = ((WildcardTree)tree).getBound();
        }
        TreePath path = trees.getPath(cu, tree);
        Element el = trees.getElement(path);
        if ((el != null) && ((el.getKind() == ElementKind.CLASS) || (el.getKind() == ElementKind.INTERFACE))) {
            TypeElement tel = (TypeElement) el;
            typeName = tel.getQualifiedName().toString();
            if (tree.getKind() == Tree.Kind.PARAMETERIZED_TYPE) {
                List<? extends Tree> params = ((ParameterizedTypeTree)tree).getTypeArguments();
                List<? extends TypeParameterElement> elems = tel.getTypeParameters();
                map = new HashMap<String,TypeHelper>();
                for (int i=0; i<params.size() && i<elems.size(); i++) {
                    Tree param = params.get(0);
                    TypeHelper paramType = treeToType(cc, param, model);
                    TypeParameterElement elem = elems.get(0);
                    map.put(elem.toString(), paramType);
                }
            }
        }
    }
    TypeHelper type = new TypeHelper(typeName, map);
    if (typeName.indexOf('.') != -1) {
        try {
            Class clazz = FormUtils.loadClass(typeName, model);
            type = new TypeHelper(clazz, map);
        } catch (ClassNotFoundException cnfex) {
            // not compiled - use just the name
        }
    }
    return type;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:BindingDesignSupportImpl.java

示例8: getTopLevelClassElement

import com.sun.source.util.Trees; //导入方法依赖的package包/类
public static TypeElement getTopLevelClassElement(CompilationController controller) {
    ClassTree classTree = getTopLevelClassTree(controller);
    if (classTree == null) {
        return null;
    }
    Trees trees = controller.getTrees();
    TreePath path = trees.getPath(controller.getCompilationUnit(), classTree);

    return (TypeElement) trees.getElement(path);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:JavaSourceHelper.java

示例9: process

import com.sun.source.util.Trees; //导入方法依赖的package包/类
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (roundEnv.processingOver())
        return true;

    Trees trees = Trees.instance(processingEnv);

    TypeElement testAnno = elements.getTypeElement("Check");
    for (Element elem: roundEnv.getElementsAnnotatedWith(testAnno)) {
        TreePath p = trees.getPath(elem);
        new MulticatchParamTester(trees).scan(p, null);
    }
    return true;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:ModelChecker.java

示例10: process

import com.sun.source.util.Trees; //导入方法依赖的package包/类
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (roundEnv.processingOver())
        return true;

    Trees trees = Trees.instance(processingEnv);

    TypeElement testAnno = elements.getTypeElement("Check");
    for (Element elem: roundEnv.getElementsAnnotatedWith(testAnno)) {
        TreePath p = trees.getPath(elem);
        new IntersectionCastTester(trees).scan(p, null);
    }
    return true;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:ModelChecker.java

示例11: process

import com.sun.source.util.Trees; //导入方法依赖的package包/类
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    Trees trees = Trees.instance(processingEnv);
    Elements elements = processingEnv.getElementUtils();
    Element pack = elements.getTypeElement("Test").getEnclosingElement();
    for (Element root : pack.getEnclosedElements()) {
        TreePath tp = trees.getPath(root);
        new OwnerCheck(trees, pack).scan(tp.getCompilationUnit(), null);

    }
    return false;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:LocalInAnonymous.java

示例12: process

import com.sun.source.util.Trees; //导入方法依赖的package包/类
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    for (Element root : roundEnv.getRootElements()) {
        processingEnv.getMessager().printMessage(Kind.ERROR, "error1", root);
        processingEnv.getMessager().printMessage(Kind.ERROR, "error2", root);

        Trees trees = Trees.instance(processingEnv);
        TreePath path = trees.getPath(root);

        trees.printMessage(Kind.ERROR, "error3", path.getLeaf(), path.getCompilationUnit());
        trees.printMessage(Kind.ERROR, "error4", path.getLeaf(), path.getCompilationUnit());
    }
    return true;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:TestMultipleErrors.java

示例13: asElement

import com.sun.source.util.Trees; //导入方法依赖的package包/类
private Element asElement(Tree tree) {
    Trees treeUtil = workingCopy.getTrees();
    TreePath treePath = treeUtil.getPath(workingCopy.getCompilationUnit(), tree);
    Element element = treeUtil.getElement(treePath);
    return element;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:7,代码来源:UseSuperTypeRefactoringPlugin.java

示例14: visitAssignment

import com.sun.source.util.Trees; //导入方法依赖的package包/类
@Override
public Tree visitAssignment(AssignmentTree node, Element p) {
    if (!refactoring.getReplace()) {
        return super.visitAssignment(node, p);
    }
    ExpressionTree variable = node.getVariable();
    boolean isArray = false;
    while (variable.getKind() == Tree.Kind.ARRAY_ACCESS) {
        isArray = true;
        // int[] a; a[a[0]][a[1]] = 0; // scan also array indices
        scan(((ArrayAccessTree) variable).getIndex(), p);
        variable = ((ArrayAccessTree) variable).getExpression();
    }

    Element el = workingCopy.getTrees().getElement(new TreePath(getCurrentPath(), variable));
    if(el != null) {
    Element enclosingElement = el.getEnclosingElement();
    if (enclosingElement != null && enclosingElement.equals(p)
            && (isArray || checkAssignmentInsideExpression())) {
        ElementHandle<Element> handle = ElementHandle.create(el);
        String[] getterSetter = getterSetterMap.get(handle); // TODO: Check for null and solve !
        if (getterSetter != null) {
            if (isArray) {
                ExpressionTree invkgetter = createGetterInvokation(variable, getterSetter[0]);
                rewrite(variable, invkgetter);
            } else {
                ExpressionTree setter = createMemberSelection(variable, getterSetter[1]);

                // resolve types
                Trees trees = workingCopy.getTrees();
                ExpressionTree expTree = node.getExpression();
                ExpressionTree newExpTree;
                TreePath varPath = trees.getPath(workingCopy.getCompilationUnit(), variable);
                TreePath expPath = trees.getPath(workingCopy.getCompilationUnit(), expTree);
                TypeMirror varType = trees.getTypeMirror(varPath);
                TypeMirror expType = trees.getTypeMirror(expPath);
                if (workingCopy.getTypes().isSubtype(expType, varType)) {
                    newExpTree = expTree;
                } else {
                    newExpTree = make.TypeCast(make.Type(varType), expTree);
                }

                MethodInvocationTree invksetter = make.MethodInvocation(
                        Collections.<ExpressionTree>emptyList(),
                        setter,
                        Collections.singletonList(newExpTree));

                rewrite(node, invksetter);
            }
        }
        }
    }
    return scan(node.getExpression(), p);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:55,代码来源:IntroduceLocalExtensionTransformer.java

示例15: visitUnary

import com.sun.source.util.Trees; //导入方法依赖的package包/类
@Override
public Tree visitUnary(UnaryTree node, Element p) {
    if (!refactoring.getReplace()) {
        return super.visitUnary(node, p);
    }
    ExpressionTree t = node.getExpression();
    Tree.Kind kind = node.getKind();
    boolean isArrayOrImmutable = kind != Tree.Kind.POSTFIX_DECREMENT
            && kind != Tree.Kind.POSTFIX_INCREMENT
            && kind != Tree.Kind.PREFIX_DECREMENT
            && kind != Tree.Kind.PREFIX_INCREMENT;
    while (t.getKind() == Tree.Kind.ARRAY_ACCESS) {
        isArrayOrImmutable = true;
        t = ((ArrayAccessTree) t).getExpression();
    }
    Element el = workingCopy.getTrees().getElement(new TreePath(getCurrentPath(), t));
    if (el != null) {
        Element enclosingElement = el.getEnclosingElement();
        if (enclosingElement != null && enclosingElement.equals(p)
                && (isArrayOrImmutable || checkAssignmentInsideExpression())) {
            ElementHandle<Element> handle = ElementHandle.create(el);
            String[] getterSetter = getterSetterMap.get(handle); // TODO: Check for null and solve !
            // check (++field + 3)
            if (getterSetter != null) {
                ExpressionTree invkgetter = createGetterInvokation(t, getterSetter[0]);
                if (isArrayOrImmutable) {
                    rewrite(t, invkgetter);
                } else {
                    ExpressionTree setter = createMemberSelection(node.getExpression(), getterSetter[1]);

                    Tree.Kind operator = kind == Tree.Kind.POSTFIX_INCREMENT || kind == Tree.Kind.PREFIX_INCREMENT
                            ? Tree.Kind.PLUS
                            : Tree.Kind.MINUS;

                    // resolve types
                    Trees trees = workingCopy.getTrees();
                    ExpressionTree expTree = node.getExpression();
                    TreePath varPath = trees.getPath(workingCopy.getCompilationUnit(), expTree);
                    TypeMirror varType = trees.getTypeMirror(varPath);
                    TypeMirror expType = workingCopy.getTypes().getPrimitiveType(TypeKind.INT);
                    ExpressionTree newExpTree = make.Binary(operator, invkgetter, make.Literal(1));
                    if (!workingCopy.getTypes().isSubtype(expType, varType)) {
                        newExpTree = make.TypeCast(make.Type(varType), make.Parenthesized(newExpTree));
                    }

                    MethodInvocationTree invksetter = make.MethodInvocation(
                            Collections.<ExpressionTree>emptyList(),
                            setter,
                            Collections.singletonList(newExpTree));
                    rewrite(node, invksetter);
                }
            }
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:57,代码来源:IntroduceLocalExtensionTransformer.java


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