本文整理匯總了Java中org.eclipse.wst.jsdt.core.dom.JavaScriptUnit類的典型用法代碼示例。如果您正苦於以下問題:Java JavaScriptUnit類的具體用法?Java JavaScriptUnit怎麽用?Java JavaScriptUnit使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
JavaScriptUnit類屬於org.eclipse.wst.jsdt.core.dom包,在下文中一共展示了JavaScriptUnit類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: countFunctions
import org.eclipse.wst.jsdt.core.dom.JavaScriptUnit; //導入依賴的package包/類
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);
}
示例2: getFunctionNodes
import org.eclipse.wst.jsdt.core.dom.JavaScriptUnit; //導入依賴的package包/類
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;
}
示例3: getAST
import org.eclipse.wst.jsdt.core.dom.JavaScriptUnit; //導入依賴的package包/類
/**
* 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;
}
示例4: visit
import org.eclipse.wst.jsdt.core.dom.JavaScriptUnit; //導入依賴的package包/類
@Override
public boolean visit(final JavaScriptUnit node) {
return visitNode(node);
}