@Test public void testGetASTString() { final JavascriptASTExtractor ex = new JavascriptASTExtractor(false); assertTrue(classContent.length() > 0); final ASTNode classCU = ex.getASTNode(classContent, ParseType.COMPILATION_UNIT); assertTrue(methodContent.length() > 0); final ASTNode methodCU = ex.getASTNode(methodContent, ParseType.METHOD); }
public final ASTNode getASTNode(final char[] content, final ParseType parseType) { final ASTParser parser = ASTParser.newParser(AST.JLS3); final int astKind; switch (parseType) { case CLASS_BODY: case METHOD: astKind = ASTParser.K_CLASS_BODY_DECLARATIONS; break; case COMPILATION_UNIT: astKind = ASTParser.K_COMPILATION_UNIT; break; case EXPRESSION: astKind = ASTParser.K_EXPRESSION; break; case STATEMENTS: astKind = ASTParser.K_STATEMENTS; break; default: astKind = ASTParser.K_COMPILATION_UNIT; } parser.setKind(astKind); final Map<String, String> options = new Hashtable<String, String>(); options.put(JavaScriptCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaScriptCore.VERSION_1_7); options.put(JavaScriptCore.COMPILER_SOURCE, JavaScriptCore.VERSION_1_7); if (useJavadocs) { options.put(JavaScriptCore.COMPILER_DOC_COMMENT_SUPPORT, JavaScriptCore.ENABLED); } parser.setCompilerOptions(options); parser.setSource(content); parser.setResolveBindings(useBindings); parser.setBindingsRecovery(useBindings); parser.setStatementsRecovery(true); if (parseType != ParseType.METHOD) { return parser.createAST(null); } else { final ASTNode cu = parser.createAST(null); return getFirstFunctionDeclaration(cu); } }
JavascriptASTExtractor { public final ASTNode getASTNode(final char[] content, final ParseType parseType) { final ASTParser parser = ASTParser.newParser(AST.JLS3); final int astKind; switch (parseType) { case CLASS_BODY: case METHOD: astKind = ASTParser.K_CLASS_BODY_DECLARATIONS; break; case COMPILATION_UNIT: astKind = ASTParser.K_COMPILATION_UNIT; break; case EXPRESSION: astKind = ASTParser.K_EXPRESSION; break; case STATEMENTS: astKind = ASTParser.K_STATEMENTS; break; default: astKind = ASTParser.K_COMPILATION_UNIT; } parser.setKind(astKind); final Map<String, String> options = new Hashtable<String, String>(); options.put(JavaScriptCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaScriptCore.VERSION_1_7); options.put(JavaScriptCore.COMPILER_SOURCE, JavaScriptCore.VERSION_1_7); if (useJavadocs) { options.put(JavaScriptCore.COMPILER_DOC_COMMENT_SUPPORT, JavaScriptCore.ENABLED); } parser.setCompilerOptions(options); parser.setSource(content); parser.setResolveBindings(useBindings); parser.setBindingsRecovery(useBindings); parser.setStatementsRecovery(true); if (parseType != ParseType.METHOD) { return parser.createAST(null); } else { final ASTNode cu = parser.createAST(null); return getFirstFunctionDeclaration(cu); } } }
JavascriptASTExtractor { public final ASTNode getASTNode(final char[] content, final ParseType parseType) { final ASTParser parser = ASTParser.newParser(AST.JLS3); final int astKind; switch (parseType) { case CLASS_BODY: case METHOD: astKind = ASTParser.K_CLASS_BODY_DECLARATIONS; break; case COMPILATION_UNIT: astKind = ASTParser.K_COMPILATION_UNIT; break; case EXPRESSION: astKind = ASTParser.K_EXPRESSION; break; case STATEMENTS: astKind = ASTParser.K_STATEMENTS; break; default: astKind = ASTParser.K_COMPILATION_UNIT; } parser.setKind(astKind); final Map<String, String> options = new Hashtable<String, String>(); options.put(JavaScriptCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaScriptCore.VERSION_1_7); options.put(JavaScriptCore.COMPILER_SOURCE, JavaScriptCore.VERSION_1_7); if (useJavadocs) { options.put(JavaScriptCore.COMPILER_DOC_COMMENT_SUPPORT, JavaScriptCore.ENABLED); } parser.setCompilerOptions(options); parser.setSource(content); parser.setResolveBindings(useBindings); parser.setBindingsRecovery(useBindings); parser.setStatementsRecovery(true); if (parseType != ParseType.METHOD) { return parser.createAST(null); } else { final ASTNode cu = parser.createAST(null); return getFirstFunctionDeclaration(cu); } } JavascriptASTExtractor(final boolean useBindings);  JavascriptASTExtractor(final boolean useBindings,
			final boolean useJavadocs); }
JavascriptASTExtractor { public final ASTNode getASTNode(final char[] content, final ParseType parseType) { final ASTParser parser = ASTParser.newParser(AST.JLS3); final int astKind; switch (parseType) { case CLASS_BODY: case METHOD: astKind = ASTParser.K_CLASS_BODY_DECLARATIONS; break; case COMPILATION_UNIT: astKind = ASTParser.K_COMPILATION_UNIT; break; case EXPRESSION: astKind = ASTParser.K_EXPRESSION; break; case STATEMENTS: astKind = ASTParser.K_STATEMENTS; break; default: astKind = ASTParser.K_COMPILATION_UNIT; } parser.setKind(astKind); final Map<String, String> options = new Hashtable<String, String>(); options.put(JavaScriptCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaScriptCore.VERSION_1_7); options.put(JavaScriptCore.COMPILER_SOURCE, JavaScriptCore.VERSION_1_7); if (useJavadocs) { options.put(JavaScriptCore.COMPILER_DOC_COMMENT_SUPPORT, JavaScriptCore.ENABLED); } parser.setCompilerOptions(options); parser.setSource(content); parser.setResolveBindings(useBindings); parser.setBindingsRecovery(useBindings); parser.setStatementsRecovery(true); if (parseType != ParseType.METHOD) { return parser.createAST(null); } else { final ASTNode cu = parser.createAST(null); return getFirstFunctionDeclaration(cu); } } JavascriptASTExtractor(final boolean useBindings);  JavascriptASTExtractor(final boolean useBindings,
			final boolean useJavadocs); final JavaScriptUnit getAST(final File file); final ASTNode getAST(final String fileContent,
			final ParseType parseType); final ASTNode getASTNode(final char[] content,
			final ParseType parseType); final ASTNode getASTNode(final String fileContent,
			final ParseType parseType); final ASTNode getCompilationUnitAstNode(final char[] content); final ASTNode getCompilationUnitAstNode(final String fileContent); }
JavascriptASTExtractor { public final ASTNode getASTNode(final char[] content, final ParseType parseType) { final ASTParser parser = ASTParser.newParser(AST.JLS3); final int astKind; switch (parseType) { case CLASS_BODY: case METHOD: astKind = ASTParser.K_CLASS_BODY_DECLARATIONS; break; case COMPILATION_UNIT: astKind = ASTParser.K_COMPILATION_UNIT; break; case EXPRESSION: astKind = ASTParser.K_EXPRESSION; break; case STATEMENTS: astKind = ASTParser.K_STATEMENTS; break; default: astKind = ASTParser.K_COMPILATION_UNIT; } parser.setKind(astKind); final Map<String, String> options = new Hashtable<String, String>(); options.put(JavaScriptCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaScriptCore.VERSION_1_7); options.put(JavaScriptCore.COMPILER_SOURCE, JavaScriptCore.VERSION_1_7); if (useJavadocs) { options.put(JavaScriptCore.COMPILER_DOC_COMMENT_SUPPORT, JavaScriptCore.ENABLED); } parser.setCompilerOptions(options); parser.setSource(content); parser.setResolveBindings(useBindings); parser.setBindingsRecovery(useBindings); parser.setStatementsRecovery(true); if (parseType != ParseType.METHOD) { return parser.createAST(null); } else { final ASTNode cu = parser.createAST(null); return getFirstFunctionDeclaration(cu); } } JavascriptASTExtractor(final boolean useBindings);  JavascriptASTExtractor(final boolean useBindings,
			final boolean useJavadocs); final JavaScriptUnit getAST(final File file); final ASTNode getAST(final String fileContent,
			final ParseType parseType); final ASTNode getASTNode(final char[] content,
			final ParseType parseType); final ASTNode getASTNode(final String fileContent,
			final ParseType parseType); final ASTNode getCompilationUnitAstNode(final char[] content); final ASTNode getCompilationUnitAstNode(final String fileContent);  }