mirror of
https://github.com/cincheo/jsweet.git
synced 2025-12-15 07:19:22 +00:00
add a method to substitute some new array expression
This commit is contained in:
parent
5da32198e0
commit
dc444a7396
@ -81,6 +81,7 @@ import org.jsweet.transpiler.model.support.ExtendedElementSupport;
|
||||
import org.jsweet.transpiler.model.support.ForeachLoopElementSupport;
|
||||
import org.jsweet.transpiler.model.support.ImportElementSupport;
|
||||
import org.jsweet.transpiler.model.support.MethodInvocationElementSupport;
|
||||
import org.jsweet.transpiler.model.support.NewArrayElementSupport;
|
||||
import org.jsweet.transpiler.model.support.NewClassElementSupport;
|
||||
import org.jsweet.transpiler.model.support.UnaryOperatorElementSupport;
|
||||
import org.jsweet.transpiler.util.AbstractTreePrinter;
|
||||
@ -5563,9 +5564,11 @@ public class Java2TypeScriptTranslator extends AbstractTreePrinter {
|
||||
}
|
||||
print("]");
|
||||
} else {
|
||||
if (!getAdapter().substituteNewArrayWithVariableLength(new NewArrayElementSupport(newArray))) {
|
||||
print("(s => { let a=[]; while(s-->0) a.push(" + Util.getTypeInitialValue(newArray.elemtype.type)
|
||||
+ "); return a; })(").print(newArray.dims.head).print(")");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
print("<any> (function(dims) { " + VAR_DECL_KEYWORD
|
||||
+ " allocate = function(dims) { if (dims.length === 0) { return "
|
||||
|
||||
@ -57,6 +57,7 @@ import org.jsweet.transpiler.model.ForeachLoopElement;
|
||||
import org.jsweet.transpiler.model.IdentifierElement;
|
||||
import org.jsweet.transpiler.model.ImportElement;
|
||||
import org.jsweet.transpiler.model.MethodInvocationElement;
|
||||
import org.jsweet.transpiler.model.NewArrayElement;
|
||||
import org.jsweet.transpiler.model.NewClassElement;
|
||||
import org.jsweet.transpiler.model.TypeCastElement;
|
||||
import org.jsweet.transpiler.model.UnaryOperatorElement;
|
||||
@ -901,6 +902,17 @@ public class PrinterAdapter {
|
||||
return parentAdapter == null ? false : parentAdapter.substituteMethodInvocation(invocation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Substitutes <em>new array</em> expressions, which length are initialized with a variable.
|
||||
*
|
||||
* @param newArray
|
||||
* the new array being printed
|
||||
* @return true if substituted
|
||||
*/
|
||||
public boolean substituteNewArrayWithVariableLength(NewArrayElement newArray) {
|
||||
return parentAdapter == null ? false : parentAdapter.substituteNewArrayWithVariableLength(newArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Substitutes a given type declaration.
|
||||
*
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user