diff --git a/app/build/generated/source/kapt/debug/rxhttp/wrapper/param/RxHttp.java b/app/build/generated/source/kapt/debug/rxhttp/wrapper/param/RxHttp.java index c1f408d8..4f98c20f 100644 --- a/app/build/generated/source/kapt/debug/rxhttp/wrapper/param/RxHttp.java +++ b/app/build/generated/source/kapt/debug/rxhttp/wrapper/param/RxHttp.java @@ -562,12 +562,15 @@ public R setSimpleClient() { * 给Param设置默认域名(如果缺席的话),此方法会在请求发起前,被RxHttp内部调用 */ private void addDefaultDomainIfAbsent() { - String newUrl = addDomainIfAbsent(param.getSimpleUrl(), Url.baseUrl); - param.setUrl(newUrl); + setDomainIfAbsent(Url.baseUrl); } public R setDomainToUpdateIfAbsent() { - String newUrl = addDomainIfAbsent(param.getSimpleUrl(), Url.update); + return setDomainIfAbsent(Url.update); + } + + public R setDomainIfAbsent(String domain) { + String newUrl = addDomainIfAbsent(param.getSimpleUrl(), domain); param.setUrl(newUrl); return (R) this; } diff --git a/rxhttp-compiler/src/main/java/com/rxhttp/compiler/DefaultDomainVisitor.kt b/rxhttp-compiler/src/main/java/com/rxhttp/compiler/DefaultDomainVisitor.kt index 785b6ffc..f5da1c42 100644 --- a/rxhttp-compiler/src/main/java/com/rxhttp/compiler/DefaultDomainVisitor.kt +++ b/rxhttp-compiler/src/main/java/com/rxhttp/compiler/DefaultDomainVisitor.kt @@ -36,10 +36,7 @@ class DefaultDomainVisitor { .addModifiers(Modifier.PRIVATE) element?.apply { methodBuilder.addCode( - """ - String newUrl = addDomainIfAbsent(param.getSimpleUrl(), ${"$"}T.${simpleName}); - param.setUrl(newUrl); - """.trimIndent(), + """setDomainIfAbsent(${"$"}T.${simpleName});""", ClassName.get(enclosingElement.asType()) ) } diff --git a/rxhttp-compiler/src/main/java/com/rxhttp/compiler/DomainVisitor.kt b/rxhttp-compiler/src/main/java/com/rxhttp/compiler/DomainVisitor.kt index 8b26999f..9a0323b4 100755 --- a/rxhttp-compiler/src/main/java/com/rxhttp/compiler/DomainVisitor.kt +++ b/rxhttp-compiler/src/main/java/com/rxhttp/compiler/DomainVisitor.kt @@ -30,11 +30,7 @@ class DomainVisitor { MethodSpec.methodBuilder("setDomainTo${key}IfAbsent") .addModifiers(Modifier.PUBLIC) .addCode( - """ - String newUrl = addDomainIfAbsent(param.getSimpleUrl(), ${"$"}T.${value.simpleName}); - param.setUrl(newUrl); - return (R) this; - """.trimIndent(), + """return setDomainIfAbsent(${"$"}T.${value.simpleName});""", ClassName.get(value.enclosingElement.asType()), ) .returns(r).build() diff --git a/rxhttp-compiler/src/main/java/com/rxhttp/compiler/RxHttpGenerator.kt b/rxhttp-compiler/src/main/java/com/rxhttp/compiler/RxHttpGenerator.kt index 574a932c..23ecb839 100755 --- a/rxhttp-compiler/src/main/java/com/rxhttp/compiler/RxHttpGenerator.kt +++ b/rxhttp-compiler/src/main/java/com/rxhttp/compiler/RxHttpGenerator.kt @@ -864,6 +864,20 @@ class RxHttpGenerator { methodList.addAll(getMethodList()) } + methodList.add( + MethodSpec.methodBuilder("setDomainIfAbsent") + .addModifiers(Modifier.PUBLIC) + .addParameter(String::class.java, "domain") + .addCode( + """ + String newUrl = addDomainIfAbsent(param.getSimpleUrl(), domain); + param.setUrl(newUrl); + return (R) this; + """.trimIndent() + ) + .returns(r).build() + ) + //对url添加域名方法 methodList.add( MethodSpec.methodBuilder("addDomainIfAbsent") @@ -872,17 +886,17 @@ class RxHttpGenerator { .addParameter(String::class.java, "domain") .addCode( """ - if (url.startsWith("http")) return url; - if (url.startsWith("/")) { - if (domain.endsWith("/")) - return domain + url.substring(1); - else - return domain + url; - } else if (domain.endsWith("/")) { - return domain + url; - } else { - return domain + "/" + url; - } + if (url.startsWith("http")) return url; + if (url.startsWith("/")) { + if (domain.endsWith("/")) + return domain + url.substring(1); + else + return domain + url; + } else if (domain.endsWith("/")) { + return domain + url; + } else { + return domain + "/" + url; + } """.trimIndent() ) .returns(String::class.java).build()