public class ToolFactory
extends java.lang.Object
This class provides static methods only; it is not intended to be instantiated or subclassed by clients.
Provisional API: This class/interface is part of an interim API that is still under development and expected to change significantly before reaching stability. It is being made available at this early stage to solicit feedback from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken (repeatedly) as the API evolves.Modifier and Type | Field and Description |
---|---|
static int |
M_FORMAT_EXISTING
This mode is used for formatting existing code when all formatter options should be used.
|
static int |
M_FORMAT_NEW
This mode is used for formatting new code when some formatter options should not be used.
|
Constructor and Description |
---|
ToolFactory() |
Modifier and Type | Method and Description |
---|---|
static CodeFormatter |
createCodeFormatter(java.util.Map options)
Create an instance of the built-in code formatter.
|
static CodeFormatter |
createCodeFormatter(java.util.Map options,
int mode)
Create an instance of the built-in code formatter.
|
static IScanner |
createScanner(boolean tokenizeComments,
boolean tokenizeWhiteSpace,
boolean assertMode,
boolean recordLineSeparator)
Create a scanner, indicating the level of detail requested for tokenizing.
|
static IScanner |
createScanner(boolean tokenizeComments,
boolean tokenizeWhiteSpace,
boolean recordLineSeparator,
java.lang.String sourceLevel)
Create a scanner, indicating the level of detail requested for tokenizing.
|
static IScanner |
createScanner(boolean tokenizeComments,
boolean tokenizeWhiteSpace,
boolean recordLineSeparator,
java.lang.String sourceLevel,
java.lang.String complianceLevel)
Create a scanner, indicating the level of detail requested for tokenizing.
|
public static final int M_FORMAT_NEW
Clients that are formatting new code are recommended to use this mode.
public static final int M_FORMAT_EXISTING
Clients that are formatting existing code are recommended to use this mode.
public static CodeFormatter createCodeFormatter(java.util.Map options)
The given options should at least provide the source level (JavaScriptCore.COMPILER_SOURCE
),
the compiler compliance level (JavaScriptCore.COMPILER_COMPLIANCE
) and the target platform
(JavaScriptCore.COMPILER_CODEGEN_TARGET_PLATFORM
).
Without these options, it is not possible for the code formatter to know what kind of source it needs to format.
Note this is equivalent to createCodeFormatter(options, M_FORMAT_NEW)
. Thus some code formatter options
may be ignored. See @{link M_FORMAT_NEW
for more details.
options
- - the options map to use for formatting with the default code formatter. Recognized options
are documented on JavaScriptCore#getDefaultOptions()
. If set to null
, then use
the current settings from JavaScriptCore#getOptions
.CodeFormatter
,
JavaScriptCore.getOptions()
public static CodeFormatter createCodeFormatter(java.util.Map options, int mode)
The given options should at least provide the source level (JavaScriptCore.COMPILER_SOURCE
),
the compiler compliance level (JavaScriptCore.COMPILER_COMPLIANCE
) and the target platform
(JavaScriptCore.COMPILER_CODEGEN_TARGET_PLATFORM
).
Without these options, it is not possible for the code formatter to know what kind of source it needs to format.
The given mode determines what options should be enabled when formatting the code. It can have the following
values: M_FORMAT_NEW
, M_FORMAT_EXISTING
, but other values may be added in the future.
options
- the options map to use for formatting with the default code formatter. Recognized options
are documented on JavaScriptCore#getDefaultOptions()
. If set to null
, then use
the current settings from JavaScriptCore#getOptions
.mode
- the given mode to modify the given options.CodeFormatter
,
JavaScriptCore.getOptions()
public static IScanner createScanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean assertMode, boolean recordLineSeparator)
IScanner scanner = ToolFactory.createScanner(false, false, false, false);
scanner.setSource("int i = 0;".toCharArray());
while (true) {
int token = scanner.getNextToken();
if (token == ITerminalSymbols.TokenNameEOF) break;
System.out.println(token + " : " + new String(scanner.getCurrentTokenSource()));
}
The returned scanner will tolerate unterminated line comments (missing line separator). It can be made stricter
by using API with extra boolean parameter (strictCommentMode
).
tokenizeComments
- if set to false
, comments will be silently consumedtokenizeWhiteSpace
- if set to false
, white spaces will be silently consumed,assertMode
- if set to false
, occurrences of 'assert' will be reported as identifiers
(ITerminalSymbols#TokenNameIdentifier
), whereas if set to true
, it
would report assert keywords (ITerminalSymbols#TokenNameassert
).recordLineSeparator
- if set to true
, the scanner will record positions of encountered line
separator ends. In case of multi-character line separators, the last character position is considered. These positions
can then be extracted using IScanner#getLineEnds
. Only non-unicode escape sequences are
considered as valid line separators.IScanner
public static IScanner createScanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean recordLineSeparator, java.lang.String sourceLevel)
IScanner scanner = ToolFactory.createScanner(false, false, false, false);
scanner.setSource("int i = 0;".toCharArray());
while (true) {
int token = scanner.getNextToken();
if (token == ITerminalSymbols.TokenNameEOF) break;
System.out.println(token + " : " + new String(scanner.getCurrentTokenSource()));
}
The returned scanner will tolerate unterminated line comments (missing line separator). It can be made stricter
by using API with extra boolean parameter (strictCommentMode
).
tokenizeComments
- if set to false
, comments will be silently consumedtokenizeWhiteSpace
- if set to false
, white spaces will be silently consumed,recordLineSeparator
- if set to true
, the scanner will record positions of encountered line
separator ends. In case of multi-character line separators, the last character position is considered. These positions
can then be extracted using IScanner#getLineEnds
. Only non-unicode escape sequences are
considered as valid line separators.sourceLevel
- if set to "1.3"
or null
, occurrences of 'assert' will be reported as identifiers
(ITerminalSymbols#TokenNameIdentifier
), whereas if set to "1.4"
, it
would report assert keywords (ITerminalSymbols#TokenNameassert
).IScanner
public static IScanner createScanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean recordLineSeparator, java.lang.String sourceLevel, java.lang.String complianceLevel)
IScanner scanner = ToolFactory.createScanner(false, false, false, false);
scanner.setSource("int i = 0;".toCharArray());
while (true) {
int token = scanner.getNextToken();
if (token == ITerminalSymbols.TokenNameEOF) break;
System.out.println(token + " : " + new String(scanner.getCurrentTokenSource()));
}
The returned scanner will tolerate unterminated line comments (missing line separator). It can be made stricter
by using API with extra boolean parameter (strictCommentMode
).
tokenizeComments
- if set to false
, comments will be silently consumedtokenizeWhiteSpace
- if set to false
, white spaces will be silently consumed,recordLineSeparator
- if set to true
, the scanner will record positions of encountered line
separator ends. In case of multi-character line separators, the last character position is considered. These positions
can then be extracted using IScanner#getLineEnds
. Only non-unicode escape sequences are
considered as valid line separators.sourceLevel
- if set to "1.3"
or null
, occurrences of 'assert' will be reported as identifiers
(ITerminalSymbols#TokenNameIdentifier
), whereas if set to "1.4"
, it
would report assert keywords (ITerminalSymbols#TokenNameassert
).complianceLevel
- This is used to support the Unicode 4.0 character sets. if set to 1.5 or above,
the Unicode 4.0 is supporte, otherwise Unicode 3.0 is supported.IScanner
Copyright (c) IBM Corp. and others 2000, 2010. All Rights Reserved.