Java Code Examples for jdk.nashorn.internal.runtime.ErrorManager#format()

The following examples show how to use jdk.nashorn.internal.runtime.ErrorManager#format() . 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: AbstractParser.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Report an error.
 *
 * @param errorType  The error type
 * @param message    Error message.
 * @return ParserException upon failure. Caller should throw and not ignore
 */
protected final ParserException error(final JSErrorType errorType, final String message) {
    // TODO - column needs to account for tabs.
    final int position = Token.descPosition(token);
    final int column = position - linePosition;
    final String formatted = ErrorManager.format(message, source, line, column, token);
    return new ParserException(errorType, formatted, source, line, column, token);
}
 
Example 2
Source File: AssignSymbols.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void throwParserException(final String message, final Node origin) {
    if (origin == null) {
        throw new ParserException(message);
    }
    final Source source = compiler.getSource();
    final long token = origin.getToken();
    final int line = source.getLine(origin.getStart());
    final int column = source.getColumn(origin.getStart());
    final String formatted = ErrorManager.format(message, source, line, column, token);
    throw new ParserException(JSErrorType.SYNTAX_ERROR, formatted, source, line, column, token);
}
 
Example 3
Source File: AbstractParser.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Report an error.
 *
 * @param errorType  The error type
 * @param message    Error message.
 * @return ParserException upon failure. Caller should throw and not ignore
 */
protected final ParserException error(final JSErrorType errorType, final String message) {
    // TODO - column needs to account for tabs.
    final int position = Token.descPosition(token);
    final int column = position - linePosition;
    final String formatted = ErrorManager.format(message, source, line, column, token);
    return new ParserException(errorType, formatted, source, line, column, token);
}
 
Example 4
Source File: AbstractParser.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Report an error.
 *
 * @param errorType  The error type
 * @param message    Error message.
 * @return ParserException upon failure. Caller should throw and not ignore
 */
protected final ParserException error(final JSErrorType errorType, final String message) {
    // TODO - column needs to account for tabs.
    final int position = Token.descPosition(token);
    final int column = position - linePosition;
    final String formatted = ErrorManager.format(message, source, line, column, token);
    return new ParserException(errorType, formatted, source, line, column, token);
}
 
Example 5
Source File: AssignSymbols.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void throwParserException(final String message, final Node origin) {
    if (origin == null) {
        throw new ParserException(message);
    }
    final Source source = compiler.getSource();
    final long token = origin.getToken();
    final int line = source.getLine(origin.getStart());
    final int column = source.getColumn(origin.getStart());
    final String formatted = ErrorManager.format(message, source, line, column, token);
    throw new ParserException(JSErrorType.SYNTAX_ERROR, formatted, source, line, column, token);
}
 
Example 6
Source File: JSONParser.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
ParserException error(final String message, final int start, final int length) throws ParserException {
    final long token     = Token.toDesc(STRING, start, length);
    final int  pos       = Token.descPosition(token);
    final Source src     = Source.sourceFor("<json>", source);
    final int  lineNum   = src.getLine(pos);
    final int  columnNum = src.getColumn(pos);
    final String formatted = ErrorManager.format(message, src, lineNum, columnNum, token);
    return new ParserException(JSErrorType.SYNTAX_ERROR, formatted, src, lineNum, columnNum, token);
}
 
Example 7
Source File: AssignSymbols.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void throwParserException(final String message, final Node origin) {
    if (origin == null) {
        throw new ParserException(message);
    }
    final Source source = compiler.getSource();
    final long token = origin.getToken();
    final int line = source.getLine(origin.getStart());
    final int column = source.getColumn(origin.getStart());
    final String formatted = ErrorManager.format(message, source, line, column, token);
    throw new ParserException(JSErrorType.SYNTAX_ERROR, formatted, source, line, column, token);
}
 
Example 8
Source File: AssignSymbols.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void throwParserException(final String message, final Node origin) {
    if (origin == null) {
        throw new ParserException(message);
    }
    final Source source = compiler.getSource();
    final long token = origin.getToken();
    final int line = source.getLine(origin.getStart());
    final int column = source.getColumn(origin.getStart());
    final String formatted = ErrorManager.format(message, source, line, column, token);
    throw new ParserException(JSErrorType.SYNTAX_ERROR, formatted, source, line, column, token);
}
 
Example 9
Source File: JSONParser.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
ParserException error(final String message, final int start, final int length) throws ParserException {
    final long token     = Token.toDesc(STRING, start, length);
    final int  pos       = Token.descPosition(token);
    final Source src     = Source.sourceFor("<json>", source);
    final int  lineNum   = src.getLine(pos);
    final int  columnNum = src.getColumn(pos);
    final String formatted = ErrorManager.format(message, src, lineNum, columnNum, token);
    return new ParserException(JSErrorType.SYNTAX_ERROR, formatted, src, lineNum, columnNum, token);
}
 
Example 10
Source File: AbstractParser.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Report an error.
 *
 * @param errorType  The error type
 * @param message    Error message.
 * @return ParserException upon failure. Caller should throw and not ignore
 */
protected final ParserException error(final JSErrorType errorType, final String message) {
    // TODO - column needs to account for tabs.
    final int position = Token.descPosition(token);
    final int column = position - linePosition;
    final String formatted = ErrorManager.format(message, source, line, column, token);
    return new ParserException(errorType, formatted, source, line, column, token);
}
 
Example 11
Source File: AssignSymbols.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void throwParserException(final String message, final Node origin) {
    if (origin == null) {
        throw new ParserException(message);
    }
    final Source source = compiler.getSource();
    final long token = origin.getToken();
    final int line = source.getLine(origin.getStart());
    final int column = source.getColumn(origin.getStart());
    final String formatted = ErrorManager.format(message, source, line, column, token);
    throw new ParserException(JSErrorType.SYNTAX_ERROR, formatted, source, line, column, token);
}
 
Example 12
Source File: AbstractParser.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Report an error.
 *
 * @param errorType  The error type
 * @param message    Error message.
 * @return ParserException upon failure. Caller should throw and not ignore
 */
protected final ParserException error(final JSErrorType errorType, final String message) {
    // TODO - column needs to account for tabs.
    final int position = Token.descPosition(token);
    final int column = position - linePosition;
    final String formatted = ErrorManager.format(message, source, line, column, token);
    return new ParserException(errorType, formatted, source, line, column, token);
}
 
Example 13
Source File: AbstractParser.java    From openjdk-8-source with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Report an error.
 *
 * @param errorType  The error type
 * @param message    Error message.
 * @param errorToken Offending token.
 * @return ParserException upon failure. Caller should throw and not ignore
 */
protected final ParserException error(final JSErrorType errorType, final String message, final long errorToken) {
    final int position  = Token.descPosition(errorToken);
    final int lineNum   = source.getLine(position);
    final int columnNum = source.getColumn(position);
    final String formatted = ErrorManager.format(message, source, lineNum, columnNum, errorToken);
    return new ParserException(errorType, formatted, source, lineNum, columnNum, errorToken);
}
 
Example 14
Source File: Lexer.java    From hottub with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Generate a runtime exception
 *
 * @param message       error message
 * @param type          token type
 * @param start         start position of lexed error
 * @param length        length of lexed error
 * @throws ParserException  unconditionally
 */
protected void error(final String message, final TokenType type, final int start, final int length) throws ParserException {
    final long token     = Token.toDesc(type, start, length);
    final int  pos       = Token.descPosition(token);
    final int  lineNum   = source.getLine(pos);
    final int  columnNum = source.getColumn(pos);
    final String formatted = ErrorManager.format(message, source, lineNum, columnNum, token);
    throw new ParserException(JSErrorType.SYNTAX_ERROR, formatted, source, lineNum, columnNum, token);
}
 
Example 15
Source File: AbstractParser.java    From jdk8u60 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Report an error.
 *
 * @param errorType  The error type
 * @param message    Error message.
 * @param errorToken Offending token.
 * @return ParserException upon failure. Caller should throw and not ignore
 */
protected final ParserException error(final JSErrorType errorType, final String message, final long errorToken) {
    final int position  = Token.descPosition(errorToken);
    final int lineNum   = source.getLine(position);
    final int columnNum = source.getColumn(position);
    final String formatted = ErrorManager.format(message, source, lineNum, columnNum, errorToken);
    return new ParserException(errorType, formatted, source, lineNum, columnNum, errorToken);
}
 
Example 16
Source File: Lexer.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Generate a runtime exception
 *
 * @param message       error message
 * @param type          token type
 * @param start         start position of lexed error
 * @param length        length of lexed error
 * @throws ParserException  unconditionally
 */
protected void error(final String message, final TokenType type, final int start, final int length) throws ParserException {
    final long token     = Token.toDesc(type, start, length);
    final int  pos       = Token.descPosition(token);
    final int  lineNum   = source.getLine(pos);
    final int  columnNum = source.getColumn(pos);
    final String formatted = ErrorManager.format(message, source, lineNum, columnNum, token);
    throw new ParserException(JSErrorType.SYNTAX_ERROR, formatted, source, lineNum, columnNum, token);
}
 
Example 17
Source File: Lexer.java    From nashorn with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Generate a runtime exception
 *
 * @param message       error message
 * @param type          token type
 * @param start         start position of lexed error
 * @param length        length of lexed error
 * @throws ParserException  unconditionally
 */
protected void error(final String message, final TokenType type, final int start, final int length) throws ParserException {
    final long token     = Token.toDesc(type, start, length);
    final int  pos       = Token.descPosition(token);
    final int  lineNum   = source.getLine(pos);
    final int  columnNum = source.getColumn(pos);
    final String formatted = ErrorManager.format(message, source, lineNum, columnNum, token);
    throw new ParserException(JSErrorType.SYNTAX_ERROR, formatted, source, lineNum, columnNum, token);
}
 
Example 18
Source File: AbstractParser.java    From openjdk-jdk9 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Report an error.
 *
 * @param errorType  The error type
 * @param message    Error message.
 * @param errorToken Offending token.
 * @return ParserException upon failure. Caller should throw and not ignore
 */
protected final ParserException error(final JSErrorType errorType, final String message, final long errorToken) {
    final int position  = Token.descPosition(errorToken);
    final int lineNum   = source.getLine(position);
    final int columnNum = source.getColumn(position);
    final String formatted = ErrorManager.format(message, source, lineNum, columnNum, errorToken);
    return new ParserException(errorType, formatted, source, lineNum, columnNum, errorToken);
}
 
Example 19
Source File: Lexer.java    From openjdk-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Generate a runtime exception
 *
 * @param message       error message
 * @param type          token type
 * @param start         start position of lexed error
 * @param length        length of lexed error
 * @throws ParserException  unconditionally
 */
protected void error(final String message, final TokenType type, final int start, final int length) throws ParserException {
    final long token     = Token.toDesc(type, start, length);
    final int  pos       = Token.descPosition(token);
    final int  lineNum   = source.getLine(pos);
    final int  columnNum = source.getColumn(pos);
    final String formatted = ErrorManager.format(message, source, lineNum, columnNum, token);
    throw new ParserException(JSErrorType.SYNTAX_ERROR, formatted, source, lineNum, columnNum, token);
}
 
Example 20
Source File: AbstractParser.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Report an error.
 *
 * @param errorType  The error type
 * @param message    Error message.
 * @param errorToken Offending token.
 * @return ParserException upon failure. Caller should throw and not ignore
 */
protected final ParserException error(final JSErrorType errorType, final String message, final long errorToken) {
    final int position  = Token.descPosition(errorToken);
    final int lineNum   = source.getLine(position);
    final int columnNum = source.getColumn(position);
    final String formatted = ErrorManager.format(message, source, lineNum, columnNum, errorToken);
    return new ParserException(errorType, formatted, source, lineNum, columnNum, errorToken);
}