Skip to content

Commit

Permalink
refactor(compiler): Use singleOrNull() to simplify code
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
  • Loading branch information
mnonnenmacher committed Aug 29, 2024
1 parent b82a5c1 commit b67936d
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
Expand Up @@ -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()
}

/**
Expand All @@ -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)
Expand Down

0 comments on commit b67936d

Please sign in to comment.