Skip to content

Commit

Permalink
fix PropertyGraph create
Browse files Browse the repository at this point in the history
  • Loading branch information
eitanliu committed Jul 18, 2023
1 parent f0c97fe commit 9ef38ca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ inline fun <V> KMutableProperty0<V>.toGraphProperty(
}
}

fun createPropertyGraph() = PropertyGraph::class.java.createInstance {
fun createPropertyGraph() = PropertyGraph::class.java.createInstance({ sequence ->
sequence.sortedByDescending { it.parameterCount }
.first { it.parameterCount <= 2 }
}) {
when (it.parameterCount) {
2 -> arrayOf(null, true)
else -> null
Expand All @@ -38,11 +41,11 @@ fun createPropertyGraph() = PropertyGraph::class.java.createInstance {

@Suppress("UNCHECKED_CAST")
fun <T> Class<T>.createInstance(
predicate: ((Constructor<*>) -> Boolean)? = null,
predicate: ((sequence: Sequence<Constructor<*>>) -> Constructor<*>?)? = null,
params: ((Constructor<*>) -> Array<*>?)? = null,
): T = run {
val constructor = constructors.asSequence()
.first(predicate ?: { true })
val sequence = constructors.asSequence()
val constructor = predicate?.invoke(sequence) ?: sequence.first()
val args = params?.invoke(constructor) ?: arrayOfNulls<Any?>(constructors[0].parameterCount)
constructor.newInstance(*args) as T
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

<application-components>
<!--<component>-->
<!-- <implementation-class>com.eitanliu.dart_mappable.settings.Settings</implementation-class>-->
<!-- <implementation-class>com.eitanliu.dart.mappable.settings.Settings</implementation-class>-->
<!--</component>-->
</application-components>

Expand Down

0 comments on commit 9ef38ca

Please sign in to comment.