From 8b3d2461a2610c655b1e57e68ef72630bfad61e0 Mon Sep 17 00:00:00 2001 From: liujingxing <18268800083ljx@gmail.com> Date: Thu, 29 Jun 2023 16:23:57 +0800 Subject: [PATCH] fix #443 add setQuery/setEncodedQuery/removeAllQuery funs --- .../kotlin/rxhttp/wrapper/param/RxHttp.kt | 15 +++++++ .../rxhttp/compiler/kapt/RxHttpGenerator.kt | 33 ++++++++++++++- .../rxhttp/compiler/ksp/RxHttpGenerator.kt | 26 ++++++++++++ .../wrapper/param/AbstractBodyParam.java | 3 +- .../rxhttp/wrapper/param/AbstractParam.java | 41 +++++++++++++------ .../java/rxhttp/wrapper/param/IParam.java | 12 ++++++ 6 files changed, 114 insertions(+), 16 deletions(-) diff --git a/app/build/generated/ksp/debug/kotlin/rxhttp/wrapper/param/RxHttp.kt b/app/build/generated/ksp/debug/kotlin/rxhttp/wrapper/param/RxHttp.kt index 35c752ec..b0836d7f 100644 --- a/app/build/generated/ksp/debug/kotlin/rxhttp/wrapper/param/RxHttp.kt +++ b/app/build/generated/ksp/debug/kotlin/rxhttp/wrapper/param/RxHttp.kt @@ -160,6 +160,21 @@ public open class RxHttp
, R : RxHttp
> protected constructor( return self() } + public fun setQuery(key: String, `value`: Any?): R { + param.setQuery(key, value) + return self() + } + + public fun setEncodedQuery(key: String, `value`: Any?): R { + param.setEncodedQuery(key, value) + return self() + } + + public fun removeAllQuery(key: String): R { + param.removeAllQuery(key) + return self() + } + public fun addQuery(key: String): R { param.addQuery(key, null) return self() diff --git a/rxhttp-compiler/src/main/java/com/rxhttp/compiler/kapt/RxHttpGenerator.kt b/rxhttp-compiler/src/main/java/com/rxhttp/compiler/kapt/RxHttpGenerator.kt index 11dc0fca..09262264 100755 --- a/rxhttp-compiler/src/main/java/com/rxhttp/compiler/kapt/RxHttpGenerator.kt +++ b/rxhttp-compiler/src/main/java/com/rxhttp/compiler/kapt/RxHttpGenerator.kt @@ -219,6 +219,35 @@ class RxHttpGenerator { .build() .apply { methodList.add(this) } + MethodSpec.methodBuilder("setQuery") + .addModifiers(Modifier.PUBLIC) + .addParameter(string, "key") + .addParameter(TypeName.OBJECT, "value") + .addStatement("param.setQuery(key, value)") + .addStatement("return self()") + .returns(typeVariableR) + .build() + .apply { methodList.add(this) } + + MethodSpec.methodBuilder("setEncodedQuery") + .addModifiers(Modifier.PUBLIC) + .addParameter(string, "key") + .addParameter(TypeName.OBJECT, "value") + .addStatement("param.setEncodedQuery(key, value)") + .addStatement("return self()") + .returns(typeVariableR) + .build() + .apply { methodList.add(this) } + + MethodSpec.methodBuilder("removeAllQuery") + .addModifiers(Modifier.PUBLIC) + .addParameter(string, "key") + .addStatement("param.removeAllQuery(key)") + .addStatement("return self()") + .returns(typeVariableR) + .build() + .apply { methodList.add(this) } + MethodSpec.methodBuilder("addQuery") .addModifiers(Modifier.PUBLIC) .addParameter(string, "key") @@ -241,7 +270,7 @@ class RxHttpGenerator { .addModifiers(Modifier.PUBLIC) .addParameter(string, "key") .addParameter(TypeName.OBJECT, "value") - .addStatement("param.addQuery(key,value)") + .addStatement("param.addQuery(key, value)") .addStatement("return self()") .returns(typeVariableR) .build() @@ -251,7 +280,7 @@ class RxHttpGenerator { .addModifiers(Modifier.PUBLIC) .addParameter(string, "key") .addParameter(TypeName.OBJECT, "value") - .addStatement("param.addEncodedQuery(key,value)") + .addStatement("param.addEncodedQuery(key, value)") .addStatement("return self()") .returns(typeVariableR) .build() diff --git a/rxhttp-compiler/src/main/java/com/rxhttp/compiler/ksp/RxHttpGenerator.kt b/rxhttp-compiler/src/main/java/com/rxhttp/compiler/ksp/RxHttpGenerator.kt index b1f3da4f..00477947 100755 --- a/rxhttp-compiler/src/main/java/com/rxhttp/compiler/ksp/RxHttpGenerator.kt +++ b/rxhttp-compiler/src/main/java/com/rxhttp/compiler/ksp/RxHttpGenerator.kt @@ -366,6 +366,32 @@ class RxHttpGenerator( .build() .let { methodList.add(it) } + FunSpec.builder("setQuery") + .addParameter("key", STRING) + .addParameter("value", ANY, true) + .addStatement("param.setQuery(key, value)") + .addStatement("return self()") + .returns(typeVariableR) + .build() + .let { methodList.add(it) } + + FunSpec.builder("setEncodedQuery") + .addParameter("key", STRING) + .addParameter("value", ANY, true) + .addStatement("param.setEncodedQuery(key, value)") + .addStatement("return self()") + .returns(typeVariableR) + .build() + .let { methodList.add(it) } + + FunSpec.builder("removeAllQuery") + .addParameter("key", STRING) + .addStatement("param.removeAllQuery(key)") + .addStatement("return self()") + .returns(typeVariableR) + .build() + .let { methodList.add(it) } + FunSpec.builder("addQuery") .addParameter("key", STRING) .addStatement("param.addQuery(key, null)") diff --git a/rxhttp/src/main/java/rxhttp/wrapper/param/AbstractBodyParam.java b/rxhttp/src/main/java/rxhttp/wrapper/param/AbstractBodyParam.java index 67560155..fed268d8 100644 --- a/rxhttp/src/main/java/rxhttp/wrapper/param/AbstractBodyParam.java +++ b/rxhttp/src/main/java/rxhttp/wrapper/param/AbstractBodyParam.java @@ -29,9 +29,8 @@ public final RequestBody buildRequestBody() { return callback != null ? new ProgressRequestBody(requestBody, callback) : requestBody; } - @SuppressWarnings("unchecked") public final P setProgressCallback(ProgressCallback callback) { this.callback = callback; - return (P) this; + return self(); } } diff --git a/rxhttp/src/main/java/rxhttp/wrapper/param/AbstractParam.java b/rxhttp/src/main/java/rxhttp/wrapper/param/AbstractParam.java index 1b4aa02c..b99287e6 100644 --- a/rxhttp/src/main/java/rxhttp/wrapper/param/AbstractParam.java +++ b/rxhttp/src/main/java/rxhttp/wrapper/param/AbstractParam.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.Objects; @@ -28,7 +29,6 @@ * Date: 2019/1/19 * Time: 14:35 */ -@SuppressWarnings("unchecked") public abstract class AbstractParam
> extends Param
{
private String url; //链接地址
@@ -53,7 +53,7 @@ public AbstractParam(@NotNull String url, Method method) {
public P setUrl(@NotNull String url) {
this.url = url;
- return (P) this;
+ return self();
}
@Override
@@ -69,7 +69,7 @@ public P addEncodedPath(String name, Object value) {
private P addPath(KeyValuePair keyValuePair) {
if (paths == null) paths = new ArrayList<>();
paths.add(keyValuePair);
- return (P) this;
+ return self();
}
@Override
@@ -85,7 +85,7 @@ public P addEncodedQuery(String key, @Nullable Object value) {
private P addQuery(KeyValuePair keyValuePair) {
if (queryParam == null) queryParam = new ArrayList<>();
queryParam.add(keyValuePair);
- return (P) this;
+ return self();
}
@Nullable
@@ -133,25 +133,25 @@ public final Builder getHeadersBuilder() {
@Override
public P setHeadersBuilder(Builder builder) {
HBuilder = builder;
- return (P) this;
+ return self();
}
@Override
public P cacheControl(CacheControl cacheControl) {
requestBuilder.cacheControl(cacheControl);
- return (P) this;
+ return self();
}
@Override
public