Skip to content

Commit

Permalink
Merge pull request #77 from specs-feup/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
joaobispo authored Oct 15, 2024
2 parents 33a84ee + acc4bf2 commit 7892bb1
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,31 @@ private static JavaType getJavaType(String type, String paramName, Action action
return jType;
}

/**
* Processes the arguments. Processing includes:
*
* <p>
* - Arrays are converted to arrays of Objects, for compatibility with the JavaScript layer.
* </p>
*
* @param arguments
* @return
*/
public static List<Argument> convertParamArrayToObjArray(List<Argument> arguments) {
var newArgs = new ArrayList<Argument>(arguments.size());

for (var arg : arguments) {
if (arg.getClassType().isArray()) {
arg = arg.clone();
arg.getClassType().setName("Object");
}

newArgs.add(arg);
}

return newArgs;
}

/**
* Convert an action method to actionImpl,which will be the one the user should implement, and generate the action
* implementation that invokes this new actionImpl
Expand Down Expand Up @@ -726,6 +751,8 @@ public static Method generateActionImplMethod(Method original, Action action,
argStr = "NamedEnum.fromString(" + arg.getClassType().getName() + ".class, " + arg.getName()
+ ", \"parameter " + arg.getName() + "\")";
arg.setClassType(stringType);
} else if (arg.getClassType().isArray()) {
argStr = "pt.up.fe.specs.util.SpecsCollections.cast(" + arg.getName() + ", " + arg.getClassType().getName() + ".class)";
} else {
argStr = arg.getName();
}
Expand Down Expand Up @@ -765,6 +792,12 @@ public static Method generateActionImplMethod(Method original, Action action,
cloned.appendCodeln("(" + GenConstants.getClassName() + "(), \"" + actionName + "\", e);");
cloned.appendCodeln("}");
targetClass.addImport(ActionException.class);

// Adapts parameters after processing and code generation is done, to improve compatibility with
// calls from JavaScript
cloned.setArguments(convertParamArrayToObjArray(cloned.getParams()));


return cloned;

}
Expand Down

0 comments on commit 7892bb1

Please sign in to comment.