本文整理汇总了Java中com.sun.tools.javac.tree.TreeInfo.opPrec方法的典型用法代码示例。如果您正苦于以下问题:Java TreeInfo.opPrec方法的具体用法?Java TreeInfo.opPrec怎么用?Java TreeInfo.opPrec使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.tools.javac.tree.TreeInfo
的用法示例。
在下文中一共展示了TreeInfo.opPrec方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: matchBinary
import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
@Override
public Description matchBinary(BinaryTree tree, VisitorState state) {
Tree parent = state.getPath().getParentPath().getLeaf();
if (!(parent instanceof BinaryTree)) {
return NO_MATCH;
}
if (TreeInfo.opPrec(((JCBinary) tree).getTag())
== TreeInfo.opPrec(((JCBinary) parent).getTag())) {
return NO_MATCH;
}
if (!isConfusing(tree.getKind(), parent.getKind())) {
return NO_MATCH;
}
return describeMatch(
tree, SuggestedFix.builder().prefixWith(tree, "(").postfixWith(tree, ")").build());
}
示例2: visitUnary
import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
public void visitUnary(JCUnary tree) {
try {
int ownprec = TreeInfo.opPrec(getTag(tree));
String opname = operatorName(getTag(tree));
open(prec, ownprec);
if (getTag(tree) <= Javac.getCtcInt(JCTree.class, "PREDEC")) {
print(opname);
printExpr(tree.arg, ownprec);
} else {
printExpr(tree.arg, ownprec);
print(opname);
}
close(prec, ownprec);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例3: visitUnary
import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
@Override
public void visitUnary(JCUnary tree) {
int ownprec = TreeInfo.opPrec(tree.getTag());
Name opname;
switch (tree.getTag()) {
case POS: opname = names.fromString("+"); break;
case NEG: opname = names.fromString("-"); break;
default: opname = operators.operatorName(tree.getTag()); break;
}
if (tree.getTag().ordinal() <= JCTree.Tag.PREDEC.ordinal()) { //XXX: comparing ordinals!
if (cs.spaceAroundUnaryOps()) {
needSpace();
print(opname);
print(' ');
} else {
print(opname);
if ( (tree.getTag() == JCTree.Tag.POS && (tree.arg.getTag() == JCTree.Tag.POS || tree.arg.getTag() == JCTree.Tag.PREINC))
|| (tree.getTag() == JCTree.Tag.NEG && (tree.arg.getTag() == JCTree.Tag.NEG || tree.arg.getTag() == JCTree.Tag.PREDEC))) {
print(' ');
}
}
printExpr(tree.arg, ownprec);
} else {
printExpr(tree.arg, ownprec);
if (cs.spaceAroundUnaryOps()) {
print(' ');
print(opname);
print(' ');
} else {
print(opname);
}
}
}
示例4: visitBinary
import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
@Override
public void visitBinary(JCBinary tree) {
int ownprec = TreeInfo.opPrec(tree.getTag());
Name opname = operators.operatorName(tree.getTag());
int col = out.col;
printExpr(tree.lhs, ownprec);
if(cs.spaceAroundBinaryOps())
print(' ');
print(opname);
boolean needsSpace = cs.spaceAroundBinaryOps()
|| (tree.getTag() == JCTree.Tag.PLUS && (tree.rhs.getTag() == JCTree.Tag.POS || tree.rhs.getTag() == JCTree.Tag.PREINC))
|| (tree.getTag() == JCTree.Tag.MINUS && (tree.rhs.getTag() == JCTree.Tag.NEG || tree.rhs.getTag() == JCTree.Tag.PREDEC));
int rm = cs.getRightMargin();
switch(cs.wrapBinaryOps()) {
case WRAP_IF_LONG:
if (widthEstimator.estimateWidth(tree.rhs, rm - out.col) + out.col <= cs.getRightMargin()) {
if(needsSpace)
print(' ');
break;
}
case WRAP_ALWAYS:
newline();
toColExactly(cs.alignMultilineBinaryOp() ? col : out.leftMargin + cs.getContinuationIndentSize());
break;
case WRAP_NEVER:
if(needsSpace)
print(' ');
break;
}
printExpr(tree.rhs, ownprec + 1);
}
示例5: visitUnary
import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
public void visitUnary(JCUnary tree) {
int ownprec = TreeInfo.opPrec(tree.getTag());
Name opname = operators.operatorName(tree.getTag());
open(prec, ownprec);
width(opname);
width(tree.arg, ownprec);
}
示例6: visitBinary
import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
public void visitBinary(JCBinary tree) {
int ownprec = TreeInfo.opPrec(tree.getTag());
Name opname = operators.operatorName(tree.getTag());
open(prec, ownprec);
width(opname);
width+=2;
width(tree.lhs, ownprec);
width(tree.rhs, ownprec + 1);
}
示例7: visitBinary
import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
public void visitBinary(JCBinary tree) {
try {
int ownprec = TreeInfo.opPrec(getTag(tree));
String opname = operatorName(getTag(tree));
open(prec, ownprec);
printExpr(tree.lhs, ownprec);
print(" " + opname + " ");
printExpr(tree.rhs, ownprec + 1);
close(prec, ownprec);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例8: precedence
import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
/**
* Returns the precedence of an expression's operator.
*/
static int precedence(ExpressionTree expression) {
return TreeInfo.opPrec(((JCTree) expression).getTag());
}
示例9: getPrecedence
import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
/**
* Returns the precedence level appropriate for unambiguously printing
* leaf as a subexpression of its parent.
*/
private static int getPrecedence(JCTree leaf, Context context) {
JCCompilationUnit comp = context.get(JCCompilationUnit.class);
JCTree parent = TreeInfo.pathFor(leaf, comp).get(1);
// In general, this should match the logic in com.sun.tools.javac.tree.Pretty.
//
// TODO(mdempsky): There are probably cases where we could omit parentheses
// by tweaking the returned precedence, but they need careful review.
// For example, consider a template to replace "add(a, b)" with "a + b",
// which applied to "x + add(y, z)" would result in "x + (y + z)".
// In most cases, we'd likely prefer "x + y + z" instead, but those aren't
// always equivalent: "0L + (Integer.MIN_VALUE + Integer.MIN_VALUE)" yields
// a different value than "0L + Integer.MIN_VALUE + Integer.MIN_VALUE" due
// to integer promotion rules.
if (parent instanceof JCConditional) {
// This intentionally differs from Pretty, because Pretty appears buggy:
// http://mail.openjdk.java.net/pipermail/compiler-dev/2013-September/007303.html
JCConditional conditional = (JCConditional) parent;
return TreeInfo.condPrec + ((conditional.cond == leaf) ? 1 : 0);
} else if (parent instanceof JCAssign) {
JCAssign assign = (JCAssign) parent;
return TreeInfo.assignPrec + ((assign.lhs == leaf) ? 1 : 0);
} else if (parent instanceof JCAssignOp) {
JCAssignOp assignOp = (JCAssignOp) parent;
return TreeInfo.assignopPrec + ((assignOp.lhs == leaf) ? 1 : 0);
} else if (parent instanceof JCUnary) {
return TreeInfo.opPrec(parent.getTag());
} else if (parent instanceof JCBinary) {
JCBinary binary = (JCBinary) parent;
return TreeInfo.opPrec(parent.getTag()) + ((binary.rhs == leaf) ? 1 : 0);
} else if (parent instanceof JCTypeCast) {
JCTypeCast typeCast = (JCTypeCast) parent;
return (typeCast.expr == leaf) ? TreeInfo.prefixPrec : TreeInfo.noPrec;
} else if (parent instanceof JCInstanceOf) {
JCInstanceOf instanceOf = (JCInstanceOf) parent;
return TreeInfo.ordPrec + ((instanceOf.clazz == leaf) ? 1 : 0);
} else if (parent instanceof JCArrayAccess) {
JCArrayAccess arrayAccess = (JCArrayAccess) parent;
return (arrayAccess.indexed == leaf) ? TreeInfo.postfixPrec : TreeInfo.noPrec;
} else if (parent instanceof JCFieldAccess) {
JCFieldAccess fieldAccess = (JCFieldAccess) parent;
return (fieldAccess.selected == leaf) ? TreeInfo.postfixPrec : TreeInfo.noPrec;
} else {
return TreeInfo.noPrec;
}
}
示例10: getPrecedence
import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
/**
* Returns the precedence level appropriate for unambiguously printing leaf as a subexpression of
* its parent.
*/
private static int getPrecedence(JCTree leaf, Context context) {
JCCompilationUnit comp = context.get(JCCompilationUnit.class);
JCTree parent = TreeInfo.pathFor(leaf, comp).get(1);
// In general, this should match the logic in com.sun.tools.javac.tree.Pretty.
//
// TODO(mdempsky): There are probably cases where we could omit parentheses
// by tweaking the returned precedence, but they need careful review.
// For example, consider a template to replace "add(a, b)" with "a + b",
// which applied to "x + add(y, z)" would result in "x + (y + z)".
// In most cases, we'd likely prefer "x + y + z" instead, but those aren't
// always equivalent: "0L + (Integer.MIN_VALUE + Integer.MIN_VALUE)" yields
// a different value than "0L + Integer.MIN_VALUE + Integer.MIN_VALUE" due
// to integer promotion rules.
if (parent instanceof JCConditional) {
// This intentionally differs from Pretty, because Pretty appears buggy:
// http://mail.openjdk.java.net/pipermail/compiler-dev/2013-September/007303.html
JCConditional conditional = (JCConditional) parent;
return TreeInfo.condPrec + ((conditional.cond == leaf) ? 1 : 0);
} else if (parent instanceof JCAssign) {
JCAssign assign = (JCAssign) parent;
return TreeInfo.assignPrec + ((assign.lhs == leaf) ? 1 : 0);
} else if (parent instanceof JCAssignOp) {
JCAssignOp assignOp = (JCAssignOp) parent;
return TreeInfo.assignopPrec + ((assignOp.lhs == leaf) ? 1 : 0);
} else if (parent instanceof JCUnary) {
return TreeInfo.opPrec(parent.getTag());
} else if (parent instanceof JCBinary) {
JCBinary binary = (JCBinary) parent;
return TreeInfo.opPrec(parent.getTag()) + ((binary.rhs == leaf) ? 1 : 0);
} else if (parent instanceof JCTypeCast) {
JCTypeCast typeCast = (JCTypeCast) parent;
return (typeCast.expr == leaf) ? TreeInfo.prefixPrec : TreeInfo.noPrec;
} else if (parent instanceof JCInstanceOf) {
JCInstanceOf instanceOf = (JCInstanceOf) parent;
return TreeInfo.ordPrec + ((instanceOf.clazz == leaf) ? 1 : 0);
} else if (parent instanceof JCArrayAccess) {
JCArrayAccess arrayAccess = (JCArrayAccess) parent;
return (arrayAccess.indexed == leaf) ? TreeInfo.postfixPrec : TreeInfo.noPrec;
} else if (parent instanceof JCFieldAccess) {
JCFieldAccess fieldAccess = (JCFieldAccess) parent;
return (fieldAccess.selected == leaf) ? TreeInfo.postfixPrec : TreeInfo.noPrec;
} else {
return TreeInfo.noPrec;
}
}
示例11: prec
import com.sun.tools.javac.tree.TreeInfo; //导入方法依赖的package包/类
/** Return precedence of operator represented by token,
* -1 if token is not a binary operator. @see TreeInfo.opPrec
*/
static int prec(Token token) {
int oc = optag(token);
return (oc >= 0) ? TreeInfo.opPrec(oc) : -1;
}