Class 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.
    • Constructor Detail

      • ParserConfiguration

        public ParserConfiguration()
    • 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)
      • 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.
      • 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()