本文整理汇总了Java中jdk.nashorn.internal.parser.TokenType.needsParens方法的典型用法代码示例。如果您正苦于以下问题:Java TokenType.needsParens方法的具体用法?Java TokenType.needsParens怎么用?Java TokenType.needsParens使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.nashorn.internal.parser.TokenType
的用法示例。
在下文中一共展示了TokenType.needsParens方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toString
import jdk.nashorn.internal.parser.TokenType; //导入方法依赖的package包/类
/**
* Creates the string representation of this unary node, delegating the creation of the string representation of its
* operand to a specified runnable.
* @param sb the string builder to use
* @param rhsStringBuilder the runnable that appends the string representation of the operand to the string builder
* @param printType should we print type
* when invoked.
*/
public void toString(final StringBuilder sb, final Runnable rhsStringBuilder, final boolean printType) {
final TokenType tokenType = tokenType();
final String name = tokenType.getName();
final boolean isPostfix = tokenType == DECPOSTFIX || tokenType == INCPOSTFIX;
if (isOptimistic()) {
sb.append(Expression.OPT_IDENTIFIER);
}
boolean rhsParen = tokenType.needsParens(getExpression().tokenType(), false);
if (!isPostfix) {
if (name == null) {
sb.append(tokenType.name());
rhsParen = true;
} else {
sb.append(name);
if (tokenType.ordinal() > BIT_NOT.ordinal()) {
sb.append(' ');
}
}
}
if (rhsParen) {
sb.append('(');
}
rhsStringBuilder.run();
if (rhsParen) {
sb.append(')');
}
if (isPostfix) {
sb.append(tokenType == DECPOSTFIX ? "--" : "++");
}
}
示例2: toString
import jdk.nashorn.internal.parser.TokenType; //导入方法依赖的package包/类
@Override
public void toString(final StringBuilder sb, final boolean printType) {
final TokenType tokenType = tokenType();
final boolean testParen = tokenType.needsParens(getTest().tokenType(), true);
final boolean trueParen = tokenType.needsParens(getTrueExpression().tokenType(), false);
final boolean falseParen = tokenType.needsParens(getFalseExpression().tokenType(), false);
if (testParen) {
sb.append('(');
}
getTest().toString(sb, printType);
if (testParen) {
sb.append(')');
}
sb.append(" ? ");
if (trueParen) {
sb.append('(');
}
getTrueExpression().toString(sb, printType);
if (trueParen) {
sb.append(')');
}
sb.append(" : ");
if (falseParen) {
sb.append('(');
}
getFalseExpression().toString(sb, printType);
if (falseParen) {
sb.append(')');
}
}
示例3: toString
import jdk.nashorn.internal.parser.TokenType; //导入方法依赖的package包/类
@Override
public void toString(final StringBuilder sb, final boolean printType) {
final TokenType tokenType = tokenType();
final boolean lhsParen = tokenType.needsParens(lhs().tokenType(), true);
final boolean rhsParen = tokenType.needsParens(rhs().tokenType(), false);
if (lhsParen) {
sb.append('(');
}
lhs().toString(sb, printType);
if (lhsParen) {
sb.append(')');
}
sb.append(' ');
switch (tokenType) {
case COMMALEFT:
sb.append(",<");
break;
case COMMARIGHT:
sb.append(",>");
break;
case INCPREFIX:
case DECPREFIX:
sb.append("++");
break;
default:
sb.append(tokenType.getName());
break;
}
if (isOptimistic()) {
sb.append(Expression.OPT_IDENTIFIER);
}
sb.append(' ');
if (rhsParen) {
sb.append('(');
}
rhs().toString(sb, printType);
if (rhsParen) {
sb.append(')');
}
}