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


Java Tree.getKind方法代码示例

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


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

示例1: visitImport

import com.sun.source.tree.Tree; //导入方法依赖的package包/类
@Override
public Void visitImport(ImportTree node, Void p) {
    if (node.isStatic() && toFind.getModifiers().contains(Modifier.STATIC)) {
        Tree qualIdent = node.getQualifiedIdentifier();
        if (qualIdent.getKind() == Kind.MEMBER_SELECT) {
            MemberSelectTree mst = (MemberSelectTree) qualIdent;
            if (toFind.getSimpleName().contentEquals(mst.getIdentifier())) {
                Element el = info.getTrees().getElement(new TreePath(getCurrentPath(), mst.getExpression()));
                if (el != null && el.equals(toFind.getEnclosingElement())) {
                    try {
                        int[] span = treeUtils.findNameSpan(mst);
                        if(span != null) {
                            MutablePositionRegion region = createRegion(doc, span[0], span[1]);
                            usages.add(region);
                        }
                    } catch (BadLocationException ex) {
                        Exceptions.printStackTrace(ex);
                    }
                }
            }
        }
    }
    return super.visitImport(node, p);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:FindLocalUsagesQuery.java

示例2: isValid

import com.sun.source.tree.Tree; //导入方法依赖的package包/类
static boolean isValid(CompilationInfo javac, TreePath path, Severity severity, Access access, int caret) {
    Tree leaf = path.getLeaf();
    boolean onLine = severity == Severity.HINT && caret > -1;
    switch (leaf.getKind()) {
        case ANNOTATION_TYPE:
        case CLASS:
        case ENUM:
        case INTERFACE:
            return access.isAccessible(javac, path, false) && (!onLine || isInHeader(javac, (ClassTree) leaf, caret));
        case METHOD:
            return access.isAccessible(javac, path, false) && (!onLine || isInHeader(javac, (MethodTree) leaf, caret));
        case VARIABLE:
            return access.isAccessible(javac, path, false);
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:JavadocUtilities.java

示例3: findSuppressedWarnings

import com.sun.source.tree.Tree; //导入方法依赖的package包/类
public static Set<? extends String> findSuppressedWarnings(CompilationInfo info, TreePath path) {
    //TODO: cache?
    Set<String> keys = new HashSet<String>();

    while (path != null) {
        Tree leaf = path.getLeaf();

        switch (leaf.getKind()) {
            case METHOD:
                handleSuppressWarnings(info, path, ((MethodTree) leaf).getModifiers(), keys);
                break;
            case CLASS:
                handleSuppressWarnings(info, path, ((ClassTree) leaf).getModifiers(), keys);
                break;
            case VARIABLE:
                handleSuppressWarnings(info, path, ((VariableTree) leaf).getModifiers(), keys);
                break;
        }

        path = path.getParentPath();
    }

    return Collections.unmodifiableSet(keys);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:Utilities.java

示例4: invocationOnThis

import com.sun.source.tree.Tree; //导入方法依赖的package包/类
private static boolean invocationOnThis(MethodInvocationTree mit) {
    Tree select = mit.getMethodSelect();
    
    switch (select.getKind()) {
        case IDENTIFIER:
            return true;
        case MEMBER_SELECT:
            if (((MemberSelectTree) select).getExpression().getKind() == Kind.IDENTIFIER) {
                IdentifierTree ident = (IdentifierTree) ((MemberSelectTree) select).getExpression();

                return ident.getName().contentEquals("this");
            }
    }

    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:OverridableMethodCallInConstructor.java

示例5: findMethod

import com.sun.source.tree.Tree; //导入方法依赖的package包/类
static TreePath findMethod(TreePath path, boolean methodOnly) {
    while (path != null) {
        Tree leaf = path.getLeaf();
        switch (leaf.getKind()) {
            case BLOCK:
                if (path.getParentPath() != null && TreeUtilities.CLASS_TREE_KINDS.contains(path.getParentPath().getLeaf().getKind())) {
                    return path;
                }
                break;
            case LAMBDA_EXPRESSION:
                if (methodOnly) {
                    break;
                }
            case METHOD:
                return path;
            default:
                break;
        }
        path = path.getParentPath();
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:TreeUtils.java

示例6: disambiguateDeclarationVsExpression

import com.sun.source.tree.Tree; //导入方法依赖的package包/类
public Completeness disambiguateDeclarationVsExpression() {
    // String folding messes up position information.
    ParseTask pt = parseFactory.get();
    List<? extends Tree> units = pt.units();
    if (units.isEmpty()) {
        return error();
    }
    Tree unitTree = units.get(0);
    switch (unitTree.getKind()) {
        case EXPRESSION_STATEMENT:
            return parseExpressionOptionalSemi();
        case LABELED_STATEMENT:
            if (shouldAbort(IDENTIFIER))  return checkResult;
            if (shouldAbort(COLON))  return checkResult;
        return parseStatement();
        case VARIABLE:
        case IMPORT:
        case CLASS:
        case ENUM:
        case ANNOTATION_TYPE:
        case INTERFACE:
        case METHOD:
            return parseDeclaration();
        default:
            return error();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:CompletenessAnalyzer.java

示例7: method

import com.sun.source.tree.Tree; //导入方法依赖的package包/类
MethodTree method(MethodSnippet msn) {
    if (targetClass == null) {
        return null;
    }
    OuterWrap ow = msn.outerWrap();
    if (!(ow instanceof OuterSnippetsClassWrap)) {
        return null;
    }
    int ordinal = ((OuterSnippetsClassWrap) ow).ordinal(msn);
    if (ordinal < 0) {
        return null;
    }
    int count = 0;
    String name = msn.name();
    for (Tree mem : targetClass.getMembers()) {
        if (mem.getKind() == Tree.Kind.METHOD) {
            MethodTree mt = (MethodTree) mem;
            if (mt.getName().toString().equals(name)) {
                if (count == ordinal) {
                    return mt;
                }
                ++count;
            }
        }
    }
    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:TreeDissector.java

示例8: visitReturn

import com.sun.source.tree.Tree; //导入方法依赖的package包/类
@Override
public Object visitReturn(ReturnTree node, Object p) {
    TreePath path = getCurrentPath();
    TreePath parentPath = path.getParentPath();
    if (suppress) {
        return  super.visitReturn(node, p);
    }
    if (ignoreGuards && parentPath != null) {
        Tree parentTree = parentPath.getLeaf();
        TreePath branchPath = path;
        while (parentTree.getKind() == Tree.Kind.BLOCK) {
            branchPath = parentPath;
            parentPath = parentPath.getParentPath();
            parentTree = parentPath.getLeaf();
        }
        if (parentTree.getKind() == Tree.Kind.IF) {
            IfTree ifTree = (IfTree)parentTree;
            StatementTree trueTree = ifTree.getThenStatement() == branchPath.getLeaf() ? 
                    ifTree.getThenStatement() : ifTree.getElseStatement();
            if (trueTree == node) {
                return  super.visitReturn(node, p);
            }
            if (trueTree.getKind() == Tree.Kind.BLOCK) {
                BlockTree bt = (BlockTree)trueTree;
                if (bt.getStatements().size() == 1) {
                    return  super.visitReturn(node, p);
                }
            }
        }
    }
    returnCount++;
    return super.visitReturn(node, p);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:34,代码来源:MethodMetrics.java

示例9: createEqualsLineForField

import com.sun.source.tree.Tree; //导入方法依赖的package包/类
private String createEqualsLineForField(VariableTree field) {
    Name fieldName = field.getName();
    Tree fieldType = field.getType();
    if (fieldType.getKind() == Tree.Kind.PRIMITIVE_TYPE) {
        return "if (this." + fieldName + " != other." + fieldName + ") return false;"; // NOI18N
    }
    return "if ((this." + fieldName + " == null && other." + fieldName + " != null) || " + "(this." + fieldName +
            " != null && !this." + fieldName + ".equals(other." + fieldName + "))) return false;"; // NOI18N
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:EntityMethodGenerator.java

示例10: firstVariable

import com.sun.source.tree.Tree; //导入方法依赖的package包/类
VariableTree firstVariable() {
    if (targetClass != null) {
        for (Tree mem : targetClass.getMembers()) {
            if (mem.getKind() == Tree.Kind.VARIABLE) {
                VariableTree vt = (VariableTree) mem;
                return vt;
            }
        }
    }
    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:TreeDissector.java

示例11: isSetter

import com.sun.source.tree.Tree; //导入方法依赖的package包/类
private static boolean isSetter(Tree member) {
    return member.getKind() == Tree.Kind.METHOD
            && name(member).startsWith("set") //NOI18N
            && ((MethodTree)member).getParameters().size() == 1
            && ((MethodTree)member).getReturnType().getKind() == Tree.Kind.PRIMITIVE_TYPE
            && ((PrimitiveTypeTree)((MethodTree)member).getReturnType()).getPrimitiveTypeKind() == TypeKind.VOID;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:GeneratorUtilities.java

示例12: isInAnnotation

import com.sun.source.tree.Tree; //导入方法依赖的package包/类
/** Return true iff this tree is a child of some annotation. */
public static boolean isInAnnotation(Env<?> env, JCTree tree) {
    TreePath tp = TreePath.getPath(env.toplevel, tree);
    if (tp != null) {
        for (Tree t : tp) {
            if (t.getKind() == Tree.Kind.ANNOTATION)
                return true;
        }
    }
    return false;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:TreeInfo.java

示例13: qualifiedString

import com.sun.source.tree.Tree; //导入方法依赖的package包/类
private static String qualifiedString(Tree tree) {
  switch (tree.getKind()) {
  case IDENTIFIER:
      return ((IdentifierTree) tree).getName().toString();
  case MEMBER_SELECT:
    MemberSelectTree select = (MemberSelectTree) tree;
    return qualifiedString(select.getExpression()) + '.' + select.getIdentifier().toString();
  default:
      throw new AssertionError(tree.toString());
  }
}
 
开发者ID:forax,项目名称:moduletools,代码行数:12,代码来源:JavacModuleParser.java

示例14: collectFieldGroup

import com.sun.source.tree.Tree; //导入方法依赖的package包/类
/**
 * Resolves all fields that belong to the same field group. 
 */
private static @NonNull List<? extends Tree> collectFieldGroup(@NonNull CompilationInfo info, 
        @NonNull TreePath parentPath, Tree leaf) {
    Iterable<? extends Tree> children;

    switch (parentPath.getLeaf().getKind()) {
        case BLOCK: children = ((BlockTree) parentPath.getLeaf()).getStatements(); break;
        case ANNOTATION_TYPE:
        case CLASS:
        case ENUM:
        case INTERFACE:
            children = ((ClassTree) parentPath.getLeaf()).getMembers(); break;
        case CASE:  children = ((CaseTree) parentPath.getLeaf()).getStatements(); break;
        default:    children = Collections.singleton(leaf); break;
    }

    List<Tree> result = new LinkedList<>();
    ModifiersTree currentModifiers = ((VariableTree) leaf).getModifiers();

    for (Tree c : children) {
        if (c.getKind() != Kind.VARIABLE) continue;

        if (((VariableTree) c).getModifiers() == currentModifiers) {
            result.add(c);
        }
    }
    
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:WorkingCopy.java

示例15: resolveFieldGroup

import com.sun.source.tree.Tree; //导入方法依赖的package包/类
public static @NonNull Collection<? extends TreePath> resolveFieldGroup(@NonNull CompilationInfo info, @NonNull TreePath variable) {
    Tree leaf = variable.getLeaf();

    if (leaf.getKind() != Kind.VARIABLE) {
        return Collections.singleton(variable);
    }

    TreePath parentPath = variable.getParentPath();
    Iterable<? extends Tree> children;

    switch (parentPath.getLeaf().getKind()) {
        case BLOCK: children = ((BlockTree) parentPath.getLeaf()).getStatements(); break;
        case ANNOTATION_TYPE:
        case CLASS:
        case ENUM:
        case INTERFACE:
            children = ((ClassTree) parentPath.getLeaf()).getMembers(); break;
        case CASE:  children = ((CaseTree) parentPath.getLeaf()).getStatements(); break;
        default:    children = Collections.singleton(leaf); break;
    }

    List<TreePath> result = new LinkedList<TreePath>();
    ModifiersTree currentModifiers = ((VariableTree) leaf).getModifiers();

    for (Tree c : children) {
        if (c.getKind() != Kind.VARIABLE) continue;

        if (((VariableTree) c).getModifiers() == currentModifiers) {
            result.add(new TreePath(parentPath, c));
        }
    }
    
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:Utilities.java


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