public class Scanner
extends java.lang.Object
String objects.
The optionalFileName parameter passed to many
constructors should point
| Modifier and Type | Class and Description |
|---|---|
class |
Scanner.Token
Representation of a Java™ token.
|
| Modifier and Type | Field and Description |
|---|---|
private boolean |
crLfPending |
private java.lang.String |
docComment
The optional JAVADOC comment preceding the
#nextToken. |
private boolean |
expectGreater
Whether the scanner is in 'expect greater' mode: If so, it parses character sequences like ">>>=" as
">", ">", ">", "=".
|
private java.io.Reader |
in |
private static java.util.Map<java.lang.String,java.lang.String> |
JAVA_KEYWORDS |
private static java.util.Map<java.lang.String,java.lang.String> |
JAVA_OPERATORS |
private static java.util.Map<java.lang.String,java.lang.String> |
JAVA_OPERATORS_EXPECT_GREATER |
private int |
nextChar |
private short |
nextCharColumnNumber |
private short |
nextCharLineNumber |
private java.lang.String |
optionalFileName |
private WarningHandler |
optionalWarningHandler |
private short |
tokenColumnNumber
Column number of the first character of the previously produced token (1 if token is immediately preceded by a
line break).
|
private short |
tokenLineNumber
Line number of the previously produced token (typically starting at one).
|
| Constructor and Description |
|---|
Scanner(java.io.File file)
Deprecated.
// SUPPRESS CHECKSTYLE MissingDeprecated
|
Scanner(java.io.File file,
java.lang.String optionalEncoding)
Deprecated.
// SUPPRESS CHECKSTYLE MissingDeprecated
|
Scanner(java.lang.String fileName)
Deprecated.
// SUPPRESS CHECKSTYLE MissingDeprecated
|
Scanner(java.lang.String optionalFileName,
java.io.InputStream is)
Set up a scanner that reads tokens from the given
InputStream in the platform default encoding. |
Scanner(java.lang.String optionalFileName,
java.io.InputStream is,
java.lang.String optionalEncoding)
Set up a scanner that reads tokens from the given
InputStream with the given optionalEncoding
(null means platform default encoding). |
Scanner(java.lang.String optionalFileName,
java.io.Reader in)
Set up a scanner that reads tokens from the given
Reader. |
Scanner(java.lang.String optionalFileName,
java.io.Reader in,
short initialLineNumber,
short initialColumnNumber)
Creates a
Scanner that counts lines and columns from non-default initial values. |
Scanner(java.lang.String fileName,
java.lang.String encoding)
Deprecated.
// SUPPRESS CHECKSTYLE MissingDeprecated
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Deprecated.
This method is deprecated, because the concept described above is confusing. An application should
close the underlying
InputStream or Reader itself. |
java.lang.String |
doc()
Get the text of the doc comment (a.k.a.
|
boolean |
getExpectGreater() |
java.lang.String |
getFileName() |
Location |
location() |
Scanner.Token |
produce()
Preduces and returns the next token.
|
private void |
readNextChar() |
private void |
scanLiteralCharacter(java.lang.StringBuilder sb)
Scans the next literal character into a
StringBuilder. |
private Scanner.Token |
scanNumericLiteral(boolean hadDecimalPoint) |
boolean |
setExpectGreater(boolean value)
Sets or resets the 'expect greater' mode.
|
void |
setWarningHandler(WarningHandler optionalWarningHandler)
By default, warnings are discarded, but an application my install a
WarningHandler. |
private void |
warning(java.lang.String handle,
java.lang.String message,
Location optionalLocation)
Issues a warning with the given message and location and returns.
|
private final java.lang.String optionalFileName
private final java.io.Reader in
private int nextChar
private boolean crLfPending
private short nextCharLineNumber
private short nextCharColumnNumber
private short tokenLineNumber
private short tokenColumnNumber
private java.lang.String docComment
#nextToken.private boolean expectGreater
private static final java.util.Map<java.lang.String,java.lang.String> JAVA_KEYWORDS
private static final java.util.Map<java.lang.String,java.lang.String> JAVA_OPERATORS
private static final java.util.Map<java.lang.String,java.lang.String> JAVA_OPERATORS_EXPECT_GREATER
private WarningHandler optionalWarningHandler
@Deprecated
public Scanner(java.lang.String fileName)
throws CompileException,
java.io.IOException
This method is deprecated because it leaves the input file open.
CompileExceptionjava.io.IOException@Deprecated
public Scanner(java.lang.String fileName,
java.lang.String encoding)
throws CompileException,
java.io.IOException
This method is deprecated because it leaves the input file open.
CompileExceptionjava.io.IOException@Deprecated
public Scanner(java.io.File file)
throws CompileException,
java.io.IOException
This method is deprecated because it leaves the input file open.
CompileExceptionjava.io.IOException@Deprecated
public Scanner(java.io.File file,
java.lang.String optionalEncoding)
throws CompileException,
java.io.IOException
This method is deprecated because it leaves the input file open.
CompileExceptionjava.io.IOExceptionpublic Scanner(java.lang.String optionalFileName,
java.io.InputStream is)
throws CompileException,
java.io.IOException
InputStream in the platform default encoding.
The fileName is solely used for reporting in thrown
exceptions.
CompileExceptionjava.io.IOExceptionpublic Scanner(java.lang.String optionalFileName,
java.io.InputStream is,
java.lang.String optionalEncoding)
throws CompileException,
java.io.IOException
InputStream with the given optionalEncoding
(null means platform default encoding).
The optionalFileName is used for reporting errors during
compilation and for source level debugging, and should name an existing
file. If null is passed, and the system property
org.codehaus.janino.source_debugging.enable is set to "true", then
a temporary file in org.codehaus.janino.source_debugging.dir or the
system's default temp dir is created in order to make the source code
available to a debugger.
CompileExceptionjava.io.IOExceptionpublic Scanner(java.lang.String optionalFileName,
java.io.Reader in)
throws CompileException,
java.io.IOException
Reader.
The optionalFileName is used for reporting errors during
compilation and for source level debugging, and should name an existing
file. If null is passed, and the system property
org.codehaus.janino.source_debugging.enable is set to "true", then
a temporary file in org.codehaus.janino.source_debugging.dir or the
system's default temp dir is created in order to make the source code
available to a debugger.
CompileExceptionjava.io.IOExceptionpublic Scanner(java.lang.String optionalFileName,
java.io.Reader in,
short initialLineNumber,
short initialColumnNumber)
throws CompileException,
java.io.IOException
Scanner that counts lines and columns from non-default initial values.CompileExceptionjava.io.IOExceptionpublic java.lang.String getFileName()
@Deprecated
public void close()
throws java.io.IOException
InputStream or Reader itself.InputStream, Reader) associated with this object. The results
of future calls to produce() are undefined.java.io.IOExceptionpublic java.lang.String doc()
null if the next token is not preceeded by a doc commentpublic Scanner.Token produce() throws CompileException, java.io.IOException
null
product, but by the special Scanner.Token.EOF token.CompileExceptionjava.io.IOExceptionpublic boolean getExpectGreater()
public boolean setExpectGreater(boolean value)
private Scanner.Token scanNumericLiteral(boolean hadDecimalPoint) throws CompileException, java.io.IOException
CompileExceptionjava.io.IOExceptionprivate void scanLiteralCharacter(java.lang.StringBuilder sb)
throws CompileException,
java.io.IOException
StringBuilder.CompileExceptionjava.io.IOExceptionprivate void readNextChar()
throws java.io.IOException,
CompileException
java.io.IOExceptionCompileExceptionpublic void setWarningHandler(WarningHandler optionalWarningHandler)
WarningHandler.
Notice that there is no Scanner.setErrorHandler() method, but scan errors
always throw a CompileException. The reason being is that there is no reasonable
way to recover from scan errors and continue scanning, so there is no need to install
a custom scan error handler.
optionalWarningHandler - null to indicate that no warnings be issuedprivate void warning(java.lang.String handle,
java.lang.String message,
Location optionalLocation)
throws CompileException
WarningHandler that was installed through
setWarningHandler(WarningHandler).
The handle argument qulifies the warning and is typically used by
the WarningHandler to suppress individual warnings.
CompileException