Package com.github.javaparser
Class ParserConfiguration
- java.lang.Object
-
- com.github.javaparser.ParserConfiguration
-
public class ParserConfiguration extends Object
The configuration that is used by the parser. Note that this can be changed even when reusing the same JavaParser instance. It will pick up the changes.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ParserConfiguration.LanguageLevel
-
Constructor Summary
Constructors Constructor Description ParserConfiguration()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ParserConfiguration.LanguageLevel
getLanguageLevel()
List<ParseResult.PostProcessor>
getPostProcessors()
List<Providers.PreProcessor>
getPreProcessors()
Optional<SymbolResolver>
getSymbolResolver()
Retrieve the SymbolResolver to be used while parsing, if any.int
getTabSize()
boolean
isAttributeComments()
boolean
isDoNotAssignCommentsPrecedingEmptyLines()
boolean
isIgnoreAnnotationsWhenAttributingComments()
boolean
isLexicalPreservationEnabled()
boolean
isPreprocessUnicodeEscapes()
boolean
isStoreTokens()
ParserConfiguration
setAttributeComments(boolean attributeComments)
Whether to run CommentsInserter, which will put the comments that were found in the source code into the comment and javadoc fields of the nodes it thinks they refer to.ParserConfiguration
setDoNotAssignCommentsPrecedingEmptyLines(boolean doNotAssignCommentsPrecedingEmptyLines)
ParserConfiguration
setIgnoreAnnotationsWhenAttributingComments(boolean ignoreAnnotationsWhenAttributingComments)
ParserConfiguration
setLanguageLevel(ParserConfiguration.LanguageLevel languageLevel)
ParserConfiguration
setLexicalPreservationEnabled(boolean lexicalPreservationEnabled)
Disabled by default.ParserConfiguration
setPreprocessUnicodeEscapes(boolean preprocessUnicodeEscapes)
When set to true, unicode escape handling is done by preprocessing the whole input, meaning that all unicode escapes are turned into unicode characters before parsing.ParserConfiguration
setStoreTokens(boolean storeTokens)
ParserConfiguration
setSymbolResolver(SymbolResolver symbolResolver)
Set the SymbolResolver to be injected while parsing.ParserConfiguration
setTabSize(int tabSize)
When a TAB character is encountered during parsing, the column position will be increased by this value.
-
-
-
Method Detail
-
isAttributeComments
public boolean isAttributeComments()
-
setAttributeComments
public ParserConfiguration setAttributeComments(boolean attributeComments)
Whether to run CommentsInserter, which will put the comments that were found in the source code into the comment and javadoc fields of the nodes it thinks they refer to.
-
isDoNotAssignCommentsPrecedingEmptyLines
public boolean isDoNotAssignCommentsPrecedingEmptyLines()
-
setDoNotAssignCommentsPrecedingEmptyLines
public ParserConfiguration setDoNotAssignCommentsPrecedingEmptyLines(boolean doNotAssignCommentsPrecedingEmptyLines)
-
isIgnoreAnnotationsWhenAttributingComments
public boolean isIgnoreAnnotationsWhenAttributingComments()
-
setIgnoreAnnotationsWhenAttributingComments
public ParserConfiguration setIgnoreAnnotationsWhenAttributingComments(boolean ignoreAnnotationsWhenAttributingComments)
-
setStoreTokens
public ParserConfiguration setStoreTokens(boolean storeTokens)
-
isStoreTokens
public boolean isStoreTokens()
-
getTabSize
public int getTabSize()
-
setTabSize
public ParserConfiguration setTabSize(int tabSize)
When a TAB character is encountered during parsing, the column position will be increased by this value. By default it is 1.
-
setLexicalPreservationEnabled
public ParserConfiguration setLexicalPreservationEnabled(boolean lexicalPreservationEnabled)
Disabled by default. When this is enabled, LexicalPreservingPrinter.print can be used to reproduce the original formatting of the file.
-
isLexicalPreservationEnabled
public boolean isLexicalPreservationEnabled()
-
getSymbolResolver
public Optional<SymbolResolver> getSymbolResolver()
Retrieve the SymbolResolver to be used while parsing, if any.
-
setSymbolResolver
public ParserConfiguration setSymbolResolver(SymbolResolver symbolResolver)
Set the SymbolResolver to be injected while parsing.
-
getPreProcessors
public List<Providers.PreProcessor> getPreProcessors()
-
getPostProcessors
public List<ParseResult.PostProcessor> getPostProcessors()
-
setLanguageLevel
public ParserConfiguration setLanguageLevel(ParserConfiguration.LanguageLevel languageLevel)
-
getLanguageLevel
public ParserConfiguration.LanguageLevel getLanguageLevel()
-
setPreprocessUnicodeEscapes
public ParserConfiguration setPreprocessUnicodeEscapes(boolean preprocessUnicodeEscapes)
When set to true, unicode escape handling is done by preprocessing the whole input, meaning that all unicode escapes are turned into unicode characters before parsing. That means the AST will never contain literal unicode escapes, and that positions will point to where a token was found in the *processed input*, not in the original input, which is mostly not what you want. That's why the default is false, which is not the correct way to parse a Java file according to the Java Language Specification, but it works for almost any input, since unicode escapes are mostly used in comments, strings and characters, and the parser will understand them in those locations. The unicode escapes will not be processed and are transfered intact to the AST, and the locations will point to the original stream.
-
isPreprocessUnicodeEscapes
public boolean isPreprocessUnicodeEscapes()
-
-