Skip to content

Commit

Permalink
Ensure optics type with "data" modifier is a class (#3036)
Browse files Browse the repository at this point in the history
  • Loading branch information
deotimedev committed Apr 10, 2023
1 parent 58c37f9 commit b1ad7f7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package arrow.optics.plugin

import com.google.devtools.ksp.symbol.ClassKind
import com.google.devtools.ksp.symbol.KSClassDeclaration
import com.google.devtools.ksp.symbol.Modifier

Expand All @@ -9,8 +10,8 @@ val KSClassDeclaration.companionObject: KSClassDeclaration?
val KSClassDeclaration.isSealed
get() = modifiers.contains(Modifier.SEALED)

val KSClassDeclaration.isData
get() = modifiers.contains(Modifier.DATA)
val KSClassDeclaration.isDataClass
get() = classKind == ClassKind.CLASS && modifiers.contains(Modifier.DATA)

val KSClassDeclaration.isValue
get() = modifiers.contains(Modifier.VALUE)
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class OpticsProcessor(private val codegen: CodeGenerator, private val logger: KS

private fun processClass(klass: KSClassDeclaration) {
// check that it is sealed or data
if (!klass.isSealed && !klass.isData && !klass.isValue) {
if (!klass.isSealed && !klass.isDataClass && !klass.isValue) {
logger.error(klass.qualifiedNameOrSimpleName.otherClassTypeErrorMessage, klass)
return
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package arrow.optics.plugin.internals

import arrow.optics.plugin.isData
import arrow.optics.plugin.isDataClass
import arrow.optics.plugin.isSealed
import arrow.optics.plugin.isValue
import com.google.devtools.ksp.processing.KSPLogger
Expand Down Expand Up @@ -100,7 +100,7 @@ internal fun evalAnnotatedDataClass(
logger: KSPLogger
): List<Focus> =
when {
element.isData ->
element.isDataClass ->
element
.getConstructorTypesNames()
.zip(element.getConstructorParamNames(), Focus.Companion::invoke)
Expand All @@ -112,7 +112,7 @@ internal fun evalAnnotatedDataClass(

internal fun evalAnnotatedDslElement(element: KSClassDeclaration, logger: KSPLogger): Target =
when {
element.isData ->
element.isDataClass ->
DataClassDsl(
element
.getConstructorTypesNames()
Expand All @@ -133,7 +133,7 @@ internal fun evalAnnotatedIsoElement(
logger: KSPLogger
): List<Focus> =
when {
element.isData ->
element.isDataClass ->
element
.getConstructorTypesNames()
.zip(element.getConstructorParamNames(), Focus.Companion::invoke)
Expand Down

0 comments on commit b1ad7f7

Please sign in to comment.