Java Code Examples for jdk.nashorn.internal.ir.LiteralNode#getToken()

The following examples show how to use jdk.nashorn.internal.ir.LiteralNode#getToken() . 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: Parser.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Directive value or null if statement is not a directive.
 *
 * @param stmt Statement to be checked
 * @return Directive value if the given statement is a directive
 */
private String getDirective(final Node stmt) {
    if (stmt instanceof ExpressionStatement) {
        final Node expr = ((ExpressionStatement)stmt).getExpression();
        if (expr instanceof LiteralNode) {
            final LiteralNode<?> lit = (LiteralNode<?>)expr;
            final long litToken = lit.getToken();
            final TokenType tt = Token.descType(litToken);
            // A directive is either a string or an escape string
            if (tt == TokenType.STRING || tt == TokenType.ESCSTRING) {
                // Make sure that we don't unescape anything. Return as seen in source!
                return source.getString(lit.getStart(), Token.descLength(litToken));
            }
        }
    }

    return null;
}
 
Example 2
Source File: Parser.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Directive value or null if statement is not a directive.
 *
 * @param stmt Statement to be checked
 * @return Directive value if the given statement is a directive
 */
private String getDirective(final Node stmt) {
    if (stmt instanceof ExpressionStatement) {
        final Node expr = ((ExpressionStatement)stmt).getExpression();
        if (expr instanceof LiteralNode) {
            final LiteralNode<?> lit = (LiteralNode<?>)expr;
            final long litToken = lit.getToken();
            final TokenType tt = Token.descType(litToken);
            // A directive is either a string or an escape string
            if (tt == TokenType.STRING || tt == TokenType.ESCSTRING) {
                // Make sure that we don't unescape anything. Return as seen in source!
                return source.getString(lit.getStart(), Token.descLength(litToken));
            }
        }
    }

    return null;
}
 
Example 3
Source File: Parser.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Directive value or null if statement is not a directive.
 *
 * @param stmt Statement to be checked
 * @return Directive value if the given statement is a directive
 */
private String getDirective(final Node stmt) {
    if (stmt instanceof ExpressionStatement) {
        final Node expr = ((ExpressionStatement)stmt).getExpression();
        if (expr instanceof LiteralNode) {
            final LiteralNode<?> lit = (LiteralNode<?>)expr;
            final long litToken = lit.getToken();
            final TokenType tt = Token.descType(litToken);
            // A directive is either a string or an escape string
            if (tt == TokenType.STRING || tt == TokenType.ESCSTRING) {
                // Make sure that we don't unescape anything. Return as seen in source!
                return source.getString(lit.getStart(), Token.descLength(litToken));
            }
        }
    }

    return null;
}
 
Example 4
Source File: Parser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Directive value or null if statement is not a directive.
 *
 * @param stmt Statement to be checked
 * @return Directive value if the given statement is a directive
 */
private String getDirective(final Node stmt) {
    if (stmt instanceof ExpressionStatement) {
        final Node expr = ((ExpressionStatement)stmt).getExpression();
        if (expr instanceof LiteralNode) {
            final LiteralNode<?> lit = (LiteralNode<?>)expr;
            final long litToken = lit.getToken();
            final TokenType tt = Token.descType(litToken);
            // A directive is either a string or an escape string
            if (tt == TokenType.STRING || tt == TokenType.ESCSTRING) {
                // Make sure that we don't unescape anything. Return as seen in source!
                return source.getString(lit.getStart(), Token.descLength(litToken));
            }
        }
    }

    return null;
}
 
Example 5
Source File: Parser.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Directive value or null if statement is not a directive.
 *
 * @param stmt Statement to be checked
 * @return Directive value if the given statement is a directive
 */
private String getDirective(final Node stmt) {
    if (stmt instanceof ExpressionStatement) {
        final Node expr = ((ExpressionStatement)stmt).getExpression();
        if (expr instanceof LiteralNode) {
            final LiteralNode<?> lit = (LiteralNode<?>)expr;
            final long litToken = lit.getToken();
            final TokenType tt = Token.descType(litToken);
            // A directive is either a string or an escape string
            if (tt == TokenType.STRING || tt == TokenType.ESCSTRING) {
                // Make sure that we don't unescape anything. Return as seen in source!
                return source.getString(lit.getStart(), Token.descLength(litToken));
            }
        }
    }

    return null;
}
 
Example 6
Source File: Parser.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Directive value or null if statement is not a directive.
 *
 * @param stmt Statement to be checked
 * @return Directive value if the given statement is a directive
 */
private String getDirective(final Node stmt) {
    if (stmt instanceof ExpressionStatement) {
        final Node expr = ((ExpressionStatement)stmt).getExpression();
        if (expr instanceof LiteralNode) {
            final LiteralNode<?> lit = (LiteralNode<?>)expr;
            final long litToken = lit.getToken();
            final TokenType tt = Token.descType(litToken);
            // A directive is either a string or an escape string
            if (tt == TokenType.STRING || tt == TokenType.ESCSTRING) {
                // Make sure that we don't unescape anything. Return as seen in source!
                return source.getString(lit.getStart(), Token.descLength(litToken));
            }
        }
    }

    return null;
}
 
Example 7
Source File: Parser.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Directive value or null if statement is not a directive.
 *
 * @param stmt Statement to be checked
 * @return Directive value if the given statement is a directive
 */
private String getDirective(final Node stmt) {
    if (stmt instanceof ExpressionStatement) {
        final Node expr = ((ExpressionStatement)stmt).getExpression();
        if (expr instanceof LiteralNode) {
            final LiteralNode<?> lit = (LiteralNode<?>)expr;
            final long litToken = lit.getToken();
            final TokenType tt = Token.descType(litToken);
            // A directive is either a string or an escape string
            if (tt == TokenType.STRING || tt == TokenType.ESCSTRING) {
                // Make sure that we don't unescape anything. Return as seen in source!
                return source.getString(lit.getStart(), Token.descLength(litToken));
            }
        }
    }

    return null;
}
 
Example 8
Source File: Parser.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Directive value or null if statement is not a directive.
 *
 * @param stmt Statement to be checked
 * @return Directive value if the given statement is a directive
 */
private String getDirective(final Node stmt) {
    if (stmt instanceof ExpressionStatement) {
        final Node expr = ((ExpressionStatement)stmt).getExpression();
        if (expr instanceof LiteralNode) {
            final LiteralNode<?> lit = (LiteralNode<?>)expr;
            final long litToken = lit.getToken();
            final TokenType tt = Token.descType(litToken);
            // A directive is either a string or an escape string
            if (tt == TokenType.STRING || tt == TokenType.ESCSTRING) {
                // Make sure that we don't unescape anything. Return as seen in source!
                return source.getString(lit.getStart(), Token.descLength(litToken));
            }
        }
    }

    return null;
}
 
Example 9
Source File: Parser.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Directive value or null if statement is not a directive.
 *
 * @param stmt Statement to be checked
 * @return Directive value if the given statement is a directive
 */
private String getDirective(final Node stmt) {
    if (stmt instanceof ExpressionStatement) {
        final Node expr = ((ExpressionStatement)stmt).getExpression();
        if (expr instanceof LiteralNode) {
            final LiteralNode<?> lit = (LiteralNode<?>)expr;
            final long litToken = lit.getToken();
            final TokenType tt = Token.descType(litToken);
            // A directive is either a string or an escape string
            if (tt == TokenType.STRING || tt == TokenType.ESCSTRING) {
                // Make sure that we don't unescape anything. Return as seen in source!
                return source.getString(lit.getStart(), Token.descLength(litToken));
            }
        }
    }

    return null;
}