Class TokenStreamImpl
java.lang.Object
org.codehaus.janino.TokenStreamImpl
- All Implemented Interfaces:
TokenStream
Standard implementation for the
TokenStream.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final CompileExceptioncompileException(String message) Convenience method for throwing aCompileException.doc()Gets the text of the doc comment (a.k.a.private static intprivate static intprivate static Stringlocation()peek()booleanintChecks whether the value of the next token equals any of the suspected; does not consume the next token.booleanintChecks whether the type of the next token is any of the suspected; does not consume the next token.booleanpeekNextButOne(String suspected) booleanChecks whether the value of the next token equals the suspected; if so, consumes the token.intChecks whether the value of the next token is one of the suspected; if so, consumes the token.Checks whether the type of the next token is the suspected; if so, consumes the token.intChecks whether the type of the next token is one of the suspected; if so, consumes the token.private Tokenread()voidVerifies that the value of the next token equals expected, and consumes the token.intVerifies that the value of the next token equals one of the expected, and consumes the token.Verifies that the type of the next token is the expected, and consumes the token.intVerifies that the type of the next token is one of the expected, and consumes the token.voidsetWarningHandler(WarningHandler warningHandler) By default, warnings are discarded, but an application my install aWarningHandler.toString()private voidIssues a warning with the given message and location and returns.
-
Field Details
-
scanner
-
docComment
-
previousToken
-
nextToken
-
nextButOneToken
-
warningHandler
-
-
Constructor Details
-
TokenStreamImpl
-
-
Method Details
-
produceToken
- Throws:
CompileExceptionIOException
-
doc
-
peek
- Specified by:
peekin interfaceTokenStream- Returns:
- The next token, but does not consume it
- Throws:
CompileExceptionIOException
-
peekNextButOne
- Specified by:
peekNextButOnein interfaceTokenStream- Returns:
- The next-but-one token, but consumes neither the next nor the next-but-one token
- Throws:
CompileExceptionIOException
-
peek
- Specified by:
peekin interfaceTokenStream- Returns:
- Whether the value of the next token equals suspected; does not consume the next token
- Throws:
CompileExceptionIOException
-
peek
Description copied from interface:TokenStreamChecks whether the value of the next token equals any of the suspected; does not consume the next token.- Specified by:
peekin interfaceTokenStream- Returns:
- The index of the first of the suspected that equals the value of the next token, or -1 if the value of the next token equals none of the suspected
- Throws:
CompileExceptionIOException
-
peek
- Specified by:
peekin interfaceTokenStream- Returns:
- Whether the type of the next token is suspected
- Throws:
CompileExceptionIOException
-
peek
Description copied from interface:TokenStreamChecks whether the type of the next token is any of the suspected; does not consume the next token.- Specified by:
peekin interfaceTokenStream- Returns:
- The index of the first of the suspected types that is the next token's type, or -1 if the type of the next token is none of the suspected types
- Throws:
CompileExceptionIOException
-
peekNextButOne
- Specified by:
peekNextButOnein interfaceTokenStream- Returns:
- Whether the value of the next-but-one token equals the suspected; consumes neither the next nor the next-but-one token
- Throws:
CompileExceptionIOException
-
read
- Specified by:
readin interfaceTokenStream- Returns:
- The next token, which it also consumes, or
nulliff the scanner is at end-of-input - Throws:
CompileExceptionIOException
-
read
Description copied from interface:TokenStreamVerifies that the value of the next token equals expected, and consumes the token.- Specified by:
readin interfaceTokenStream- Throws:
CompileException- The value of the next token does not equal expected (this includes the case that the scanner is at end-of-input)IOException
-
read
Description copied from interface:TokenStreamVerifies that the value of the next token equals one of the expected, and consumes the token.- Specified by:
readin interfaceTokenStream- Returns:
- The index of the consumed token within expected
- Throws:
CompileException- The value of the next token does not equal any of the expected (this includes the case where the scanner is at end-of-input)IOException
-
read
Description copied from interface:TokenStreamVerifies that the type of the next token is the expected, and consumes the token.- Specified by:
readin interfaceTokenStream- Returns:
- The value of the next token; an
internedString iff the token represents an identifier,true,false,null, or an operator - Throws:
CompileException- The next token's type is not the expectedIOException
-
read
Description copied from interface:TokenStreamVerifies that the type of the next token is one of the expected, and consumes the token.- Specified by:
readin interfaceTokenStream- Returns:
- The index of the first of the expected types that is the next token's type; -1 if the type of the next token is none of the expected
- Throws:
CompileException- The next token's type is none of the expectedIOException
-
peekRead
Description copied from interface:TokenStreamChecks whether the value of the next token equals the suspected; if so, consumes the token.- Specified by:
peekReadin interfaceTokenStream- Throws:
CompileExceptionIOException
-
peekRead
Description copied from interface:TokenStreamChecks whether the value of the next token is one of the suspected; if so, consumes the token.- Specified by:
peekReadin interfaceTokenStream- Returns:
- The index of the first of the suspected that equals the next token's value; -1 iff the next token's value equals none of the suspected
- Throws:
CompileExceptionIOException
-
peekRead
Description copied from interface:TokenStreamChecks whether the type of the next token is the suspected; if so, consumes the token.- Specified by:
peekReadin interfaceTokenStream- Returns:
- The value of the next token; an
internedString iff the token represents an identifier,true,false,null, or an operator - Throws:
CompileExceptionIOException
-
peekRead
Description copied from interface:TokenStreamChecks whether the type of the next token is one of the suspected; if so, consumes the token.- Specified by:
peekReadin interfaceTokenStream- Returns:
- The index of the elements that is the next token's type, or -1 iff the type of next token is none of the suspected
- Throws:
CompileExceptionIOException
-
location
- Specified by:
locationin interfaceTokenStream- Returns:
- The location of the first character of the previously read (not peeked!) token
-
indexOf
-
indexOf
-
setWarningHandler
Description copied from interface:TokenStreamBy default, warnings are discarded, but an application my install aWarningHandler.Notice that there is no
Parser.setErrorHandler()method, but parse errors always throw aCompileException. The reason being is that there is no reasonable way to recover from parse errors and continue parsing, so there is no need to install a custom parse error handler.- Specified by:
setWarningHandlerin interfaceTokenStream- Parameters:
warningHandler-nullto indicate that no warnings be issued
-
toString
-
warning
private void warning(String handle, String message, @Nullable Location location) throws CompileException Issues a warning with the given message and location and returns. This is done through aWarningHandlerthat was installed throughsetWarningHandler(WarningHandler).The
handleargument qualifies the warning and is typically used by theWarningHandlerto suppress individual warnings.- Throws:
CompileException- The optionally installedWarningHandlerdecided to throw aCompileException
-
compileException
Convenience method for throwing aCompileException. -
join
-