本文整理匯總了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;
}
示例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;
}
}
示例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;
}
示例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;
}
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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
);
}
示例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;
}
示例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);
}
示例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;
}
}
示例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;
}
示例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);
}
}
示例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 + "=");
}