Skip to content

Commit

Permalink
recursive prop search
Browse files Browse the repository at this point in the history
  • Loading branch information
UtkonosCorp committed May 5, 2021
1 parent c90f2d9 commit 885fb60
Showing 1 changed file with 28 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,36 @@ abstract class ComponentClassBuilder(
) {

protected val propProperties = ArrayList<PropProperty>().apply {
val viewModelEnclosedElements =
(viewModelClass as DeclaredType).asElement().enclosedElements
viewModelEnclosedElements.forEach { viewModelElement ->
viewModelElement.getAnnotation(Prop::class.java)?.let { annotation ->
var propertyName = viewModelElement.toString().substringBefore('$')
if (propertyName.contains("get")) propertyName =
propertyName.replace("get", "").decapitalize(Locale.getDefault())
val capitalizedPropertyName = propertyName.substring(0, 1)
.toUpperCase(Locale.getDefault()) + propertyName.substring(1)
val propertyGetter = viewModelEnclosedElements.first {
it.toString() == "get$capitalizedPropertyName()"
|| it.toString() == "$propertyName()"
}
val propertyType = (propertyGetter as ExecutableElement).returnType
add(
PropProperty(
propertyName,
capitalizedPropertyName,
propertyType,
annotation.twoWay,
"${propertyName}AttrChanged"
var downwardViewModelClass = viewModelClass
while (downwardViewModelClass.toString() != "ru.impression.ui_generator_base.ComponentViewModel" && downwardViewModelClass.toString() != "ru.impression.ui_generator_base.CoroutineViewModel") {
val viewModelEnclosedElements =
(downwardViewModelClass as DeclaredType).asElement().enclosedElements

viewModelEnclosedElements.forEach { viewModelElement ->
viewModelElement.getAnnotation(Prop::class.java)?.let { annotation ->
var propertyName = viewModelElement.toString().substringBefore('$')
if (propertyName.contains("get")) propertyName =
propertyName.replace("get", "").decapitalize(Locale.getDefault())
val capitalizedPropertyName = propertyName.substring(0, 1)
.toUpperCase(Locale.getDefault()) + propertyName.substring(1)
val propertyGetter = viewModelEnclosedElements.first {
it.toString() == "get$capitalizedPropertyName()"
|| it.toString() == "$propertyName()"
}
val propertyType = (propertyGetter as ExecutableElement).returnType
add(
PropProperty(
propertyName,
capitalizedPropertyName,
propertyType,
annotation.twoWay,
"${propertyName}AttrChanged"
)
)
)
}
}

downwardViewModelClass = (downwardViewModelClass.asElement() as TypeElement).superclass
}
}

Expand Down

0 comments on commit 885fb60

Please sign in to comment.