org.eclipse.wst.jsdt.core.dom.JavaScriptUnit Java Examples

The following examples show how to use org.eclipse.wst.jsdt.core.dom.JavaScriptUnit. 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: JavascriptFunctionCounter.java    From api-mining with GNU General Public License v3.0 6 votes vote down vote up
public static void countFunctions(final File projectDir) throws IOException {

		System.out.println("\n===== Project " + projectDir);
		final MethodClassCountVisitor mccv = new MethodClassCountVisitor();
		final JavascriptASTExtractor astExtractor = new JavascriptASTExtractor(
				false);

		final List<File> files = (List<File>) FileUtils.listFiles(projectDir,
				new String[] { "js" }, true);

		int count = 0;
		for (final File file : files) {

			final JavaScriptUnit cu = astExtractor.getAST(file);
			cu.accept(mccv);

			if (count % 1000 == 0)
				System.out.println("At file " + count + " of " + files.size());
			count++;
		}

		System.out.println("Project " + projectDir);
		System.out.println("No. *.js files " + files.size());
		System.out.println("No. Functions: " + mccv.noFunctions);
	}
 
Example #2
Source File: JavascriptFunctionCounter.java    From tassal with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void countFunctions(final File projectDir) throws IOException {

		System.out.println("\n===== Project " + projectDir);
		final MethodClassCountVisitor mccv = new MethodClassCountVisitor();
		final JavascriptASTExtractor astExtractor = new JavascriptASTExtractor(
				false);

		final List<File> files = (List<File>) FileUtils.listFiles(projectDir,
				new String[] { "js" }, true);

		int count = 0;
		for (final File file : files) {

			final JavaScriptUnit cu = astExtractor.getAST(file);
			cu.accept(mccv);

			if (count % 1000 == 0)
				System.out.println("At file " + count + " of " + files.size());
			count++;
		}

		System.out.println("Project " + projectDir);
		System.out.println("No. *.js files " + files.size());
		System.out.println("No. Functions: " + mccv.noFunctions);
	}
 
Example #3
Source File: JavascriptFunctionCounter.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void countFunctions(final File projectDir) throws IOException {

		System.out.println("\n===== Project " + projectDir);
		final MethodClassCountVisitor mccv = new MethodClassCountVisitor();
		final JavascriptASTExtractor astExtractor = new JavascriptASTExtractor(
				false);

		final List<File> files = (List<File>) FileUtils.listFiles(projectDir,
				new String[] { "js" }, true);

		int count = 0;
		for (final File file : files) {

			final JavaScriptUnit cu = astExtractor.getAST(file);
			cu.accept(mccv);

			if (count % 1000 == 0)
				System.out.println("At file " + count + " of " + files.size());
			count++;
		}

		System.out.println("Project " + projectDir);
		System.out.println("No. *.js files " + files.size());
		System.out.println("No. Functions: " + mccv.noFunctions);
	}
 
Example #4
Source File: FunctionRetriever.java    From api-mining with GNU General Public License v3.0 5 votes vote down vote up
public static Map<String, FunctionDeclaration> getFunctionNodes(
		final File file) throws IOException {
	final JavascriptASTExtractor astExtractor = new JavascriptASTExtractor(
			false);
	final FunctionRetriever m = new FunctionRetriever();
	final JavaScriptUnit cu = astExtractor.getAST(file);
	cu.accept(m);
	return m.functions;
}
 
Example #5
Source File: JavascriptASTExtractor.java    From api-mining with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 #6
Source File: FunctionRetriever.java    From tassal with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Map<String, FunctionDeclaration> getFunctionNodes(
		final File file) throws IOException {
	final JavascriptASTExtractor astExtractor = new JavascriptASTExtractor(
			false);
	final FunctionRetriever m = new FunctionRetriever();
	final JavaScriptUnit cu = astExtractor.getAST(file);
	cu.accept(m);
	return m.functions;
}
 
Example #7
Source File: JavascriptASTExtractor.java    From tassal with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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 #8
Source File: FunctionRetriever.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Map<String, FunctionDeclaration> getFunctionNodes(
		final File file) throws IOException {
	final JavascriptASTExtractor astExtractor = new JavascriptASTExtractor(
			false);
	final FunctionRetriever m = new FunctionRetriever();
	final JavaScriptUnit cu = astExtractor.getAST(file);
	cu.accept(m);
	return m.functions;
}
 
Example #9
Source File: JavascriptASTExtractor.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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 #10
Source File: NodeFinder.java    From api-mining with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean visit(final JavaScriptUnit node) {
	return visitNode(node);
}
 
Example #11
Source File: NodeFinder.java    From tassal with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public boolean visit(final JavaScriptUnit node) {
	return visitNode(node);
}
 
Example #12
Source File: NodeFinder.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public boolean visit(final JavaScriptUnit node) {
	return visitNode(node);
}