當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。