Skip to content

Commit 0978ab5

Browse files
committed
简化${'$'}写法
1 parent 250729c commit 0978ab5

5 files changed

Lines changed: 29 additions & 28 deletions

File tree

rxhttp-compiler/src/main/java/com/rxhttp/compiler/kapt/BaseRxHttpGenerator.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,11 @@ class BaseRxHttpGenerator(
159159
.addParameter(outputStreamFactory.parameterizedBy(t), "osFactory")
160160
.addParameter(Boolean::class.java, "append")
161161
.addCode(
162-
"""
162+
$$"""
163163
if (append) {
164164
tag(OutputStreamFactory.class, osFactory);
165165
}
166-
return toObservable(new ${'$'}T<>(osFactory));
166+
return toObservable(new $T<>(osFactory));
167167
""".trimIndent(), streamParser
168168
)
169169
.returns(observableCallT)
@@ -246,15 +246,15 @@ class BaseRxHttpGenerator(
246246

247247
if (isDependenceRxJava()) {
248248
val codeBlock = CodeBlock.of(
249-
"""
250-
${'$'}T<? super Throwable> errorHandler = ${'$'}T.getErrorHandler();
249+
$$"""
250+
$T<? super Throwable> errorHandler = $T.getErrorHandler();
251251
if (errorHandler == null) {
252252
/*
253253
RxJava的一个重要的设计理念是:不吃掉任何一个异常, 即抛出的异常无人处理,便会导致程序崩溃
254254
这就会导致一个问题,当RxJava“downStream”取消订阅后,“upStream”仍有可能抛出异常,
255255
这时由于已经取消订阅,“downStream”无法处理异常,此时的异常无人处理,便会导致程序崩溃
256256
*/
257-
RxJavaPlugins.setErrorHandler(${'$'}T::logRxJavaError);
257+
RxJavaPlugins.setErrorHandler($T::logRxJavaError);
258258
}
259259
260260
""".trimIndent(), consumer, rxJavaPlugins, logUtilName

rxhttp-compiler/src/main/java/com/rxhttp/compiler/kapt/DefaultDomainVisitor.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ class DefaultDomainVisitor(
4242
.addModifiers(Modifier.PRIVATE)
4343
element?.apply {
4444
val className = ClassName.get(enclosingElement.asType())
45-
methodBuilder.addCode("""
45+
methodBuilder.addCode(
46+
$$"""
4647
String originUrl = param.getSimpleUrl();
4748
if (originUrl.startsWith("http")) return;
48-
setDomainIfAbsent(${'$'}T.${simpleName});
49+
setDomainIfAbsent($T.$${simpleName});
4950
""".trimIndent(), className)
5051
}
5152
return methodBuilder.build()

rxhttp-compiler/src/main/java/com/rxhttp/compiler/kapt/ParserVisitor.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,11 @@ private fun TypeElement.getToObservableXxxFun(
141141
.varargs(varargs)
142142
.returns(parserClass)
143143
.addCode(
144-
"""
145-
Type actualType = ${'$'}T.getActualType($firstParamName);
146-
if (actualType == null) actualType = $firstParamName;
147-
${'$'}T parser = new ${'$'}T($paramNames);
148-
return actualType == $firstParamName ? parser : new ${'$'}T(parser);
144+
$$"""
145+
Type actualType = $T.getActualType($$firstParamName);
146+
if (actualType == null) actualType = $$firstParamName;
147+
$T parser = new $T($$paramNames);
148+
return actualType == $$firstParamName ? parser : new $T(parser);
149149
""".trimIndent(), typeUtil, customParser, customParser, okResponseParser
150150
).build().apply { methodList.add(this) }
151151
}

rxhttp-compiler/src/main/java/com/rxhttp/compiler/kapt/RxHttpGenerator.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -511,10 +511,10 @@ class RxHttpGenerator {
511511
.addParameter(TypeName.LONG, "endIndex")
512512
.addParameter(TypeName.BOOLEAN, "connectLastProgress")
513513
.addCode(
514-
"""
514+
$$"""
515515
param.setRangeHeader(startIndex, endIndex);
516516
if (connectLastProgress && startIndex >= 0)
517-
param.tag(DownloadOffSize.class, new ${'$'}T(startIndex));
517+
param.tag(DownloadOffSize.class, new $T(startIndex));
518518
return self();
519519
""".trimIndent(), downloadOffSizeName
520520
)
@@ -636,11 +636,11 @@ class RxHttpGenerator {
636636
.addParameter(typeParam)
637637
.addParameter(t, "tag")
638638
.addCode(
639-
"""
639+
$$"""
640640
param.tag(type, tag);
641-
if (type == ${'$'}T.class) {
641+
if (type == $T.class) {
642642
okClient = okClient.newBuilder()
643-
.addInterceptor(new ${'$'}T())
643+
.addInterceptor(new $T())
644644
.build();
645645
}
646646
return self();
@@ -726,34 +726,34 @@ class RxHttpGenerator {
726726
MethodSpec.methodBuilder("getOkHttpClient")
727727
.addModifiers(Modifier.PUBLIC)
728728
.addCode(
729-
"""
729+
$$"""
730730
if (realOkClient != null) return realOkClient;
731731
final OkHttpClient okClient = this.okClient;
732732
OkHttpClient.Builder builder = null;
733733
734-
if (${'$'}T.isDebug()) {
734+
if ($T.isDebug()) {
735735
builder = okClient.newBuilder();
736-
builder.addInterceptor(new ${'$'}T(okClient));
736+
builder.addInterceptor(new $T(okClient));
737737
}
738738
739739
if (connectTimeoutMillis != 0L) {
740740
if (builder == null) builder = okClient.newBuilder();
741-
builder.connectTimeout(connectTimeoutMillis, ${'$'}T.MILLISECONDS);
741+
builder.connectTimeout(connectTimeoutMillis, $T.MILLISECONDS);
742742
}
743743
744744
if (readTimeoutMillis != 0L) {
745745
if (builder == null) builder = okClient.newBuilder();
746-
builder.readTimeout(readTimeoutMillis, ${'$'}T.MILLISECONDS);
746+
builder.readTimeout(readTimeoutMillis, $T.MILLISECONDS);
747747
}
748748
749749
if (writeTimeoutMillis != 0L) {
750750
if (builder == null) builder = okClient.newBuilder();
751-
builder.writeTimeout(writeTimeoutMillis, ${'$'}T.MILLISECONDS);
751+
builder.writeTimeout(writeTimeoutMillis, $T.MILLISECONDS);
752752
}
753753
754754
if (param.getCacheMode() != CacheMode.ONLY_NETWORK) {
755755
if (builder == null) builder = okClient.newBuilder();
756-
builder.addInterceptor(new ${'$'}T(getCacheStrategy()));
756+
builder.addInterceptor(new $T(getCacheStrategy()));
757757
}
758758
759759
realOkClient = builder != null ? builder.build() : okClient;

rxhttp-compiler/src/main/java/com/rxhttp/compiler/ksp/RxHttpGenerator.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -810,17 +810,17 @@ class RxHttpGenerator(
810810
.addParameter("url", STRING)
811811
.addParameter("domain", STRING)
812812
.addCode(
813-
"""
813+
$$"""
814814
return
815815
if (url.startsWith("http")) {
816816
url
817817
} else if (url.startsWith("/")) {
818818
val finalUrl = if (domain.endsWith("/")) url.substring(1) else url
819-
"${'$'}domain${'$'}finalUrl"
819+
"$domain$finalUrl"
820820
} else if (domain.endsWith("/")) {
821-
"${'$'}domain${'$'}url"
821+
"$domain$url"
822822
} else {
823-
"${'$'}domain/${'$'}url"
823+
"$domain/$url"
824824
}
825825
""".trimIndent()
826826
)

0 commit comments

Comments
 (0)