Class ToolFactory
This class provides static methods only.
- Since:
- 2.0
- Restriction:
- This class is not intended to be subclassed by clients.
- Restriction:
- This class is not intended to be instantiated by clients.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
This mode is used for formatting existing code when all formatter options should be used.static final int
This mode is used for formatting new code when some formatter options should not be used. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic ICodeFormatter
Deprecated.static CodeFormatter
createCodeFormatter
(Map options) Create an instance of the built-in code formatter.static CodeFormatter
createCodeFormatter
(Map options, int mode) Creates an instance of a code formatter.static ClassFileBytesDisassembler
Create a classfile bytecode disassembler, able to produce a String representation of a given classfile.static IClassFileDisassembler
Deprecated.UsecreateDefaultClassFileBytesDisassembler()
insteadstatic IClassFileReader
createDefaultClassFileReader
(InputStream stream, int decodingFlag) Create a default classfile reader, able to expose the internal representation of a given classfile according to the decoding flag used to initialize the reader.static IClassFileReader
createDefaultClassFileReader
(String fileName, int decodingFlag) Create a default classfile reader, able to expose the internal representation of a given classfile according to the decoding flag used to initialize the reader.static IClassFileReader
createDefaultClassFileReader
(String zipFileName, String zipEntryName, int decodingFlag) Create a default classfile reader, able to expose the internal representation of a given classfile according to the decoding flag used to initialize the reader.static IClassFileReader
createDefaultClassFileReader
(IClassFile classfile, int decodingFlag) Create a classfile reader onto a classfile Java element.static ICodeFormatter
createDefaultCodeFormatter
(Map options) Deprecated.UsecreateCodeFormatter(Map)
instead but note the different optionsstatic 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, String sourceLevel) Create a scanner, indicating the level of detail requested for tokenizing.static IScanner
createScanner
(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean recordLineSeparator, String sourceLevel, String complianceLevel) Create a scanner, indicating the level of detail requested for tokenizing.static IScanner
createScanner
(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean recordLineSeparator, String sourceLevel, String complianceLevel, boolean enablePreview) Create a scanner, indicating the level of detail requested for tokenizing.
-
Field Details
-
M_FORMAT_NEW
public static final int M_FORMAT_NEWThis mode is used for formatting new code when some formatter options should not be used. In particular, options that preserve the indentation of comments are not used. In the future, newly added options may be ignored as well.Clients that are formatting new code are recommended to use this mode.
-
M_FORMAT_EXISTING
public static final int M_FORMAT_EXISTINGThis mode is used for formatting existing code when all formatter options should be used. In particular, options that preserve the indentation of comments are used.Clients that are formatting existing code are recommended to use this mode.
-
-
Constructor Details
-
ToolFactory
public ToolFactory()
-
-
Method Details
-
createCodeFormatter
Deprecated.The extension point has been deprecated, usecreateCodeFormatter(Map)
instead.Create an instance of a code formatter. A code formatter implementation can be contributed via the extension point "org.eclipse.jdt.core.codeFormatter". If unable to find a registered extension, the factory will default to using the default code formatter.- Returns:
- an instance of a code formatter
- See Also:
-
createCodeFormatter
Create an instance of the built-in code formatter.The given options should at least provide the source level (
JavaCore.COMPILER_SOURCE
), the compiler compliance level (JavaCore.COMPILER_COMPLIANCE
) and the target platform (JavaCore.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 @{linkM_FORMAT_NEW
for more details.- Parameters:
options
- - the options map to use for formatting with the default code formatter. Recognized options are documented onJavaCore#getDefaultOptions()
. If set tonull
, then use the current settings fromJavaCore#getOptions
.- Returns:
- an instance of the built-in code formatter
- Since:
- 3.0
- See Also:
-
createCodeFormatter
Creates an instance of a code formatter. A code formatter implementation can be contributed via the extension point "org.eclipse.jdt.core.javaFormatter". The formatter id specified in the "org.eclipse.jdt.core.javaFormatter" is instantiated. If unable to find a registered extension, the factory will default to using the default code formatter.The given options should at least provide the source level (
JavaCore.COMPILER_SOURCE
), the compiler compliance level (JavaCore.COMPILER_COMPLIANCE
) and the target platform (JavaCore.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.- Parameters:
options
- the options map to use for formatting with the default code formatter. Recognized options are documented onJavaCore#getDefaultOptions()
. If set tonull
, then use the current settings fromJavaCore#getOptions
.mode
- the given mode to modify the given options.- Returns:
- an instance of the built-in code formatter
- Since:
- 3.3
- See Also:
-
createDefaultClassFileBytesDisassembler
Create a classfile bytecode disassembler, able to produce a String representation of a given classfile.- Returns:
- a classfile bytecode disassembler
- Since:
- 2.1
- See Also:
-
createDefaultClassFileDisassembler
Deprecated.UsecreateDefaultClassFileBytesDisassembler()
insteadCreate a classfile bytecode disassembler, able to produce a String representation of a given classfile.- Returns:
- a classfile bytecode disassembler
- See Also:
-
createDefaultClassFileReader
Create a classfile reader onto a classfile Java element. Create a default classfile reader, able to expose the internal representation of a given classfile according to the decoding flag used to initialize the reader. Answer null if the file named fileName doesn't represent a valid .class file. The decoding flags are described in IClassFileReader.- Parameters:
classfile
- the classfile element to introspectdecodingFlag
- the flag used to decode the class file reader.- Returns:
- a default classfile reader
- See Also:
-
createDefaultClassFileReader
Create a default classfile reader, able to expose the internal representation of a given classfile according to the decoding flag used to initialize the reader. Answer null if the input stream contents cannot be retrieved The decoding flags are described in IClassFileReader.- Parameters:
stream
- the given input stream to readdecodingFlag
- the flag used to decode the class file reader.- Returns:
- a default classfile reader
- Since:
- 3.2
- See Also:
-
createDefaultClassFileReader
Create a default classfile reader, able to expose the internal representation of a given classfile according to the decoding flag used to initialize the reader. Answer null if the file named fileName doesn't represent a valid .class file. The fileName has to be an absolute OS path to the given .class file. The decoding flags are described in IClassFileReader.- Parameters:
fileName
- the name of the file to be readdecodingFlag
- the flag used to decode the class file reader.- Returns:
- a default classfile reader
- See Also:
-
createDefaultClassFileReader
public static IClassFileReader createDefaultClassFileReader(String zipFileName, String zipEntryName, int decodingFlag) Create a default classfile reader, able to expose the internal representation of a given classfile according to the decoding flag used to initialize the reader. Answer null if the file named zipFileName doesn't represent a valid zip file or if the zipEntryName is not a valid entry name for the specified zip file or if the bytes don't represent a valid .class file according to the JVM specifications. The decoding flags are described in IClassFileReader.- Parameters:
zipFileName
- the name of the zip filezipEntryName
- the name of the entry in the zip file to be readdecodingFlag
- the flag used to decode the class file reader.- Returns:
- a default classfile reader
- See Also:
-
createDefaultCodeFormatter
Deprecated.UsecreateCodeFormatter(Map)
instead but note the different optionsCreate an instance of the default code formatter.- Parameters:
options
- - the options map to use for formatting with the default code formatter. Recognized options are documented onJavaCore#getDefaultOptions()
. If set tonull
, then use the current settings fromJavaCore#getOptions
.- Returns:
- an instance of the built-in code formatter
- See Also:
-
createScanner
public static IScanner createScanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean assertMode, boolean recordLineSeparator) Create a scanner, indicating the level of detail requested for tokenizing. The scanner can then be used to tokenize some source in a Java aware way. Here is a typical scanning loop: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())); }
By default the compliance used to create the scanner is the workspace's compliance when running inside the IDE or 1.4 if running from outside of a headless eclipse.
- Parameters:
tokenizeComments
- if set tofalse
, comments will be silently consumedtokenizeWhiteSpace
- if set tofalse
, white spaces will be silently consumed,assertMode
- if set tofalse
, occurrences of 'assert' will be reported as identifiers (ITerminalSymbols.TokenNameIdentifier
), whereas if set totrue
, it would report assert keywords (ITerminalSymbols.TokenNameassert
). Java 1.4 has introduced a new 'assert' keyword.recordLineSeparator
- if set totrue
, 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 usingIScanner.getLineEnds()
. Only non-unicode escape sequences are considered as valid line separators.- Returns:
- a scanner
- See Also:
-
createScanner
public static IScanner createScanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean recordLineSeparator, String sourceLevel) Create a scanner, indicating the level of detail requested for tokenizing. The scanner can then be used to tokenize some source in a Java aware way. Here is a typical scanning loop: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())); }
By default the compliance used to create the scanner is the workspace's compliance when running inside the IDE or 1.4 if running from outside of a headless eclipse.
- Parameters:
tokenizeComments
- if set tofalse
, comments will be silently consumedtokenizeWhiteSpace
- if set tofalse
, white spaces will be silently consumed,recordLineSeparator
- if set totrue
, 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 usingIScanner.getLineEnds()
. Only non-unicode escape sequences are considered as valid line separators.sourceLevel
- if set to"1.3"
ornull
, occurrences of 'assert' will be reported as identifiers (ITerminalSymbols.TokenNameIdentifier
), whereas if set to"1.4"
, it would report assert keywords (ITerminalSymbols.TokenNameassert
). Java 1.4 has introduced a new 'assert' keyword.- Returns:
- a scanner
- Since:
- 3.0
- See Also:
-
createScanner
public static IScanner createScanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean recordLineSeparator, String sourceLevel, String complianceLevel) Create a scanner, indicating the level of detail requested for tokenizing. The scanner can then be used to tokenize some source in a Java aware way. Here is a typical scanning loop: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())); }
- Parameters:
tokenizeComments
- if set tofalse
, comments will be silently consumedtokenizeWhiteSpace
- if set tofalse
, white spaces will be silently consumed,recordLineSeparator
- if set totrue
, 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 usingIScanner.getLineEnds()
. Only non-unicode escape sequences are considered as valid line separators.sourceLevel
- if set to"1.3"
ornull
, occurrences of 'assert' will be reported as identifiers (ITerminalSymbols.TokenNameIdentifier
), whereas if set to"1.4"
, it would report assert keywords (ITerminalSymbols.TokenNameassert
). Java 1.4 has introduced a new 'assert' keyword.complianceLevel
- This is used to support the Unicode 4.0 character sets. if set to 1.5 or above, the Unicode 4.0 is supported, otherwise Unicode 3.0 is supported.- Returns:
- a scanner
- Since:
- 3.1
- See Also:
-
createScanner
public static IScanner createScanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean recordLineSeparator, String sourceLevel, String complianceLevel, boolean enablePreview) Create a scanner, indicating the level of detail requested for tokenizing. The scanner can then be used to tokenize some source in a Java aware way. Here is a typical scanning loop: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())); }
- Parameters:
tokenizeComments
- if set tofalse
, comments will be silently consumedtokenizeWhiteSpace
- if set tofalse
, white spaces will be silently consumed,recordLineSeparator
- if set totrue
, 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 usingIScanner.getLineEnds()
. Only non-unicode escape sequences are considered as valid line separators.sourceLevel
- if set to"1.3"
ornull
, occurrences of 'assert' will be reported as identifiers (ITerminalSymbols.TokenNameIdentifier
), whereas if set to"1.4"
, it would report assert keywords (ITerminalSymbols.TokenNameassert
). Java 1.4 has introduced a new 'assert' keyword.complianceLevel
- This is used to support the Unicode 4.0 character sets. if set to 1.5 or above, the Unicode 4.0 is supported, otherwise Unicode 3.0 is supported.enablePreview
- specify whether the scanner should look for preview language features for the specified compliance level- Returns:
- a scanner
- Since:
- 3.20
- See Also:
-
createCodeFormatter(Map)
instead.