Skip to content

Commit

Permalink
chore: Add extension for finding VssProperties easily
Browse files Browse the repository at this point in the history
  • Loading branch information
Chrylo committed Oct 20, 2023
1 parent 43386e5 commit 37e70c7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ android.defaults.buildfeatures.buildconfig=true
android.enableJetifier=true
android.nonFinalResIds=false
android.nonTransitiveRClass=false

android.useAndroidX=true

kotlin.code.style=official

org.gradle.jvmargs=-Xmx2048m

# When using compose + ksp the incremental compiler should be disabled: https://issuetracker.google.com/issues/207185051
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,32 @@ private val classNamePrefix: String
get() = "Vss"

/**
* Creates an inheritance line to the given heir. Similar to [vssPathHeritageLine] but the other way around.
*
* @param heir where the inheritance line should stop
* @return a [Collection] of the full heritage line in the form of [VssSpecification]
* Creates an inheritance line to the given [heir]. Similar to [vssPathHeritageLine] but the other way around. It
* returns a [Collection] of the full heritage line in the form of [VssSpecification].
*/
fun VssSpecification.findHeritageLine(heir: VssSpecification): List<VssSpecification> {
fun VssSpecification.findHeritageLine(heir: VssSpecification): Collection<VssSpecification> {
val specificationKeys = heir.vssPathHeritageLine
return heritage.filter { child ->
specificationKeys.contains(child.vssPath)
}
}

/**
* Finds the given [property] inside the current [VssSpecification].
*/
fun <T : VssProperty<V>, V : Any> VssSpecification.findProperty(property: VssProperty<V>): VssProperty<V> {
return heritage
.filterIsInstance<VssProperty<V>>()
.first { it.uuid == property.uuid }
}

/**
* Finds all [VssProperty] which matches the given [KClass.simpleName]. This is useful when multiple nested objects
* with the same Name exists but are pretty much the same besides the [VssSpecification.vssPath] etc.
*/
fun <T : VssProperty<V>, V : Any> VssSpecification.findProperties(type: KClass<T>): Map<String, VssProperty<V>> {
return heritage
.filterIsInstance<VssProperty<V>>()
.filter { it::class.simpleName == type.simpleName }
.associateBy { it.vssPath }
}

0 comments on commit 37e70c7

Please sign in to comment.