Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure optics type with "data" modifier is a class #3036

Merged
merged 1 commit into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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