Minor: cleanup warnings in codebase-tests

This commit is contained in:
Nikolay Krasko
2023-03-15 11:19:38 +01:00
committed by Space Team
parent c1a1986344
commit 3eeb867f56
5 changed files with 34 additions and 29 deletions
+1
View File
@@ -2,6 +2,7 @@
<dictionary name="Nikolay.Krasko">
<words>
<w>accessors</w>
<w>codeowners</w>
<w>coroutines</w>
<w>crossinline</w>
<w>fqname</w>
@@ -17,7 +17,8 @@ class CodeConformanceTest : TestCase() {
companion object {
private val JAVA_FILE_PATTERN = Pattern.compile(".+\\.java")
private val SOURCES_FILE_PATTERN = Pattern.compile(".+\\.(java|kt|js)")
private const val MAX_STEPS_COUNT = 100
@Suppress("SpellCheckingInspection")
private val nonSourcesMatcher = FileMatcher(
File("."),
listOf(
@@ -74,6 +75,7 @@ class CodeConformanceTest : TestCase() {
)
)
@Suppress("SpellCheckingInspection")
private val COPYRIGHT_EXCLUDED_FILES_AND_DIRS_MATCHER = FileMatcher(
File("."),
listOf(
@@ -162,7 +164,7 @@ class CodeConformanceTest : TestCase() {
val atAuthorPattern = Pattern.compile("/\\*.+@author.+\\*/", Pattern.DOTALL)
val tests = listOf(
@Suppress("SpellCheckingInspection") val tests = listOf(
FileTestCase(
"%d source files contain @author javadoc tag.\nPlease remove them or exclude in this test:\n%s"
) { _, source ->
@@ -394,7 +396,7 @@ class CodeConformanceTest : TestCase() {
)
)
data class RepoOccurance(val repo: String, val file: File)
data class RepoOccurrence(val repo: String, val file: File)
data class RepoOccurrences(val repo: String, val files: Collection<File>)
val extensionsPattern = Pattern.compile(".+\\.(java|kt|gradle|kts|xml)(\\.\\w+)?")
@@ -405,12 +407,12 @@ class CodeConformanceTest : TestCase() {
}
if (checkers.isNotEmpty()) {
val occurrences = ArrayList<RepoOccurance>()
val occurrences = ArrayList<RepoOccurrence>()
file.useLines { lines ->
for (line in lines) {
for (checker in checkers) {
if (line.contains(checker.repo) && (checker.exclude == null || !line.contains(checker.exclude))) {
occurrences.add(RepoOccurance(checker.repo, file))
occurrences.add(RepoOccurrence(checker.repo, file))
}
}
}
@@ -17,7 +17,7 @@ import org.junit.Test
import java.io.File
class DepsVerificationMetadataTest {
class DependenciesVerificationMetadataTest {
@JacksonXmlRootElement(localName = "verification-metadata")
private data class VerificationMetadata(
@field:JacksonXmlElementWrapper(localName = "components")
@@ -27,7 +27,7 @@ class ReflectionCodeSanityTest : TestCase() {
}
private fun loadClass(name: String): Class<*> =
classLoader.loadClass("kotlin.reflect.jvm.internal.$name")
classLoader.loadClass("kotlin.reflect.jvm.internal.$name")
private fun collectClassesWithSupers(vararg names: String): Set<Class<*>> {
val result = linkedSetOf<Class<*>>()
@@ -47,41 +47,43 @@ class ReflectionCodeSanityTest : TestCase() {
fun testNoDelegatedPropertiesInKClassAndKProperties() {
val badMembers = linkedSetOf<Member>()
for (klass in collectClassesWithSupers(
"KClassImpl",
"KMutableProperty0Impl",
"KMutableProperty1Impl",
"KMutableProperty2Impl"
"KClassImpl",
"KMutableProperty0Impl",
"KMutableProperty1Impl",
"KMutableProperty2Impl"
)) {
badMembers.addAll(klass.declaredFields.filter { it.name.endsWith(JvmAbi.DELEGATED_PROPERTY_NAME_SUFFIX) })
badMembers.addAll(klass.declaredMethods.filter { it.name.endsWith(JvmAbi.DELEGATED_PROPERTY_NAME_SUFFIX) })
}
if (badMembers.isNotEmpty()) {
fail("The members listed below appear to be delegates for properties.\n" +
"It's highly not recommended to use property delegates in reflection.jvm because a KProperty instance\n" +
"is created for each delegated property and that makes the initialization sequence of reflection\n" +
"implementation classes unpredictable and leads to a deadlock or ExceptionInInitializerError.\n\n" +
"Please un-delegate the corresponding properties:\n\n" +
badMembers.joinToString("\n"))
fail(
"The members listed below appear to be delegates for properties.\n" +
"It's highly not recommended to use property delegates in reflection.jvm because a KProperty instance\n" +
"is created for each delegated property and that makes the initialization sequence of reflection\n" +
"implementation classes unpredictable and leads to a deadlock or ExceptionInInitializerError.\n\n" +
"Please un-delegate the corresponding properties:\n\n" +
badMembers.joinToString("\n")
)
}
}
fun testMaxAllowedFields() {
// The following classes are instantiated a lot in Kotlin applications and thus they should be optimized as best as possible.
// The following classes are instantiated a lot in Kotlin applications, and thus they should be optimized as good as possible.
// This test checks that these classes have not more fields than a predefined small number, which can usually be calculated as
// the number of constructor parameters (number of objects needed to initialize an instance) + 1 for 'data', the reflection cache.
val classesWithMaxAllowedFields = linkedMapOf(
"KClassImpl" to 2, // jClass, data
"KPackageImpl" to 3 // jClass, moduleName, data
"KClassImpl" to 2, // jClass, data
"KPackageImpl" to 3 // jClass, moduleName, data
)
val badClasses = linkedMapOf<Class<*>, Collection<Field>>()
for ((className, maxAllowedFields) in classesWithMaxAllowedFields) {
val klass = loadClass(className)
val fields = generateSequence(klass) { it.superclass }
.flatMap { it.declaredFields.asSequence() }
.filterNot { Modifier.isStatic(it.modifiers) }
.toList()
.flatMap { it.declaredFields.asSequence() }
.filterNot { Modifier.isStatic(it.modifiers) }
.toList()
if (fields.size > maxAllowedFields) {
badClasses[klass] = fields
}
@@ -89,11 +91,11 @@ class ReflectionCodeSanityTest : TestCase() {
if (badClasses.isNotEmpty()) {
fail("Some classes in reflection.jvm contain more fields than it is allowed. Please optimize storage in these classes:\n\n" +
badClasses.entries.joinToString("\n") { entry ->
val (klass, fields) = entry
"$klass has ${fields.size} fields but max allowed = ${classesWithMaxAllowedFields[klass.simpleName]}:\n" +
fields.joinToString("\n") { " $it" }
})
badClasses.entries.joinToString("\n") { entry ->
val (klass, fields) = entry
"$klass has ${fields.size} fields but max allowed = ${classesWithMaxAllowedFields[klass.simpleName]}:\n" +
fields.joinToString("\n") { " $it" }
})
}
}
}
@@ -120,7 +120,7 @@ class SpaceCodeOwnersTest : TestCase() {
// (line = 5, pattern = /some/),
// (line = 1, pattern = *)
// With input of parent = (line = 5, pattern = /some/) and path = /some/other
// we only search till our parent pattern line, as other rules has lower specifity
// we only search till our parent pattern line, as other rules are less specific
for (use in this) {
if (parentMatchLine != null && use.item.line < parentMatchLine) break
if (use.rule.isMatch(path, isDirectory)) {