Skip to content

Conversation

rnett
Copy link
Contributor

@rnett rnett commented Oct 10, 2025

Fixes KT-81448, adding wildcard support using regexes.

@rnett rnett requested review from a team, bnorm and broadwaylamb as code owners October 10, 2025 00:50
@rnett rnett requested review from Tapchicoma and mcpiroman October 10, 2025 00:50
Copy link
Member

@bnorm bnorm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. A departure from the glob style mentioned in the ticket, but I'm not strongly opposed to this, personally at least. I'd want some input from the Kotlin Build Tools team (@Tapchicoma) on if this conflicts with any of their design goals, though.

val project = kotlinCompilation.target.project
val extension = project.extensions.getByType(PowerAssertGradleExtension::class.java)
return extension.functions.map { functions ->
return extension.functions.zip(extension.functionRegexes) { functions, patterns ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This confused me for so long because I thought this was zipping the sets together, rather than zipping the properties together. 😆

Maybe each property could be mapped individually and then zipped at the end? Probably less confusing but also less efficient. Though maybe efficiency isn't super important here? Or maybe there's another way to make it more clear and equally efficient?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pulled out the element mapping to local variables and then ziped at the end. I think it's a bit clearer.

Comment on lines +48 to +49
// Java's Pattern is used here instead of Kotlin's Regex for Groovy compatability
val functionRegexes: SetProperty<Pattern> = objectFactory.setProperty(Pattern::class.java).convention(setOf())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... I think it might just be better to make this a Set of Strings. Pattern might logically be correct, but also seems a little too specific. Maybe @Tapchicoma has more specific thoughts here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see why you might want to use Stirng. There's two primary reasons I went with pattern:

  • you get the nice Regex syntax highlighting in Pattern.compile("...") (IntelliJ's language annotation can't be applied to types, and applying it to the property doesn't work). This is particularly useful when escaping .s in package names.
  • so that regex flags can be set.

Comment on lines +57 to +59
val flags = value.substringBefore(':', "").toIntOrNull() ?: 0
val pattern = value.substringAfter(':')
configuration.add(KEY_FUNCTION_REGEXES, Pattern.compile(pattern, flags).toRegex())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This flags part is interesting but may expose too many implementation details. Ties in with the comment about not using Pattern as the Gradle property, but rather just a String. Is there a reason to expose this functionality or just a side-effect of using Pattern?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was mostly because we're using pattern on both ends anyways, and this is necessary to get an equal pattern on the other end. But looking over the flags, there aren't any that I think would be useful here, so I'm not opposed to dropping it.

@rnett rnett requested a review from bnorm October 11, 2025 18:57
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

Successfully merging this pull request may close these issues.

2 participants