use of org.stjs.generator.name.DefaultJavaScriptNameProvider in project st-js by st-js.
the class Generator method generateJavascript.
/**
* <p>generateJavascript.</p>
*
* @return the list of imports needed by the generated class
* @param className a {@link java.lang.String} object.
* @param sourceFolder a {@link java.io.File} object.
* @throws org.stjs.generator.JavascriptFileGenerationException if any.
* @throws org.stjs.generator.JavascriptFileGenerationException if any.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public ClassWithJavascript generateJavascript(String className, File sourceFolder) throws JavascriptFileGenerationException {
Class<?> clazz = ClassUtils.getClazz(config.getStjsClassLoader(), className);
if (ClassUtils.isBridge(config.getStjsClassLoader(), clazz)) {
return new BridgeClass(config.getClassResolver(), clazz);
}
File inputFile = getInputFile(sourceFolder, className);
File outputFile = getOutputFile(config.getGenerationFolder().getGeneratedSourcesAbsolutePath(), className);
JavaScriptNameProvider names = new DefaultJavaScriptNameProvider();
GenerationPlugins<Object> currentClassPlugins = plugins.forClass(clazz);
GenerationContext<Object> context = new GenerationContext<Object>(inputFile, config, names, null, cacheAnnotations, getJavaScriptBuilder());
CompilationUnitTree cu = parseAndResolve(inputFile, context, config.getStjsClassLoader(), config.getSourceEncoding());
// check the code
Timers.start("check-java");
currentClassPlugins.getCheckVisitor().scan(cu, (GenerationContext) context);
context.getChecks().check();
Timers.end("check-java");
// generate the javascript code
Timers.start("write-js-ast");
Object javascriptRoot = currentClassPlugins.getWriterVisitor().scan(cu, context);
// check for any error arriving during writing
context.getChecks().check();
Timers.end("write-js-ast");
Class<?> javaClass = config.getClassResolver().resolveJavaClass(className);
STJSClass stjsClass = new STJSClass(config.getClassResolver(), config.getTargetFolder(), javaClass);
Map<String, DependencyType> resolvedClasses = new LinkedHashMap<String, DependencyType>(names.getResolvedTypes());
resolvedClasses.remove(className);
stjsClass.setDependencies(resolvedClasses);
stjsClass.setGeneratedJavascriptFile(getRuntimeUri(className));
TypeElement classElement = context.getElements().getTypeElement(clazz.getCanonicalName());
stjsClass.setJavascriptNamespace(context.wrap(classElement).getNamespace());
// dump the ast to a file
taskExecutor.execute(new DumpFilesTask<>(outputFile, context, javascriptRoot, stjsClass));
return stjsClass;
}
Aggregations