[light classes] optimize accessors retrieval

Avoid expensive calls to `navigationElement` for methods
that cannot be getters/setters and would be filtered later.
Repeat partly naming generation strategy.

Merge-request: KT-MR-10689
Merged-by: Anna Kozlova <Anna.Kozlova@jetbrains.com>
This commit is contained in:
Anna Kozlova
2023-06-22 14:14:39 +00:00
committed by Space Team
parent 7e9a897ef3
commit 190d49a1e0
14 changed files with 257 additions and 15 deletions
@@ -0,0 +1,5 @@
// EXPECTED: org.jetbrains.kotlin.light.classes.symbol.methods.SymbolLightAccessorMethod
// EXPECTED: org.jetbrains.kotlin.light.classes.symbol.fields.SymbolLightFieldForProperty
class Foo {
internal val <caret> p: Int = 42
}
@@ -0,0 +1,6 @@
// EXPECTED: org.jetbrains.kotlin.light.classes.symbol.methods.SymbolLightAccessorMethod
// EXPECTED: org.jetbrains.kotlin.light.classes.symbol.fields.SymbolLightFieldForProperty
class Foo {
@get:JvmName("getBar")
val <caret>p: Int = 42
}
@@ -0,0 +1,3 @@
// EXPECTED: org.jetbrains.kotlin.light.classes.symbol.methods.SymbolLightAccessorMethod
val p: Int = 42
g<caret>et
@@ -0,0 +1,4 @@
// EXPECTED: org.jetbrains.kotlin.light.classes.symbol.methods.SymbolLightAccessorMethod
val p: Int = 42
@JvmName("getBar")
g<caret>et
@@ -0,0 +1,4 @@
// EXPECTED: org.jetbrains.kotlin.light.classes.symbol.methods.SymbolLightAccessorMethod
@get:JvmName("getBar")
val p: Int = 42
g<caret>et
@@ -0,0 +1,3 @@
// EXPECTED: org.jetbrains.kotlin.light.classes.symbol.methods.SymbolLightAccessorMethod
val <caret>p: Int
get() = 42
@@ -0,0 +1,4 @@
// EXPECTED: org.jetbrains.kotlin.light.classes.symbol.methods.SymbolLightAccessorMethod
@get:JvmName("getBar")
val <caret>p: Int
get() = 42
@@ -0,0 +1,4 @@
// EXPECTED: org.jetbrains.kotlin.light.classes.symbol.methods.SymbolLightAccessorMethod
val <caret>p: Int
@JvmName("getBar")
get() = 42
@@ -0,0 +1,4 @@
// EXPECTED: org.jetbrains.kotlin.light.classes.symbol.methods.SymbolLightAccessorMethod
// EXPECTED: org.jetbrains.kotlin.light.classes.symbol.fields.SymbolLightFieldForProperty
@get:JvmName("getBar")
val <caret>p: Int = 42
@@ -0,0 +1,45 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.light.classes.symbol.base
import org.jetbrains.kotlin.analysis.low.level.api.fir.test.configurators.AnalysisApiFirSourceTestConfigurator
import org.jetbrains.kotlin.analysis.test.framework.base.AbstractAnalysisApiBasedSingleModuleTest
import org.jetbrains.kotlin.analysis.test.framework.services.expressionMarkerProvider
import org.jetbrains.kotlin.asJava.toLightElements
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder
import org.jetbrains.kotlin.test.directives.model.SimpleDirectivesContainer
import org.jetbrains.kotlin.test.model.TestModule
import org.jetbrains.kotlin.test.services.TestServices
import org.jetbrains.kotlin.test.services.assertions
abstract class AbstractLightClassUtilTest : AbstractAnalysisApiBasedSingleModuleTest() {
override val configurator = AnalysisApiFirSourceTestConfigurator(analyseInDependentSession = false)
override fun doTestByFileStructure(ktFiles: List<KtFile>, module: TestModule, testServices: TestServices) {
val ktFile = ktFiles.single()
val declaration = testServices.expressionMarkerProvider.getElementOfTypeAtCaret<KtDeclaration>(ktFile)
val lightElements = declaration.toLightElements()
testServices.assertions.assertFalse(lightElements.isEmpty())
val directives = module.directives
val expectedLightElements = directives[Directives.EXPECTED]
testServices.assertions.assertEquals(expectedLightElements.size, lightElements.size) {
"Found ${lightElements.map { it.javaClass.name }}"
}
lightElements.forEachIndexed { index, element ->
testServices.assertions.assertEquals(expectedLightElements[index], element.javaClass.name)
}
}
override fun configureTest(builder: TestConfigurationBuilder) {
super.configureTest(builder)
builder.useDirectives(Directives)
}
private object Directives : SimpleDirectivesContainer() {
val EXPECTED by stringDirective(description = "Expected light classes")
}
}
@@ -0,0 +1,80 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.light.classes.symbol.base;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.util.KtTestUtil;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.analysis.api.GenerateAnalysisApiTestsKt}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("analysis/symbol-light-classes/testData/lightElements")
@TestDataPath("$PROJECT_ROOT")
public class LightClassUtilTestGenerated extends AbstractLightClassUtilTest {
@Test
public void testAllFilesPresentInLightElements() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/symbol-light-classes/testData/lightElements"), Pattern.compile("^(.+)\\.(kt)$"), null, true);
}
@Test
@TestMetadata("mangledName.kt")
public void testMangledName() throws Exception {
runTest("analysis/symbol-light-classes/testData/lightElements/mangledName.kt");
}
@Test
@TestMetadata("mangledNameWithAnnotations.kt")
public void testMangledNameWithAnnotations() throws Exception {
runTest("analysis/symbol-light-classes/testData/lightElements/mangledNameWithAnnotations.kt");
}
@Test
@TestMetadata("propertyAccessor.kt")
public void testPropertyAccessor() throws Exception {
runTest("analysis/symbol-light-classes/testData/lightElements/propertyAccessor.kt");
}
@Test
@TestMetadata("propertyAccessorWithAnnotation.kt")
public void testPropertyAccessorWithAnnotation() throws Exception {
runTest("analysis/symbol-light-classes/testData/lightElements/propertyAccessorWithAnnotation.kt");
}
@Test
@TestMetadata("propertyAccessorWithImplicitAnnotation.kt")
public void testPropertyAccessorWithImplicitAnnotation() throws Exception {
runTest("analysis/symbol-light-classes/testData/lightElements/propertyAccessorWithImplicitAnnotation.kt");
}
@Test
@TestMetadata("propertyWithExplicitAccessors.kt")
public void testPropertyWithExplicitAccessors() throws Exception {
runTest("analysis/symbol-light-classes/testData/lightElements/propertyWithExplicitAccessors.kt");
}
@Test
@TestMetadata("propertyWithExplicitAccessorsAndAnnotation.kt")
public void testPropertyWithExplicitAccessorsAndAnnotation() throws Exception {
runTest("analysis/symbol-light-classes/testData/lightElements/propertyWithExplicitAccessorsAndAnnotation.kt");
}
@Test
@TestMetadata("propertyWithExplicitAccessorsAndAnnotationOnThem.kt")
public void testPropertyWithExplicitAccessorsAndAnnotationOnThem() throws Exception {
runTest("analysis/symbol-light-classes/testData/lightElements/propertyWithExplicitAccessorsAndAnnotationOnThem.kt");
}
@Test
@TestMetadata("propertyWithImplicitAccessors.kt")
public void testPropertyWithImplicitAccessors() throws Exception {
runTest("analysis/symbol-light-classes/testData/lightElements/propertyWithImplicitAccessors.kt");
}
}