@@ -58,24 +58,32 @@ private fun checkConverterValidClass(element: VariableElement, types: Types) {
58
58
)
59
59
}
60
60
var classType = element.asType()
61
- if (" rxhttp.wrapper.callback.IConverter" != classType.toString()) {
62
- while (true ) {
63
- // TypeMirror转TypeElement
64
- val currentClass = types.asElement(classType) as TypeElement
65
- // 遍历实现的接口有没有IConverter接口
66
- for (mirror in currentClass.interfaces) {
67
- if (mirror.toString() == " rxhttp.wrapper.callback.IConverter" ) {
68
- return
69
- }
70
- }
71
- // 未遍历到IConverter,则找到父类继续,一直循环下去,直到最顶层的父类
72
- classType = currentClass.superclass
73
- if (classType.kind == TypeKind .NONE ) {
74
- throw ProcessingException (
75
- element,
76
- " The variable ${element.simpleName} is not a IConverter"
77
- )
78
- }
61
+ val iConverter = " rxhttp.wrapper.callback.IConverter"
62
+ while (true ) {
63
+ if (iConverter == classType.toString()) return
64
+ // TypeMirror转TypeElement
65
+ val currentClass = types.asElement(classType) as TypeElement
66
+ // 遍历实现的接口有没有IConverter接口
67
+ if (currentClass.findIConverter(types, iConverter)) return
68
+ // 未遍历到IConverter,则找到父类继续,一直循环下去,直到最顶层的父类
69
+ classType = currentClass.superclass
70
+ if (classType.kind == TypeKind .NONE ) {
71
+ throw ProcessingException (
72
+ element,
73
+ " The variable ${element.simpleName} is not a IConverter"
74
+ )
75
+ }
76
+ }
77
+ }
78
+
79
+ fun TypeElement.findIConverter (types : Types , iConverter : String ): Boolean {
80
+ for (mirror in interfaces) {
81
+ return if (mirror.toString() == " rxhttp.wrapper.callback.IConverter" ) {
82
+ true
83
+ } else {
84
+ (types.asElement(mirror) as ? TypeElement )?.findIConverter(types, iConverter)
85
+ ? : return false
79
86
}
80
87
}
81
- }
88
+ return false
89
+ }
0 commit comments