Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
liujingxing committed Oct 26, 2021
2 parents b1383d6 + eace6a5 commit db65175
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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()
Expand Down

0 comments on commit db65175

Please sign in to comment.