當前位置: 首頁>>代碼示例>>Java>>正文


Java ExpressionTree.getKind方法代碼示例

本文整理匯總了Java中com.sun.source.tree.ExpressionTree.getKind方法的典型用法代碼示例。如果您正苦於以下問題:Java ExpressionTree.getKind方法的具體用法?Java ExpressionTree.getKind怎麽用?Java ExpressionTree.getKind使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.sun.source.tree.ExpressionTree的用法示例。


在下文中一共展示了ExpressionTree.getKind方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: checkZeroSizeArray

import com.sun.source.tree.ExpressionTree; //導入方法依賴的package包/類
private static boolean checkZeroSizeArray(CompilationInfo info, TreePath val) {
    if (val.getLeaf().getKind() != Tree.Kind.VARIABLE) {
        return false;
    }
    VariableTree vt = (VariableTree)val.getLeaf();
    ExpressionTree xpr = vt.getInitializer();
    if (xpr == null) {
        return false;
    }
    if (xpr.getKind() == Tree.Kind.NEW_ARRAY) {
        NewArrayTree nat = (NewArrayTree)xpr;
        List<? extends ExpressionTree> dims = nat.getDimensions();
        if (dims != null && !dims.isEmpty()) {
            Object size = ArithmeticUtilities.compute(info, 
                    new TreePath(
                        new TreePath(val, xpr),
                        dims.get(dims.size() -1)), 
                    true);
            return ArithmeticUtilities.isRealValue(size) && Integer.valueOf(0).equals(size);
        } else {
            return nat.getInitializers() != null && nat.getInitializers().isEmpty();
        }
    }
    return false;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:ConstantNameHint.java

示例2: depth

import com.sun.source.tree.ExpressionTree; //導入方法依賴的package包/類
@SuppressWarnings("unused")
private int depth(ExpressionTree expression) {
  switch (expression.getKind()) {
    case MEMBER_SELECT:
      MemberSelectTree selectTree = (MemberSelectTree) expression;
      return 1 + depth(selectTree.getExpression());
    case METHOD_INVOCATION:
      MethodInvocationTree invTree = (MethodInvocationTree) expression;
      return depth(invTree.getMethodSelect());
    case IDENTIFIER:
      IdentifierTree varTree = (IdentifierTree) expression;
      Symbol symbol = ASTHelpers.getSymbol(varTree);
      return (symbol.getKind().equals(ElementKind.FIELD)) ? 2 : 1;
    default:
      return 0;
  }
}
 
開發者ID:uber,項目名稱:NullAway,代碼行數:18,代碼來源:NullAway.java

示例3: getBundleName

import com.sun.source.tree.ExpressionTree; //導入方法依賴的package包/類
private String getBundleName(MethodInvocationTree n, int index, String bfn) {
    if (n.getArguments().size() <= index) {
        return null;
    }
    ExpressionTree t = n.getArguments().get(index);
    // recognize just string literals + .class references
    if (t.getKind() == Tree.Kind.STRING_LITERAL) {
        Object o = ((LiteralTree)t).getValue();
        return o == null ? null : o.toString();
    } else if (t.getKind() == Tree.Kind.MEMBER_SELECT) {
        MemberSelectTree mst = (MemberSelectTree)t;
        if (!mst.getIdentifier().contentEquals("class")) {
            return null;
        }
        return bundleFileFromClass(new TreePath(getCurrentPath(), mst.getExpression()), bfn);
    }
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:ResourceStringFoldProvider.java

示例4: dotExpressionUpToArgs

import com.sun.source.tree.ExpressionTree; //導入方法依賴的package包/類
private void dotExpressionUpToArgs(ExpressionTree expression, Optional<BreakTag> tyargTag) {
    expression = getArrayBase(expression);
    switch (expression.getKind()) {
        case MEMBER_SELECT:
            MemberSelectTree fieldAccess = (MemberSelectTree) expression;
            visit(fieldAccess.getIdentifier());
            break;
        case METHOD_INVOCATION:
            MethodInvocationTree methodInvocation = (MethodInvocationTree) expression;
            if (!methodInvocation.getTypeArguments().isEmpty()) {
                builder.open(plusFour);
                addTypeArguments(methodInvocation.getTypeArguments(), ZERO);
                // TODO(jdd): Should indent the name -4.
                builder.breakOp(Doc.FillMode.UNIFIED, "", ZERO, tyargTag);
                builder.close();
            }
            visit(getMethodName(methodInvocation));
            break;
        case IDENTIFIER:
            visit(((IdentifierTree) expression).getName());
            break;
        default:
            scan(expression, null);
            break;
    }
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:27,代碼來源:JavaInputAstVisitor.java

示例5: dotExpressionArgsAndParen

import com.sun.source.tree.ExpressionTree; //導入方法依賴的package包/類
private void dotExpressionArgsAndParen(
        ExpressionTree expression, Indent tyargIndent, Indent indent) {
    Deque<ExpressionTree> indices = getArrayIndices(expression);
    expression = getArrayBase(expression);
    switch (expression.getKind()) {
        case METHOD_INVOCATION:
            builder.open(tyargIndent);
            MethodInvocationTree methodInvocation = (MethodInvocationTree) expression;
            addArguments(methodInvocation.getArguments(), indent);
            builder.close();
            break;
        default:
            break;
    }
    formatArrayIndices(indices);
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:17,代碼來源:JavaInputAstVisitor.java

示例6: visitMethodInvocation

import com.sun.source.tree.ExpressionTree; //導入方法依賴的package包/類
@Override
public Void visitMethodInvocation(MethodInvocationTree node, Void p) {
    if (!node.getArguments().isEmpty()) {
        return null;
    }
    final ExpressionTree et = node.getMethodSelect();
    if (et.getKind() != Tree.Kind.MEMBER_SELECT) {
        return null;
    }
    final MemberSelectTree mst = (MemberSelectTree) et;
    if (!FINALIZE.contentEquals(mst.getIdentifier())) {
        return null;
    }
    if (mst.getExpression().getKind() != Tree.Kind.IDENTIFIER) {
        return null;
    }
    if (!SUPER.contentEquals(((IdentifierTree)mst.getExpression()).getName())) {
        return null;
    }
    found = true;
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:FinalizeDoesNotCallSuper.java

示例7: visitAnnotation

import com.sun.source.tree.ExpressionTree; //導入方法依賴的package包/類
@Override
public Boolean visitAnnotation(AnnotationTree node, TreePath p) {
    if (p == null)
        return super.visitAnnotation(node, p);

    AnnotationTree t = (AnnotationTree) p.getLeaf();
    
    List<? extends ExpressionTree> arguments = t.getArguments();
    
    if (arguments.size() == 1) {
        ExpressionTree arg = arguments.get(0);
        
        if (arg.getKind() == Kind.ASSIGNMENT) {
            AssignmentTree at = (AssignmentTree) arg;
            
            if (   at.getVariable().getKind() == Kind.IDENTIFIER
                && isMultistatementWildcardTree(at.getExpression())
                && ((IdentifierTree) at.getVariable()).getName().contentEquals("value")) {
                arguments = Collections.singletonList(at.getExpression());
            }
        }
    }
    
    if (!checkLists(node.getArguments(), arguments, p))
        return false;

    return scan(node.getAnnotationType(), t.getAnnotationType(), p);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:29,代碼來源:CopyFinder.java

示例8: transformInitializer

import com.sun.source.tree.ExpressionTree; //導入方法依賴的package包/類
private ExpressionTree transformInitializer(ExpressionTree initializer, Tree type, TreeMaker make) {
    if(initializer.getKind() == Tree.Kind.NEW_ARRAY) {
        NewArrayTree nat = (NewArrayTree) initializer;
        if(nat.getType() == null) {
            if(type.getKind() == Tree.Kind.ARRAY_TYPE) {
                ArrayTypeTree arrayTypeTree = (ArrayTypeTree) type;
                type = arrayTypeTree.getType();
            }
            return make.NewArray(type, nat.getDimensions(), nat.getInitializers());
        }
    }
    return initializer;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:14,代碼來源:Move.java

示例9: methodInvocationToMemberReference

import com.sun.source.tree.ExpressionTree; //導入方法依賴的package包/類
public static Tree methodInvocationToMemberReference(WorkingCopy copy, Tree tree, TreePath contextPath, List<? extends VariableTree> passedParameters, boolean addTypeCast) {
    if (tree.getKind() != Tree.Kind.METHOD_INVOCATION)
        return null;
    ExpressionTree ms = ((MethodInvocationTree)tree).getMethodSelect();
    Element e = copy.getTrees().getElement(new TreePath(contextPath, ms));
    if (e == null || e.getKind() != ElementKind.METHOD) {
        return null;
    }
    Name name = null;
    ExpressionTree expr = null;
    TreeMaker make = copy.getTreeMaker();
    
    if (ms.getKind() == Tree.Kind.IDENTIFIER) {
        name = ((IdentifierTree)ms).getName();
        expr = e.getModifiers().contains(Modifier.STATIC) ? 
                make.Identifier(e.getEnclosingElement()) :
                make.Identifier("this"); //NOI18N
    } else if (ms.getKind() == Tree.Kind.MEMBER_SELECT) {
        name = ((MemberSelectTree)ms).getIdentifier();
        if (passedParameters.size() == ((MethodInvocationTree)tree).getArguments().size()) {
            expr = ((MemberSelectTree)ms).getExpression();
        } else {
            expr = make.Identifier(e.getEnclosingElement());
        }
    }
    if (name == null || expr == null) {
        return null;
    }
    return possiblyCast(copy, 
            make.MemberReference(MemberReferenceTree.ReferenceMode.INVOKE, expr, name, Collections.<ExpressionTree>emptyList()),
            contextPath, addTypeCast
    );
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:34,代碼來源:ConvertToLambdaConverter.java

示例10: onOverrideMayBeNullExpr

import com.sun.source.tree.ExpressionTree; //導入方法依賴的package包/類
@Override
public boolean onOverrideMayBeNullExpr(
    NullAway analysis, ExpressionTree expr, VisitorState state, boolean exprMayBeNull) {
  if (expr.getKind() == Tree.Kind.METHOD_INVOCATION
      && LibraryModels.LibraryModelUtil.hasNullableReturn(
          libraryModels, (Symbol.MethodSymbol) ASTHelpers.getSymbol(expr), state.getTypes())) {
    return analysis.nullnessFromDataflow(state, expr) || exprMayBeNull;
  }
  return exprMayBeNull;
}
 
開發者ID:uber,項目名稱:NullAway,代碼行數:11,代碼來源:LibraryModelsHandler.java

示例11: visitReturn

import com.sun.source.tree.ExpressionTree; //導入方法依賴的package包/類
@Override
public Tree visitReturn(ReturnTree that, Trees trees) {
    ExpressionTree thatExpression = that.getExpression();
    if (!this.hasMatcherReturn && thatExpression != null && thatExpression.getKind() == Tree.Kind.BOOLEAN_LITERAL
            && thisIsMatcherReturn(that, this.getCurrentPath())) {
        this.hasMatcherReturn = true;
    } else {
        this.hasReturns = true;
    }
    return super.visitReturn(that, trees);

}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:13,代碼來源:PreconditionsChecker.java

示例12: getName

import com.sun.source.tree.ExpressionTree; //導入方法依賴的package包/類
static String getName(ExpressionTree et) {
    if (et == null)
        return null;
    
    switch (et.getKind()) {
        case IDENTIFIER:
            return ((IdentifierTree) et).getName().toString();
        case METHOD_INVOCATION:
            return getName(((MethodInvocationTree) et).getMethodSelect());
        case MEMBER_SELECT:
            return ((MemberSelectTree) et).getIdentifier().toString();
        default:
            return null;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:16,代碼來源:SuspiciousNamesCombination.java

示例13: fillFirstArgument

import com.sun.source.tree.ExpressionTree; //導入方法依賴的package包/類
private boolean fillFirstArgument(
        ExpressionTree e,
        List<ExpressionTree> items,
        Indent indent) {
    // is there a trailing dereference?
    if (items.size() < 2) {
        return false;
    }
    // don't special-case calls nested inside expressions
    if (e.getKind() != METHOD_INVOCATION) {
        return false;
    }
    MethodInvocationTree methodInvocation = (MethodInvocationTree) e;
    Name name = getMethodName(methodInvocation);
    if (!(methodInvocation.getMethodSelect() instanceof IdentifierTree)
            || name.length() > 4
            || !methodInvocation.getTypeArguments().isEmpty()
            || methodInvocation.getArguments().size() != 1) {
        return false;
    }
    builder.open(ZERO);
    builder.open(indent);
    visit(name);
    token("(");
    ExpressionTree arg = getOnlyElement(methodInvocation.getArguments());
    scan(arg, null);
    builder.close();
    token(")");
    builder.close();
    return true;
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:32,代碼來源:JavaInputAstVisitor.java

示例14: performRewrite

import com.sun.source.tree.ExpressionTree; //導入方法依賴的package包/類
@Override
protected void performRewrite(TransformationContext ctx) {
    WorkingCopy copy = ctx.getWorkingCopy();
    TreePath path = ctx.getPath();
    if (path != null) {
        TreeMaker make = copy.getTreeMaker();
        BinaryTree oldTree = (BinaryTree) path.getLeaf();
        ExpressionTree left = oldTree.getLeftOperand();
        ExpressionTree right = oldTree.getRightOperand();
        ExpressionTree newTree;
        if (kind == Kind.REVERSE_OPERANDS) {
            // "str2".equals(str1)
            ExpressionTree rightEquals = make.MemberSelect(right, "equals"); // NOI18N
            ExpressionTree rightEqualsLeft = make.MethodInvocation(Collections.<ExpressionTree>emptyList(), rightEquals, Collections.singletonList(left));
            rightEqualsLeft = matchSign(make, oldTree, rightEqualsLeft);
            newTree = rightEqualsLeft;
        } else {
            ExpressionTree leftEquals = make.MemberSelect(left, "equals"); // NOI18N
            ExpressionTree leftEqualsRight = make.MethodInvocation(Collections.<ExpressionTree>emptyList(), leftEquals, Collections.singletonList(right));
            leftEqualsRight = matchSign(make, oldTree, leftEqualsRight);
            if (kind == Kind.NO_NULL_CHECK) {
                // str1.equals(str2)
                newTree = leftEqualsRight;
            } else {
                ExpressionTree leftEqNull  = make.Binary(Tree.Kind.EQUAL_TO, left, make.Identifier("null")); // NOI18N
                ExpressionTree rightEqNull = make.Binary(oldTree.getKind(), right, make.Identifier("null")); // NOI18N
                if (kind == Kind.NULL_CHECK_TERNARY) {
                    // str1 == null ? str2 == null : str1.equals(str2)
                    newTree = make.ConditionalExpression(leftEqNull, rightEqNull, leftEqualsRight);
                } else {
                    ExpressionTree leftNeNull = make.Binary(Tree.Kind.NOT_EQUAL_TO, left, make.Identifier("null")); // NOI18N
                    ExpressionTree leftNeNullAndLeftEqualsRight = make.Binary(Tree.Kind.CONDITIONAL_AND, leftNeNull, leftEqualsRight);
                    if (right.getKind() == Tree.Kind.STRING_LITERAL) {
                        // str1 != null && str1.equals("str2")
                        newTree = leftNeNullAndLeftEqualsRight;
                    } else {
                        // (str1 == null && str2 == null) || (str1 != null && str1.equals(str2))
                        ExpressionTree leftEqNullAndRightEqNull  = make.Binary(Tree.Kind.CONDITIONAL_AND, leftEqNull, rightEqNull);
                        newTree = make.Binary(Tree.Kind.CONDITIONAL_OR, make.Parenthesized(leftEqNullAndRightEqNull), make.Parenthesized(leftNeNullAndLeftEqualsRight));
                    }
                }
                if (path.getParentPath().getLeaf().getKind() != Tree.Kind.PARENTHESIZED) {
                    newTree = make.Parenthesized(newTree);
                }
            }
        }
        copy.rewrite(oldTree, newTree);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:50,代碼來源:WrongStringComparison.java

示例15: isRegistered

import com.sun.source.tree.ExpressionTree; //導入方法依賴的package包/類
private static boolean isRegistered(String key, ExpressionTree expr) {
    return expr.getKind() == Kind.STRING_LITERAL && ((LiteralTree) expr).getValue().toString().startsWith(key + "=");
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:4,代碼來源:UseNbBundleMessages.java


注:本文中的com.sun.source.tree.ExpressionTree.getKind方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。