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


Java TreeInfo.opPrec方法代码示例

本文整理汇总了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());
}
 
开发者ID:google,项目名称:error-prone,代码行数:17,代码来源:OperatorPrecedence.java

示例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);
    }
}
 
开发者ID:redundent,项目名称:lombok,代码行数:18,代码来源:PrettyCommentsPrinter.java

示例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);
           }
}
   }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:34,代码来源:VeryPretty.java

示例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);
   }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:VeryPretty.java

示例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);
   }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:WidthEstimator.java

示例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);
   }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:WidthEstimator.java

示例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);
    }
}
 
开发者ID:redundent,项目名称:lombok,代码行数:14,代码来源:PrettyCommentsPrinter.java

示例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());
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:7,代码来源:Trees.java

示例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;
  }
}
 
开发者ID:sivakumar-kailasam,项目名称:refactor-faster,代码行数:52,代码来源:ExpressionTemplate.java

示例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;
  }
}
 
开发者ID:google,项目名称:error-prone,代码行数:52,代码来源:ExpressionTemplate.java

示例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;
}
 
开发者ID:sebastianoe,项目名称:s4j,代码行数:8,代码来源:JavacParser.java


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