Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(compiler): Use singleOrNull() to simplify code
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Nonnenmacher <[email protected]>
mnonnenmacher committed Aug 28, 2024
1 parent cd6e024 commit 94f8dfb
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions plugins/compiler/src/main/kotlin/PluginSpecFactory.kt
Original file line number Diff line number Diff line change
@@ -97,12 +97,10 @@ class PluginSpecFactory {
firstArgumentIsDescriptor && optionalSecondArgumentIsCalledConfig
}

require(constructors.size == 1) {
return requireNotNull(constructors.singleOrNull()) {
"Plugin class $pluginClass must have exactly one constructor with a PluginDescriptor and a config " +
"argument."
}

return constructors.first()
}

/**
@@ -114,12 +112,10 @@ class PluginSpecFactory {
"Config class $this must be a data class."
}

require(getConstructors().toList().size == 1) {
val constructor = requireNotNull(getConstructors().singleOrNull()) {
"Config class $this must have exactly one constructor."
}

val constructor = getConstructors().single()

return constructor.parameters.map { param ->
val paramType = param.type.resolve()
val paramTypeString = getQualifiedNameWithTypeArguments(paramType)

0 comments on commit 94f8dfb

Please sign in to comment.