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

The following examples show how to use jdk.nashorn.internal.parser.TokenType#getName() . 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 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 5
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 6
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 7
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 8
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 9
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 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, ' ');
        }
    }
}
 
Example 11
Source File: JSONWriter.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean enterUnaryNode(final UnaryNode unaryNode) {
    enterDefault(unaryNode);

    final TokenType tokenType = unaryNode.tokenType();
    if (tokenType == TokenType.NEW) {
        type("NewExpression");
        comma();

        final CallNode callNode = (CallNode)unaryNode.getExpression();
        property("callee");
        callNode.getFunction().accept(this);
        comma();

        array("arguments", callNode.getArgs());
    } else {
        final String operator;
        final boolean prefix;
        switch (tokenType) {
        case INCPOSTFIX:
            prefix = false;
            operator = "++";
            break;
        case DECPOSTFIX:
            prefix = false;
            operator = "--";
            break;
        case INCPREFIX:
            operator = "++";
            prefix = true;
            break;
        case DECPREFIX:
            operator = "--";
            prefix = true;
            break;
        default:
            prefix = true;
            operator = tokenType.getName();
            break;
        }

        type(unaryNode.isAssignment()? "UpdateExpression" : "UnaryExpression");
        comma();

        property("operator", operator);
        comma();

        property("prefix", prefix);
        comma();

        property("argument");
        unaryNode.getExpression().accept(this);
    }

    return leave();
}
 
Example 12
Source File: JSONWriter.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean enterUnaryNode(final UnaryNode unaryNode) {
    enterDefault(unaryNode);

    final TokenType tokenType = unaryNode.tokenType();
    if (tokenType == TokenType.NEW) {
        type("NewExpression");
        comma();

        final CallNode callNode = (CallNode)unaryNode.rhs();
        property("callee");
        callNode.getFunction().accept(this);
        comma();

        array("arguments", callNode.getArgs());
    } else {
        final String operator;
        final boolean prefix;
        switch (tokenType) {
        case INCPOSTFIX:
            prefix = false;
            operator = "++";
            break;
        case DECPOSTFIX:
            prefix = false;
            operator = "--";
            break;
        case INCPREFIX:
            operator = "++";
            prefix = true;
            break;
        case DECPREFIX:
            operator = "--";
            prefix = true;
            break;
        default:
            prefix = true;
            operator = tokenType.getName();
            break;
        }

        type(unaryNode.isAssignment()? "UpdateExpression" : "UnaryExpression");
        comma();

        property("operator", operator);
        comma();

        property("prefix", prefix);
        comma();

        property("argument");
        unaryNode.rhs().accept(this);
    }

    return leave();
}
 
Example 13
Source File: JSONWriter.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean enterUnaryNode(final UnaryNode unaryNode) {
    enterDefault(unaryNode);

    final TokenType tokenType = unaryNode.tokenType();
    if (tokenType == TokenType.NEW) {
        type("NewExpression");
        comma();

        final CallNode callNode = (CallNode)unaryNode.getExpression();
        property("callee");
        callNode.getFunction().accept(this);
        comma();

        array("arguments", callNode.getArgs());
    } else {
        final String operator;
        final boolean prefix;
        switch (tokenType) {
        case INCPOSTFIX:
            prefix = false;
            operator = "++";
            break;
        case DECPOSTFIX:
            prefix = false;
            operator = "--";
            break;
        case INCPREFIX:
            operator = "++";
            prefix = true;
            break;
        case DECPREFIX:
            operator = "--";
            prefix = true;
            break;
        default:
            prefix = true;
            operator = tokenType.getName();
            break;
        }

        type(unaryNode.isAssignment()? "UpdateExpression" : "UnaryExpression");
        comma();

        property("operator", operator);
        comma();

        property("prefix", prefix);
        comma();

        property("argument");
        unaryNode.getExpression().accept(this);
    }

    return leave();
}
 
Example 14
Source File: JSONWriter.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean enterUnaryNode(final UnaryNode unaryNode) {
    enterDefault(unaryNode);

    final TokenType tokenType = unaryNode.tokenType();
    if (tokenType == TokenType.NEW) {
        type("NewExpression");
        comma();

        final CallNode callNode = (CallNode)unaryNode.rhs();
        property("callee");
        callNode.getFunction().accept(this);
        comma();

        array("arguments", callNode.getArgs());
    } else {
        final String operator;
        final boolean prefix;
        switch (tokenType) {
        case INCPOSTFIX:
            prefix = false;
            operator = "++";
            break;
        case DECPOSTFIX:
            prefix = false;
            operator = "--";
            break;
        case INCPREFIX:
            operator = "++";
            prefix = true;
            break;
        case DECPREFIX:
            operator = "--";
            prefix = true;
            break;
        default:
            prefix = true;
            operator = tokenType.getName();
            break;
        }

        type(unaryNode.isAssignment()? "UpdateExpression" : "UnaryExpression");
        comma();

        property("operator", operator);
        comma();

        property("prefix", prefix);
        comma();

        property("argument");
        unaryNode.rhs().accept(this);
    }

    return leave();
}
 
Example 15
Source File: JSONWriter.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean enterUnaryNode(final UnaryNode unaryNode) {
    enterDefault(unaryNode);

    final TokenType tokenType = unaryNode.tokenType();
    if (tokenType == TokenType.NEW) {
        type("NewExpression");
        comma();

        final CallNode callNode = (CallNode)unaryNode.rhs();
        property("callee");
        callNode.getFunction().accept(this);
        comma();

        array("arguments", callNode.getArgs());
    } else {
        final String operator;
        final boolean prefix;
        switch (tokenType) {
        case INCPOSTFIX:
            prefix = false;
            operator = "++";
            break;
        case DECPOSTFIX:
            prefix = false;
            operator = "--";
            break;
        case INCPREFIX:
            operator = "++";
            prefix = true;
            break;
        case DECPREFIX:
            operator = "--";
            prefix = true;
            break;
        default:
            prefix = true;
            operator = tokenType.getName();
            break;
        }

        type(unaryNode.isAssignment()? "UpdateExpression" : "UnaryExpression");
        comma();

        property("operator", operator);
        comma();

        property("prefix", prefix);
        comma();

        property("argument");
        unaryNode.rhs().accept(this);
    }

    return leave();
}
 
Example 16
Source File: JSONWriter.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean enterUnaryNode(final UnaryNode unaryNode) {
    enterDefault(unaryNode);

    final TokenType tokenType = unaryNode.tokenType();
    if (tokenType == TokenType.NEW) {
        type("NewExpression");
        comma();

        final CallNode callNode = (CallNode)unaryNode.getExpression();
        property("callee");
        callNode.getFunction().accept(this);
        comma();

        array("arguments", callNode.getArgs());
    } else {
        final String operator;
        final boolean prefix;
        switch (tokenType) {
        case INCPOSTFIX:
            prefix = false;
            operator = "++";
            break;
        case DECPOSTFIX:
            prefix = false;
            operator = "--";
            break;
        case INCPREFIX:
            operator = "++";
            prefix = true;
            break;
        case DECPREFIX:
            operator = "--";
            prefix = true;
            break;
        default:
            prefix = true;
            operator = tokenType.getName();
            break;
        }

        type(unaryNode.isAssignment()? "UpdateExpression" : "UnaryExpression");
        comma();

        property("operator", operator);
        comma();

        property("prefix", prefix);
        comma();

        property("argument");
        unaryNode.getExpression().accept(this);
    }

    return leave();
}
 
Example 17
Source File: JSONWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean enterUnaryNode(final UnaryNode unaryNode) {
    enterDefault(unaryNode);

    final TokenType tokenType = unaryNode.tokenType();
    if (tokenType == TokenType.NEW) {
        type("NewExpression");
        comma();

        final CallNode callNode = (CallNode)unaryNode.getExpression();
        property("callee");
        callNode.getFunction().accept(this);
        comma();

        array("arguments", callNode.getArgs());
    } else {
        final String operator;
        final boolean prefix;
        switch (tokenType) {
        case INCPOSTFIX:
            prefix = false;
            operator = "++";
            break;
        case DECPOSTFIX:
            prefix = false;
            operator = "--";
            break;
        case INCPREFIX:
            operator = "++";
            prefix = true;
            break;
        case DECPREFIX:
            operator = "--";
            prefix = true;
            break;
        default:
            prefix = true;
            operator = tokenType.getName();
            break;
        }

        type(unaryNode.isAssignment()? "UpdateExpression" : "UnaryExpression");
        comma();

        property("operator", operator);
        comma();

        property("prefix", prefix);
        comma();

        property("argument");
        unaryNode.getExpression().accept(this);
    }

    return leave();
}
 
Example 18
Source File: JSONWriter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean enterUnaryNode(final UnaryNode unaryNode) {
    enterDefault(unaryNode);

    final TokenType tokenType = unaryNode.tokenType();
    if (tokenType == TokenType.NEW) {
        type("NewExpression");
        comma();

        final CallNode callNode = (CallNode)unaryNode.getExpression();
        property("callee");
        callNode.getFunction().accept(this);
        comma();

        array("arguments", callNode.getArgs());
    } else {
        final String operator;
        final boolean prefix;
        switch (tokenType) {
        case INCPOSTFIX:
            prefix = false;
            operator = "++";
            break;
        case DECPOSTFIX:
            prefix = false;
            operator = "--";
            break;
        case INCPREFIX:
            operator = "++";
            prefix = true;
            break;
        case DECPREFIX:
            operator = "--";
            prefix = true;
            break;
        default:
            prefix = true;
            operator = tokenType.getName();
            break;
        }

        type(unaryNode.isAssignment()? "UpdateExpression" : "UnaryExpression");
        comma();

        property("operator", operator);
        comma();

        property("prefix", prefix);
        comma();

        property("argument");
        unaryNode.getExpression().accept(this);
    }

    return leave();
}
 
Example 19
Source File: JSONWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean enterUnaryNode(final UnaryNode unaryNode) {
    enterDefault(unaryNode);

    final TokenType tokenType = unaryNode.tokenType();
    if (tokenType == TokenType.NEW) {
        type("NewExpression");
        comma();

        final CallNode callNode = (CallNode)unaryNode.getExpression();
        property("callee");
        callNode.getFunction().accept(this);
        comma();

        array("arguments", callNode.getArgs());
    } else {
        final String operator;
        final boolean prefix;
        switch (tokenType) {
        case INCPOSTFIX:
            prefix = false;
            operator = "++";
            break;
        case DECPOSTFIX:
            prefix = false;
            operator = "--";
            break;
        case INCPREFIX:
            operator = "++";
            prefix = true;
            break;
        case DECPREFIX:
            operator = "--";
            prefix = true;
            break;
        default:
            prefix = true;
            operator = tokenType.getName();
            break;
        }

        type(unaryNode.isAssignment()? "UpdateExpression" : "UnaryExpression");
        comma();

        property("operator", operator);
        comma();

        property("prefix", prefix);
        comma();

        property("argument");
        unaryNode.getExpression().accept(this);
    }

    return leave();
}
 
Example 20
Source File: JSONWriter.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean enterUnaryNode(final UnaryNode unaryNode) {
    enterDefault(unaryNode);

    final TokenType tokenType = unaryNode.tokenType();
    if (tokenType == TokenType.NEW) {
        type("NewExpression");
        comma();

        final CallNode callNode = (CallNode)unaryNode.getExpression();
        property("callee");
        callNode.getFunction().accept(this);
        comma();

        array("arguments", callNode.getArgs());
    } else {
        final String operator;
        final boolean prefix;
        switch (tokenType) {
        case INCPOSTFIX:
            prefix = false;
            operator = "++";
            break;
        case DECPOSTFIX:
            prefix = false;
            operator = "--";
            break;
        case INCPREFIX:
            operator = "++";
            prefix = true;
            break;
        case DECPREFIX:
            operator = "--";
            prefix = true;
            break;
        default:
            prefix = true;
            operator = tokenType.getName();
            break;
        }

        type(unaryNode.isAssignment()? "UpdateExpression" : "UnaryExpression");
        comma();

        property("operator", operator);
        comma();

        property("prefix", prefix);
        comma();

        property("argument");
        unaryNode.getExpression().accept(this);
    }

    return leave();
}