Skip to content

Commit

Permalink
Update json check logic and remove getText method
Browse files Browse the repository at this point in the history
  • Loading branch information
Sinan Kozak committed Oct 9, 2020
1 parent f855193 commit 5c79732
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,11 @@ internal class NetworkLayerClassJsonDetector : RetrofitReturnTypeDetector() {
}

private fun hasJsonNameAnnotation(field: UField): Boolean {
return try {
field.text.contains("@Json")
} catch (ignored: Throwable) {
context
.evaluator
.getAllAnnotations(field as UAnnotated, true)
.mapNotNull { uAnnotation -> uAnnotation.qualifiedName }
.any { it.endsWith("Json") }
}
return context
.evaluator
.getAllAnnotations(field as UAnnotated, true)
.mapNotNull { uAnnotation -> uAnnotation.qualifiedName }
.any { it.endsWith("Json") }
}

private fun hasJsonClassAnnotation(clazz: PsiClass): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,22 @@ internal class NetworkLayerClassJsonDetectorTest {
import com.squareup.moshi.JsonClass
@JsonClass(generateAdapter = true)
data class Dto(
internal data class Dto(
@Json(name = "inner") val inners: List<InnerDto>
) {
@JsonClass(generateAdapter = true)
data class InnerDto(
@Json(name = "type") val type: PremiumType
)
""".trimIndent()
),
kotlin(
"""
package foo
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
) {
enum class PremiumType {
enum class PremiumType {
@Json(name = "SCHUFA") SCHUFA,
ARVATO;
@Json(name = "SCHUFA")
SCHUFA,
ARVATO
}
}
}
""".trimIndent()
)
Expand All @@ -127,11 +127,7 @@ internal class NetworkLayerClassJsonDetectorTest {
.run()
.expect(
"""
src/foo/Api.kt:8: Information: Return type doesn't have @JsonClass annotation for [KtLightClassImpl:enum class PremiumType {
@Json(name = "SCHUFA") SCHUFA,
ARVATO;
}] classes. [NetworkLayerClassJsonClassRule]
src/foo/Api.kt:8: Information: Return type doesn't have @JsonClass annotation for [PsiClass:PremiumType] classes. [NetworkLayerClassJsonClassRule]
fun get(): Dto
~~~
src/foo/Api.kt:8: Information: Return type doesn't have @Json annotation for [ARVATO] fields. [NetworkLayerClassJsonRule]
Expand Down

0 comments on commit 5c79732

Please sign in to comment.