From 875221dc7a97ee4fac270c98ffd5699f18dfa3ab Mon Sep 17 00:00:00 2001 From: David Luhmer Date: Mon, 2 Mar 2020 18:23:27 +0100 Subject: [PATCH 1/2] add workaround for kotlin Signed-off-by: Andy Scherzinger --- .../api/NextcloudRetrofitServiceMethod.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/nextcloud/android/sso/api/NextcloudRetrofitServiceMethod.java b/lib/src/main/java/com/nextcloud/android/sso/api/NextcloudRetrofitServiceMethod.java index 81770eb7..5e4d8ea5 100644 --- a/lib/src/main/java/com/nextcloud/android/sso/api/NextcloudRetrofitServiceMethod.java +++ b/lib/src/main/java/com/nextcloud/android/sso/api/NextcloudRetrofitServiceMethod.java @@ -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); @@ -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 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); } From 3a7b87c63349585d30ae7a59f60bc9e990e78ba4 Mon Sep 17 00:00:00 2001 From: David Luhmer Date: Mon, 16 Mar 2020 17:53:56 +0100 Subject: [PATCH 2/2] add comments on kotlin coroutines Signed-off-by: Andy Scherzinger --- .../android/sso/api/NextcloudRetrofitServiceMethod.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/src/main/java/com/nextcloud/android/sso/api/NextcloudRetrofitServiceMethod.java b/lib/src/main/java/com/nextcloud/android/sso/api/NextcloudRetrofitServiceMethod.java index 5e4d8ea5..1d822dd9 100644 --- a/lib/src/main/java/com/nextcloud/android/sso/api/NextcloudRetrofitServiceMethod.java +++ b/lib/src/main/java/com/nextcloud/android/sso/api/NextcloudRetrofitServiceMethod.java @@ -116,7 +116,9 @@ public NextcloudRetrofitServiceMethod(String apiEndpoint, @NonNull Method method } /** - * filter out empty parameter annotations (e.g. when using kotlin) + * filter out empty parameter annotations (e.g. when using coroutines in kotlin (suspend functions)) + * For functions that are suspendable, the Continuation parameter will be added on the JVM side. + * https://blog.kotlin-academy.com/a-little-reflection-about-coroutines-34050cbc4fe6 * @param annotations * @return */