org.eclipse.wst.jsdt.core.dom.AST Java Examples
The following examples show how to use
org.eclipse.wst.jsdt.core.dom.AST.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JavascriptASTExtractor.java From api-mining with GNU General Public License v3.0 | 5 votes |
/** * Get the AST of a file. It is assumed that a JavaScriptUnit will be * returned. An heuristic is used to set the path variables. * * @param file * @return the compilation unit of the file * @throws IOException */ public final JavaScriptUnit getAST(final File file) throws IOException { final String sourceFile = FileUtils.readFileToString(file); final ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setKind(ASTParser.K_COMPILATION_UNIT); 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(sourceFile.toCharArray()); // set source parser.setResolveBindings(useBindings); parser.setBindingsRecovery(useBindings); parser.setStatementsRecovery(true); parser.setUnitName(file.getAbsolutePath()); // FIXME Need file's project loaded into Eclipse to get bindings // which is only possible automatically if this were an Eclipse plugin // cf. https://bugs.eclipse.org/bugs/show_bug.cgi?id=206391 // final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); // final IProject project = root.getProject(projectName); // parser.setProject(JavaScriptCore.create(project)); final JavaScriptUnit compilationUnit = (JavaScriptUnit) parser .createAST(null); return compilationUnit; }
Example #2
Source File: JavascriptASTExtractor.java From tassal with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Get the AST of a file. It is assumed that a JavaScriptUnit will be * returned. An heuristic is used to set the path variables. * * @param file * @return the compilation unit of the file * @throws IOException */ public final JavaScriptUnit getAST(final File file) throws IOException { final String sourceFile = FileUtils.readFileToString(file); final ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setKind(ASTParser.K_COMPILATION_UNIT); 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(sourceFile.toCharArray()); // set source parser.setResolveBindings(useBindings); parser.setBindingsRecovery(useBindings); parser.setStatementsRecovery(true); parser.setUnitName(file.getAbsolutePath()); // FIXME Need file's project loaded into Eclipse to get bindings // which is only possible automatically if this were an Eclipse plugin // cf. https://bugs.eclipse.org/bugs/show_bug.cgi?id=206391 // final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); // final IProject project = root.getProject(projectName); // parser.setProject(JavaScriptCore.create(project)); final JavaScriptUnit compilationUnit = (JavaScriptUnit) parser .createAST(null); return compilationUnit; }
Example #3
Source File: JavascriptASTExtractor.java From codemining-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Get the AST of a file. It is assumed that a JavaScriptUnit will be * returned. An heuristic is used to set the path variables. * * @param file * @return the compilation unit of the file * @throws IOException */ public final JavaScriptUnit getAST(final File file) throws IOException { final String sourceFile = FileUtils.readFileToString(file); final ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setKind(ASTParser.K_COMPILATION_UNIT); 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(sourceFile.toCharArray()); // set source parser.setResolveBindings(useBindings); parser.setBindingsRecovery(useBindings); parser.setStatementsRecovery(true); parser.setUnitName(file.getAbsolutePath()); // FIXME Need file's project loaded into Eclipse to get bindings // which is only possible automatically if this were an Eclipse plugin // cf. https://bugs.eclipse.org/bugs/show_bug.cgi?id=206391 // final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); // final IProject project = root.getProject(projectName); // parser.setProject(JavaScriptCore.create(project)); final JavaScriptUnit compilationUnit = (JavaScriptUnit) parser .createAST(null); return compilationUnit; }
Example #4
Source File: JavascriptASTExtractor.java From api-mining with GNU General Public License v3.0 | 4 votes |
/** * Return an ASTNode given the content * * @param content * @return */ 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); // set source 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); } }
Example #5
Source File: JavascriptASTExtractor.java From tassal with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Return an ASTNode given the content * * @param content * @return */ 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); // set source 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); } }
Example #6
Source File: JavascriptASTExtractor.java From codemining-core with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Return an ASTNode given the content * * @param content * @return */ 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); // set source 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); } }