Skip to content

Commit

Permalink
add workaround for kotlin
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Scherzinger <[email protected]>
  • Loading branch information
dlwetteronline authored and AndyScherzinger committed Jul 22, 2024
1 parent 199aafd commit 75e7f17
Showing 1 changed file with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public NextcloudRetrofitServiceMethod(String apiEndpoint, @NonNull Method method
this.method = method;
this.returnType = method.getGenericReturnType();
Annotation[] methodAnnotations = method.getAnnotations();
this.parameterAnnotationsArray = method.getParameterAnnotations();
this.parameterAnnotationsArray = filterParameterAnnotations(method.getParameterAnnotations());

for (Annotation annotation : methodAnnotations) {
parseMethodAnnotation(annotation);
Expand All @@ -115,8 +115,26 @@ public NextcloudRetrofitServiceMethod(String apiEndpoint, @NonNull Method method

}

/**
* filter out empty parameter annotations (e.g. when using kotlin)
* @param annotations
* @return
*/
private Annotation[][] filterParameterAnnotations(Annotation[][] annotations) {
List<Annotation[]> res = new ArrayList<>();

for(Annotation[] annotation : annotations) {
if(annotation.length > 0) {
res.add(annotation);
}
}

return res.toArray(new Annotation[res.size()][]);
}

public T invoke(NextcloudAPI nextcloudAPI, Object[] args) throws Exception {
if(parameterAnnotationsArray.length != args.length) {
//if(parameterAnnotationsArray.length != args.length) {
if(args.length < parameterAnnotationsArray.length) { // Ignore if too many parameters are given (e.g. when using kotlin)
throw new InvalidParameterException("Expected: " + parameterAnnotationsArray.length + " params - were: " + args.length);
}

Expand Down

0 comments on commit 75e7f17

Please sign in to comment.