codemining.js.codeutils.JavascriptASTExtractor Java Examples

The following examples show how to use codemining.js.codeutils.JavascriptASTExtractor. 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 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 #2
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 #3
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 #4
Source File: AbstractJavascriptNameBindingsExtractor.java    From api-mining with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<TokenNameBinding> getNameBindings(final String code) {
	final JavascriptASTExtractor ex = createExtractor();
	try {
		return getNameBindings(ex.getCompilationUnitAstNode(code), code);
	} catch (final Exception e) {
		throw new IllegalArgumentException(e);
	}
}
 
Example #5
Source File: AbstractJavascriptNameBindingsExtractor.java    From api-mining with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ResolvedSourceCode getResolvedSourceCode(final File f)
		throws IOException {
	final JavascriptASTExtractor ex = createExtractor();
	return getResolvedSourceCode(FileUtils.readFileToString(f),
			getNameBindings(ex.getAST(f)));
}
 
Example #6
Source File: AbstractJavascriptNameBindingsExtractor.java    From api-mining with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ResolvedSourceCode getResolvedSourceCode(final String code) {
	final JavascriptASTExtractor ex = createExtractor();
	try {
		return getResolvedSourceCode(code,
				getNameBindings(ex.getCompilationUnitAstNode(code)));
	} catch (final Exception e) {
		throw new IllegalArgumentException(e);
	}
}
 
Example #7
Source File: AbstractJavascriptNameBindingsExtractor.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public ResolvedSourceCode getResolvedSourceCode(final String code) {
	final JavascriptASTExtractor ex = createExtractor();
	try {
		return getResolvedSourceCode(code,
				getNameBindings(ex.getCompilationUnitAstNode(code)));
	} catch (final Exception e) {
		throw new IllegalArgumentException(e);
	}
}
 
Example #8
Source File: AbstractJavascriptNameBindingsExtractor.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public ResolvedSourceCode getResolvedSourceCode(final File f)
		throws IOException {
	final JavascriptASTExtractor ex = createExtractor();
	return getResolvedSourceCode(FileUtils.readFileToString(f),
			getNameBindings(ex.getAST(f)));
}
 
Example #9
Source File: AbstractJavascriptNameBindingsExtractor.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public List<TokenNameBinding> getNameBindings(final String code) {
	final JavascriptASTExtractor ex = createExtractor();
	try {
		return getNameBindings(ex.getCompilationUnitAstNode(code), code);
	} catch (final Exception e) {
		throw new IllegalArgumentException(e);
	}
}
 
Example #10
Source File: AbstractJavascriptNameBindingsExtractor.java    From tassal with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public List<TokenNameBinding> getNameBindings(final String code) {
	final JavascriptASTExtractor ex = createExtractor();
	try {
		return getNameBindings(ex.getCompilationUnitAstNode(code), code);
	} catch (final Exception e) {
		throw new IllegalArgumentException(e);
	}
}
 
Example #11
Source File: AbstractJavascriptNameBindingsExtractor.java    From tassal with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public ResolvedSourceCode getResolvedSourceCode(final File f)
		throws IOException {
	final JavascriptASTExtractor ex = createExtractor();
	return getResolvedSourceCode(FileUtils.readFileToString(f),
			getNameBindings(ex.getAST(f)));
}
 
Example #12
Source File: AbstractJavascriptNameBindingsExtractor.java    From tassal with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public ResolvedSourceCode getResolvedSourceCode(final String code) {
	final JavascriptASTExtractor ex = createExtractor();
	try {
		return getResolvedSourceCode(code,
				getNameBindings(ex.getCompilationUnitAstNode(code)));
	} catch (final Exception e) {
		throw new IllegalArgumentException(e);
	}
}
 
Example #13
Source File: JavascriptCyclomaticCalculator.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public int getComplexity(final File file) throws IOException {
	final JavascriptASTExtractor ast = new JavascriptASTExtractor(false);
	final JunctionVisitor visitor = new JunctionVisitor();
	ast.getAST(file).accept(visitor);
	return visitor.complexity;
}
 
Example #14
Source File: JavascriptExactVariableBindingsExtractor.java    From api-mining with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected JavascriptASTExtractor createExtractor() {
	return new JavascriptASTExtractor(true);
}
 
Example #15
Source File: AbstractJavascriptNameBindingsExtractor.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public List<TokenNameBinding> getNameBindings(final File f)
		throws IOException {
	final JavascriptASTExtractor ex = createExtractor();
	return getNameBindings(ex.getAST(f), FileUtils.readFileToString(f));
}
 
Example #16
Source File: AbstractJavascriptNameBindingsExtractor.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
protected JavascriptASTExtractor createExtractor() {
	return new JavascriptASTExtractor(false);
}
 
Example #17
Source File: JavascriptExactVariableBindingsExtractor.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected JavascriptASTExtractor createExtractor() {
	return new JavascriptASTExtractor(true);
}
 
Example #18
Source File: JavascriptCyclomaticCalculator.java    From tassal with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public int getComplexity(final File file) throws IOException {
	final JavascriptASTExtractor ast = new JavascriptASTExtractor(false);
	final JunctionVisitor visitor = new JunctionVisitor();
	ast.getAST(file).accept(visitor);
	return visitor.complexity;
}
 
Example #19
Source File: AbstractJavascriptNameBindingsExtractor.java    From tassal with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public List<TokenNameBinding> getNameBindings(final File f)
		throws IOException {
	final JavascriptASTExtractor ex = createExtractor();
	return getNameBindings(ex.getAST(f), FileUtils.readFileToString(f));
}
 
Example #20
Source File: AbstractJavascriptNameBindingsExtractor.java    From tassal with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
protected JavascriptASTExtractor createExtractor() {
	return new JavascriptASTExtractor(false);
}
 
Example #21
Source File: JavascriptExactVariableBindingsExtractor.java    From tassal with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected JavascriptASTExtractor createExtractor() {
	return new JavascriptASTExtractor(true);
}
 
Example #22
Source File: JavascriptCyclomaticCalculator.java    From api-mining with GNU General Public License v3.0 4 votes vote down vote up
public int getComplexity(final File file) throws IOException {
	final JavascriptASTExtractor ast = new JavascriptASTExtractor(false);
	final JunctionVisitor visitor = new JunctionVisitor();
	ast.getAST(file).accept(visitor);
	return visitor.complexity;
}
 
Example #23
Source File: AbstractJavascriptNameBindingsExtractor.java    From api-mining with GNU General Public License v3.0 4 votes vote down vote up
@Override
public List<TokenNameBinding> getNameBindings(final File f)
		throws IOException {
	final JavascriptASTExtractor ex = createExtractor();
	return getNameBindings(ex.getAST(f), FileUtils.readFileToString(f));
}
 
Example #24
Source File: AbstractJavascriptNameBindingsExtractor.java    From api-mining with GNU General Public License v3.0 4 votes vote down vote up
protected JavascriptASTExtractor createExtractor() {
	return new JavascriptASTExtractor(false);
}