Rasmus Larsen
11/22/2024, 12:30 PMhasPublicOrDefaultModifier
for this. But functions within an internal class will return hasPublicOrDefaultModifier=true.
Is there anything I can do to test this?
Code sample added in comments.Rasmus Larsen
11/22/2024, 1:08 PM.isPublicAccessable
, that would return false if the function is declared within an internal or private class.
Konsist
.scopeFromProduction()
.files
.filter { file ->
file.resideInPath("..data..")
}.declarations()
.stream()
.flatMap { declaration ->
when {
declaration is KoClassDeclaration && declaration.isTopLevel -> {
Stream.of(
DynamicTest.dynamicTest(
"${declaration.name} should be private or internal"
) {
declaration.assertTrue(
testName = "${declaration.name} should be private or internal"
) {
!it.hasPublicOrDefaultModifier
}
}
)
}
declaration is KoFunctionDeclaration && declaration.isTopLevel -> {
Stream.of(
DynamicTest.dynamicTest(
"${declaration.name} should be private or internal"
) {
declaration.assertTrue(
testName = "${declaration.name} should be private or internal "
) {
!it.hasPublicOrDefaultModifier
}
}
)
}
else -> null
}
}
PoisonedYouth
11/23/2024, 6:30 PMRasmus Larsen
11/23/2024, 6:31 PMPoisonedYouth
11/23/2024, 7:27 PM!declaration.parentClass.hasInternalModifier
Rasmus Larsen
11/25/2024, 8:39 AMPoisonedYouth
11/25/2024, 9:20 AMKoBaseDeclaration
to KoClassDeclaration
or KoFunctionDeclaration
so in the case of the classes you can easily write:
declaration is KoClassDeclaration && declaration.isTopLevel && !declaration.hasInternalModifier
Rasmus Larsen
11/25/2024, 9:33 AMKoBaseDeclaration
to KoClassDeclaration
or KoFunctionDeclaration
, check it's topLevel and than I assertTrue on !hasPublicOrDefaultModifier
?PoisonedYouth
11/25/2024, 9:35 AMhasPublicOrDefaultModifier
does not work for internal classes?Rasmus Larsen
11/25/2024, 9:42 AMhasPublicOrDefaultModifier
would give "wrong"/unexpected results.
So I guess that I was hoping for or requesting was a isPublicAccessable
function that took parentClass visibility into account, so that functions within a internal or private class would return false for isPublicAccessable
instead of hasPublicOrDefaultModifier
that would return true when inside a private or internal class.PoisonedYouth
11/25/2024, 9:46 AMRasmus Larsen
11/25/2024, 9:56 AM