Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly mark vararg parameters in TypescriptDefinition #2239

Merged
merged 3 commits into from
Mar 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/net/sourceforge/kolmafia/textui/TypescriptDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.sourceforge.kolmafia.textui.parsetree.LibraryFunction;
import net.sourceforge.kolmafia.textui.parsetree.RecordType;
import net.sourceforge.kolmafia.textui.parsetree.Type;
import net.sourceforge.kolmafia.textui.parsetree.VarArgType;
import net.sourceforge.kolmafia.textui.parsetree.VariableReference;
import net.sourceforge.kolmafia.utilities.StringUtilities;

Expand Down Expand Up @@ -85,6 +86,13 @@ public class TypescriptDefinition {
DataTypes.SLOT_TYPE,
DataTypes.THRALL_TYPE);

private static List<Boolean> getVariadicParams(Function f) {
return f.getVariableReferences().stream()
.map(VariableReference::getRawType)
.map(type -> type instanceof VarArgType)
.collect(Collectors.toList());
}

private static List<String> getParamTypes(Function f) {
var paramTypes =
f.getVariableReferences().stream()
Expand Down Expand Up @@ -128,10 +136,15 @@ public static String formatFunction(LibraryFunction f) {
var paramTypes = getParamTypes(f);
var overrideKey = String.format("%s[%s]", name, String.join(",", paramTypes));
var paramNames = descriptiveParamNames.getOrDefault(overrideKey, f.getParameterNames());
var variadicParams = getVariadicParams(f);

var params =
IntStream.range(0, paramNames.size())
.mapToObj(i -> String.format("%s: %s", paramNames.get(i), paramTypes.get(i)))
.mapToObj(
i ->
variadicParams.get(i)
? String.format("...%s: %s", paramNames.get(i), paramTypes.get(i))
: String.format("%s: %s", paramNames.get(i), paramTypes.get(i)))
.collect(Collectors.joining(", "));

var deprecationWarning =
Expand Down