public ParseResult parse ( String fileContent ) { ParseResult result = null ; // setup environment and initialize the parser. CompilerEnvirons environment = new CompilerEnvirons ( ) ; environment . setLanguageVersion ( 180 ) ; environment . setStrictMode ( false ) ; environment . setRecordingComments ( true ) ; environment . setAllowSharpComments ( true ) ; environment . setRecordingLocalJsDocComments ( true ) ; // IMPORTANT: the parser can only be used once! Parser parser = new Parser ( environment ) ; try { AstRoot root = parser . parse ( new StringReader ( fileContent ) , null , 1 ) ; result = new ParseResult ( ) ; // remove all comments result . setContentWithoutComments ( root . toSource ( ) ) ; // remove all header comments SortedSet < Comment > comments = root . getComments ( ) ; if ( comments != null && ! comments . isEmpty ( ) ) { String headerlessFileContent = removeHeaderComments ( fileContent , comments ) ; result . setContentWithoutHeaderComments ( headerlessFileContent ) ; } } catch ( Exception e ) { logger . debug ( "Error parsing JavaScript file: {}" , e . getMessage ( ) ) ; } return result ; }
Parse the file content and return variants of the file .