substitution function for switch statement selectors

This commit is contained in:
Renaud Pawlak 2020-07-09 17:54:38 +02:00
parent 3b732fc9fc
commit 6c75ac877b
2 changed files with 14 additions and 4 deletions

View File

@ -5384,10 +5384,13 @@ public class Java2TypeScriptTranslator extends AbstractTreePrinter {
@Override
public void visitSwitch(JCSwitch switchStatement) {
print("switch(");
print(switchStatement.selector);
if (context.types.isSameType(context.symtab.charType,
context.types.unboxedTypeOrType(switchStatement.selector.type))) {
print(".charCodeAt(0)");
if (!getAdapter()
.substituteSwitchStatementSelector(ExtendedElementFactory.INSTANCE.create(switchStatement.selector))) {
print(switchStatement.selector);
if (context.types.isSameType(context.symtab.charType,
context.types.unboxedTypeOrType(switchStatement.selector.type))) {
print(".charCodeAt(0)");
}
}
print(") {").println();
for (JCCase caseStatement : switchStatement.cases) {

View File

@ -1069,6 +1069,13 @@ public class PrinterAdapter {
return parentAdapter == null ? false : parentAdapter.substituteCaseStatementPattern(caseStatement, pattern);
}
/**
* Substitutes if necessary the selector expression of a switch statement.
*/
public boolean substituteSwitchStatementSelector(ExtendedElement selector) {
return parentAdapter == null ? false : parentAdapter.substituteSwitchStatementSelector(selector);
}
/**
* This method is called after a type was printed.
*/