mirror of
https://github.com/cincheo/jsweet.git
synced 2025-12-15 07:19:22 +00:00
substitution function for switch statement selectors
This commit is contained in:
parent
3b732fc9fc
commit
6c75ac877b
@ -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) {
|
||||
|
||||
@ -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.
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user