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

Impossible to use @ShowkaseColor or @ShowkaseTypography on objects' fields that have a constructor with no parameters #375

Open
francescocervone opened this issue Feb 21, 2024 · 0 comments

Comments

@francescocervone
Copy link

I see from the validator that the enclosing class must have exactly one constructor with no parameters here.

Couldn't this be relaxed to have at least one constructor with no parameters?

I mean, could that function be converted to something like this?

fun validateEnclosingClass(enclosingClass: XTypeElement?) {
  if (enclosingClass == null) return

  val hasEmptyConstructor = enclosingClass.getConstructors().any { constructor -> constructor.parameters.isEmpty() }
  if (!hasEmptyConstructor) {
    throw ShowkaseProcessorException(
      "Only classes that have at least one constructor with no parameters can " +
        "hold a @Composable function that's annotated with the " +
        "@${ShowkaseComposable::class.java.simpleName}/@Preview annotation",
      enclosingClass,
    )
  }
}
@francescocervone francescocervone changed the title Impossible to use @ShowkaseColor or @ShowkaseTypography on objects' fields that have a constructor with no parameters Impossible to use @ShowkaseColor or @ShowkaseTypography on objects' fields that have a constructor with no parameters Feb 21, 2024
@francescocervone francescocervone changed the title Impossible to use @ShowkaseColor or @ShowkaseTypography on objects' fields that have a constructor with no parameters Impossible to use @ShowkaseColor or @ShowkaseTypography on objects' fields that have a constructor with no parameters Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant