public class JSweetFactory extends Object
| Modifier and Type | Field and Description |
|---|---|
protected static org.apache.log4j.Logger |
logger
A logger to be used for internal messages.
|
| Constructor and Description |
|---|
JSweetFactory()
An empty constructor is mandatory for all subclasses.
|
| Modifier and Type | Method and Description |
|---|---|
PrinterAdapter |
createAdapter(JSweetContext context)
Creates the printer adapter or any subclass.
|
GlobalBeforeTranslationScanner |
createBeforeTranslationScanner(TranspilationHandler transpilationHandler,
JSweetContext context)
Creates the scanner which is called before translating the program.
|
JSweetContext |
createContext(JSweetOptions options)
Creates the transpiler's context or any subclass.
|
JSweetDiagnosticHandler |
createDiagnosticHandler(TranspilationHandler transpilationHandler,
JSweetContext context)
Creates a diagnostic handler (responsible for reporting Java
errors/warnings).
|
Java2TypeScriptTranslator |
createTranslator(PrinterAdapter adapter,
TranspilationHandler transpilationHandler,
JSweetContext context,
com.sun.tools.javac.tree.JCTree.JCCompilationUnit compilationUnit,
boolean fillSourceMap)
Creates the core translator or any subclass.
|
protected static final org.apache.log4j.Logger logger
public JSweetFactory()
public JSweetContext createContext(JSweetOptions options)
public PrinterAdapter createAdapter(JSweetContext context)
This is the method to be overridden to create composable extensions. Adapters are chainable (decorator pattern) and new adapters will delegate to parent adapters when not overriding the parent behavior.
For instance, here my own adapter will override the needed behavior and delegate to the default adapter chain:
@Override
public PrinterAdapter createAdapter(JSweetContext context) {
return new MyOwnAdapter(super.createAdapter(context));
}
public Java2TypeScriptTranslator createTranslator(PrinterAdapter adapter, TranspilationHandler transpilationHandler, JSweetContext context, com.sun.tools.javac.tree.JCTree.JCCompilationUnit compilationUnit, boolean fillSourceMap)
public GlobalBeforeTranslationScanner createBeforeTranslationScanner(TranspilationHandler transpilationHandler, JSweetContext context)
A typical use would be to return a subclass of
GlobalBeforeTranslationScanner in order to fill the context with
some specific global analysis results that can be used later on by the
translator.
public JSweetDiagnosticHandler createDiagnosticHandler(TranspilationHandler transpilationHandler, JSweetContext context)
One can override with a subclass to tune how JSweet reports Java messages.