public class Java2TypeScriptAdapter extends PrinterAdapter
context, logger, typeVariablesToErase| Constructor and Description |
|---|
Java2TypeScriptAdapter(JSweetContext context)
Creates a root adapter (with no parent).
|
Java2TypeScriptAdapter(PrinterAdapter parent)
Creates a new adapter that will try delegate to the given parent adapter when
not implementing its own behavior.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
delegateToEmulLayer(String targetClassName,
String targetMethodName,
InvocationElement invocation) |
protected void |
delegateToEmulLayer(String targetClassName,
VariableAccessElement fieldAccess) |
protected void |
delegateToEmulLayerStatic(String targetClassName,
String targetMethodName,
ExtendedElement target) |
Set<String> |
getErasedTypes() |
Java2TypeScriptTranslator |
getPrinter()
Gets the printer on which rely the adapter (this is not recommended).
|
String |
needsImport(ImportElement importElement,
String qualifiedName)
Returns the import qualified id if the given import requires an import
statement to be printed.
|
protected void |
printCastMethodInvocation(InvocationElement invocation) |
protected void |
printForEachLoop(com.sun.tools.javac.tree.JCTree.JCEnhancedForLoop loop,
String indexVarName) |
protected void |
printFunctionalInvocation(ExtendedElement target,
String functionName,
List<ExtendedElement> arguments) |
protected PrinterAdapter |
printTarget(ExtendedElement target) |
boolean |
substituteAndPrintType(ExtendedElement enclosingElement,
TypeElement type) |
boolean |
substituteForEachLoop(ForeachLoopElement foreachLoop,
boolean targetHasLength,
String indexVarName)
Substitutes if necessary the given foreach loop.
|
boolean |
substituteIdentifier(IdentifierElement identifierElement)
Substitutes the value of an identifier.
|
boolean |
substituteMethodInvocation(MethodInvocationElement invocationElement)
Substitutes the value of a method invocation expression.
|
boolean |
substituteNewClass(NewClassElement newClassElement)
To override to tune the printing of a new class expression.
|
boolean |
substituteVariableAccess(VariableAccessElement variableAccess)
Substitutes the given variable access.
|
adaptDocComment, addAnnotation, addAnnotation, addAnnotationManager, addAnnotationWithValue, addHeader, addTypeMapping, addTypeMapping, addTypeMappings, afterType, endIndent, eraseSuperClass, eraseSuperInterface, findExecutableDeclarationInType, getAnnotationValue, getAnnotationValue, getContext, getFunctionalTypeMappings, getHeader, getMappedType, getModuleImportDescriptor, getParentAdapter, getParentElement, getParentElement, getRootRelativeName, getTranspilerOptions, getTypeMappingTarget, hasAnnotationType, isAmbientDeclaration, isMappedType, isSubstituteSuperTypes, print, print, print, print, printArgList, printIdentifierList, printIndent, println, printMacroName, removeLastChar, removeLastChar, removeLastChars, removeLastIndent, report, report, report, report, setParentAdapter, setPrinter, space, startIndent, substitute, substituteArrayAccess, substituteAssignment, substituteAssignmentWithOperator, substituteBinaryOperator, substituteCaseStatementPattern, substituteInstanceof, substituteUnaryOperator, types, utilpublic Java2TypeScriptAdapter(JSweetContext context)
context - the transpilation contextpublic Java2TypeScriptAdapter(PrinterAdapter parent)
parentAdapter - cannot be null: if no parent you must use the
#AbstractPrinterAdapter(JSweetContext) constructorpublic Java2TypeScriptTranslator getPrinter()
PrinterAdapter
Accessing the printer with this method allows the user to access the internal
javac API directly (com.sun.tools.javac), which is non-standard and
may get deprecated in future Java versions. As a consequence, to write
sustainable adapters, it is not recommended to use the printer API.
Instead, use the adapter's API directly, which relies on an abstraction of
the AST: javax.lang.model and org.jsweet.transpiler.model. If
some feature seems to be missing, please contact JSweet.org to help improving
this API.
getPrinter in class PrinterAdapterpublic String needsImport(ImportElement importElement, String qualifiedName)
PrinterAdapterneedsImport in class PrinterAdapterimportElement - the given import declarationqualifiedName - the qualified import idpublic boolean substituteMethodInvocation(MethodInvocationElement invocationElement)
PrinterAdaptersubstituteMethodInvocation in class PrinterAdapterinvocationElement - the invocation being printedprotected void printFunctionalInvocation(ExtendedElement target, String functionName, List<ExtendedElement> arguments)
protected final PrinterAdapter printTarget(ExtendedElement target)
protected final void delegateToEmulLayer(String targetClassName, String targetMethodName, InvocationElement invocation)
protected final void delegateToEmulLayerStatic(String targetClassName, String targetMethodName, ExtendedElement target)
protected final void printCastMethodInvocation(InvocationElement invocation)
public boolean substituteAndPrintType(ExtendedElement enclosingElement, TypeElement type)
enclosingElement - is required for functional (ie dynamic) type mappingspublic boolean substituteVariableAccess(VariableAccessElement variableAccess)
PrinterAdaptersubstituteVariableAccess in class PrinterAdaptervariableAccess - the variable access being printedprotected final void delegateToEmulLayer(String targetClassName, VariableAccessElement fieldAccess)
public boolean substituteNewClass(NewClassElement newClassElement)
PrinterAdaptersubstituteNewClass in class PrinterAdapternewClassElement - the new class expressionpublic boolean substituteIdentifier(IdentifierElement identifierElement)
PrinterAdaptersubstituteIdentifier in class PrinterAdapteridentifierElement - the identifier being printedpublic Set<String> getErasedTypes()
getErasedTypes in class PrinterAdapterprotected void printForEachLoop(com.sun.tools.javac.tree.JCTree.JCEnhancedForLoop loop,
String indexVarName)
public boolean substituteForEachLoop(ForeachLoopElement foreachLoop, boolean targetHasLength, String indexVarName)
PrinterAdaptersubstituteForEachLoop in class PrinterAdapterforeachLoop - the foreach loop to printtargetHasLength - true if the iterable defines a public length fieldindexVarName - a possible (fresh) variable name that can used to iterate