Java Code Examples for jdk.nashorn.internal.parser.TokenType#ordinal()

The following examples show how to use jdk.nashorn.internal.parser.TokenType#ordinal() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UnaryNode.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 ? "--" : "++");
    }
}
 
Example 2
Source File: UnaryNode.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 ? "--" : "++");
    }
}
 
Example 3
Source File: UnaryNode.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 ? "--" : "++");
    }
}
 
Example 4
Source File: UnaryNode.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 ? "--" : "++");
    }
}
 
Example 5
Source File: UnaryNode.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 ? "--" : "++");
    }
}
 
Example 6
Source File: UnaryNode.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 ? "--" : "++");
    }
}
 
Example 7
Source File: UnaryNode.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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
 * when invoked.
 */
public void toString(final StringBuilder sb, final Runnable rhsStringBuilder) {
    final TokenType type      = tokenType();
    final String    name      = type.getName();
    final boolean   isPostfix = type == DECPOSTFIX || type == INCPOSTFIX;

    boolean rhsParen   = type.needsParens(rhs().tokenType(), false);

    if (!isPostfix) {
        if (name == null) {
            sb.append(type.name());
            rhsParen = true;
        } else {
            sb.append(name);

            if (type.ordinal() > BIT_NOT.ordinal()) {
                sb.append(' ');
            }
        }
    }

    if (rhsParen) {
        sb.append('(');
    }
    rhsStringBuilder.run();
    if (rhsParen) {
        sb.append(')');
    }

    if (isPostfix) {
        sb.append(type == DECPOSTFIX ? "--" : "++");
    }
}
 
Example 8
Source File: UnaryNode.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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
 * when invoked.
 */
public void toString(final StringBuilder sb, final Runnable rhsStringBuilder) {
    final TokenType type      = tokenType();
    final String    name      = type.getName();
    final boolean   isPostfix = type == DECPOSTFIX || type == INCPOSTFIX;

    boolean rhsParen   = type.needsParens(rhs().tokenType(), false);

    if (!isPostfix) {
        if (name == null) {
            sb.append(type.name());
            rhsParen = true;
        } else {
            sb.append(name);

            if (type.ordinal() > BIT_NOT.ordinal()) {
                sb.append(' ');
            }
        }
    }

    if (rhsParen) {
        sb.append('(');
    }
    rhsStringBuilder.run();
    if (rhsParen) {
        sb.append(')');
    }

    if (isPostfix) {
        sb.append(type == DECPOSTFIX ? "--" : "++");
    }
}
 
Example 9
Source File: UnaryNode.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 ? "--" : "++");
    }
}
 
Example 10
Source File: UnaryNode.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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
 * when invoked.
 */
public void toString(final StringBuilder sb, final Runnable rhsStringBuilder) {
    final TokenType type      = tokenType();
    final String    name      = type.getName();
    final boolean   isPostfix = type == DECPOSTFIX || type == INCPOSTFIX;
    final boolean   isConvert = type == CONVERT && getSymbol() != null;

    boolean rhsParen   = type.needsParens(rhs().tokenType(), false);
    int     convertPos = 0;

    if (isConvert) {
        convertPos = sb.length();
        sb.append("(");
        sb.append(getType());
        sb.append(")(");
    }

    if (!isPostfix && !isConvert) {
        if (name == null) {
            sb.append(type.name());
            rhsParen = true;
        } else {
            sb.append(name);

            if (type.ordinal() > BIT_NOT.ordinal()) {
                sb.append(' ');
            }
        }
    }

    if (rhsParen) {
        sb.append('(');
    }
    rhsStringBuilder.run();
    if (rhsParen) {
        sb.append(')');
    }

    if (isPostfix) {
        sb.append(type == DECPOSTFIX ? "--" : "++");
    }

    if (isConvert) {
        // strip extra cast parenthesis which makes the printout harder to read
        final boolean endsWithParenthesis = sb.charAt(sb.length() - 1) == ')';
        if (!endsWithParenthesis) {
            sb.append(')');
        } else {
            sb.setCharAt(convertPos, ' ');
        }
    }
}