[AA K2] implement symbol pointers for value parameters
^KT-54311
This commit is contained in:
committed by
Space Team
parent
043e3e6840
commit
202a022b49
+24
@@ -52,6 +52,12 @@ public class Fe10IdeNormalAnalysisSourceModuleSymbolByReferenceTestGenerated ext
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/symbols/symbolByReference"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("constructorValueParameter.kt")
|
||||
public void testConstructorValueParameter() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByReference/constructorValueParameter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("constructorViaTypeAlias.kt")
|
||||
public void testConstructorViaTypeAlias() throws Exception {
|
||||
@@ -94,6 +100,12 @@ public class Fe10IdeNormalAnalysisSourceModuleSymbolByReferenceTestGenerated ext
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByReference/javaField.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("primaryConstructorValueParameter.kt")
|
||||
public void testPrimaryConstructorValueParameter() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByReference/primaryConstructorValueParameter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("propertyReceiverParameter.kt")
|
||||
public void testPropertyReceiverParameter() throws Exception {
|
||||
@@ -106,6 +118,18 @@ public class Fe10IdeNormalAnalysisSourceModuleSymbolByReferenceTestGenerated ext
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByReference/samConstructor.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("setterValueParameter.kt")
|
||||
public void testSetterValueParameter() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByReference/setterValueParameter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("valueParameter.kt")
|
||||
public void testValueParameter() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByReference/valueParameter.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("analysis/analysis-api/testData/symbols/symbolByReference/withTestCompilerPluginEnabled")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+20
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2022 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.
|
||||
*/
|
||||
|
||||
@@ -7,18 +7,23 @@ package org.jetbrains.kotlin.analysis.api.fir.symbols
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.KtFakeSourceElementKind
|
||||
import org.jetbrains.kotlin.analysis.api.analyze
|
||||
import org.jetbrains.kotlin.analysis.api.fir.KtSymbolByFirBuilder
|
||||
import org.jetbrains.kotlin.analysis.api.fir.annotations.KtFirAnnotationListForDeclaration
|
||||
import org.jetbrains.kotlin.analysis.api.fir.findPsi
|
||||
import org.jetbrains.kotlin.analysis.api.fir.symbols.pointers.KtFirValueParameterSymbolPointer
|
||||
import org.jetbrains.kotlin.analysis.api.fir.utils.cached
|
||||
import org.jetbrains.kotlin.analysis.api.fir.utils.firSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtFunctionLikeSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtKotlinPropertySymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtValueParameterSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtPsiBasedSymbolPointer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtKotlinPropertySymbol
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.LLFirResolveSession
|
||||
import org.jetbrains.kotlin.fir.correspondingProperty
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFunction
|
||||
import org.jetbrains.kotlin.fir.renderWithType
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirValueParameterSymbol
|
||||
import org.jetbrains.kotlin.fir.types.arrayElementType
|
||||
@@ -72,7 +77,17 @@ internal class KtFirValueParameterSymbol(
|
||||
|
||||
override fun createPointer(): KtSymbolPointer<KtValueParameterSymbol> = withValidityAssertion {
|
||||
KtPsiBasedSymbolPointer.createForSymbolFromSource(this)?.let { return it }
|
||||
TODO("Creating pointers for functions parameters from library is not supported yet")
|
||||
|
||||
analyze(firResolveSession.useSiteKtModule) {
|
||||
val owner = getContainingSymbol() as KtFunctionLikeSymbol
|
||||
val firFunction = owner.firSymbol.fir as FirFunction
|
||||
|
||||
KtFirValueParameterSymbolPointer(
|
||||
owner.createPointer(),
|
||||
name,
|
||||
firFunction.valueParameters.indexOf(firSymbol.fir),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean = symbolEquals(other)
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2010-2022 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.analysis.api.fir.symbols.pointers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.fir.KtFirAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.fir.utils.firSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.*
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFunction
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
internal class KtFirValueParameterSymbolPointer(
|
||||
private val ownerPointer: KtSymbolPointer<KtFunctionLikeSymbol>,
|
||||
private val name: Name,
|
||||
private val index: Int,
|
||||
) : KtSymbolPointer<KtValueParameterSymbol>() {
|
||||
@Deprecated("Consider using org.jetbrains.kotlin.analysis.api.KtAnalysisSession.restoreSymbol")
|
||||
override fun restoreSymbol(analysisSession: KtAnalysisSession): KtValueParameterSymbol? {
|
||||
require(analysisSession is KtFirAnalysisSession)
|
||||
val ownerSymbol = with(analysisSession) {
|
||||
ownerPointer.restoreSymbol() ?: return null
|
||||
}
|
||||
|
||||
val function = ownerSymbol.firSymbol.fir as? FirFunction ?: return null
|
||||
val firValueParameterSymbol = function.valueParameters.getOrNull(index)?.takeIf { it.name == name } ?: return null
|
||||
return analysisSession.firSymbolBuilder.variableLikeBuilder.buildValueParameterSymbol(firValueParameterSymbol.symbol)
|
||||
}
|
||||
}
|
||||
+24
@@ -52,6 +52,12 @@ public class FirIdeNormalAnalysisSourceModuleSymbolByReferenceTestGenerated exte
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/symbols/symbolByReference"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("constructorValueParameter.kt")
|
||||
public void testConstructorValueParameter() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByReference/constructorValueParameter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("constructorViaTypeAlias.kt")
|
||||
public void testConstructorViaTypeAlias() throws Exception {
|
||||
@@ -94,6 +100,12 @@ public class FirIdeNormalAnalysisSourceModuleSymbolByReferenceTestGenerated exte
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByReference/javaField.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("primaryConstructorValueParameter.kt")
|
||||
public void testPrimaryConstructorValueParameter() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByReference/primaryConstructorValueParameter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("propertyReceiverParameter.kt")
|
||||
public void testPropertyReceiverParameter() throws Exception {
|
||||
@@ -106,6 +118,18 @@ public class FirIdeNormalAnalysisSourceModuleSymbolByReferenceTestGenerated exte
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByReference/samConstructor.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("setterValueParameter.kt")
|
||||
public void testSetterValueParameter() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByReference/setterValueParameter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("valueParameter.kt")
|
||||
public void testValueParameter() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByReference/valueParameter.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("analysis/analysis-api/testData/symbols/symbolByReference/withTestCompilerPluginEnabled")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+24
@@ -52,6 +52,12 @@ public class FirStandaloneNormalAnalysisSourceModuleSymbolByReferenceTestGenerat
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/symbols/symbolByReference"), Pattern.compile("^(.+)\\.kt$"), null, true, "withTestCompilerPluginEnabled");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("constructorValueParameter.kt")
|
||||
public void testConstructorValueParameter() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByReference/constructorValueParameter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("constructorViaTypeAlias.kt")
|
||||
public void testConstructorViaTypeAlias() throws Exception {
|
||||
@@ -94,6 +100,12 @@ public class FirStandaloneNormalAnalysisSourceModuleSymbolByReferenceTestGenerat
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByReference/javaField.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("primaryConstructorValueParameter.kt")
|
||||
public void testPrimaryConstructorValueParameter() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByReference/primaryConstructorValueParameter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("propertyReceiverParameter.kt")
|
||||
public void testPropertyReceiverParameter() throws Exception {
|
||||
@@ -105,4 +117,16 @@ public class FirStandaloneNormalAnalysisSourceModuleSymbolByReferenceTestGenerat
|
||||
public void testSamConstructor() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByReference/samConstructor.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("setterValueParameter.kt")
|
||||
public void testSetterValueParameter() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByReference/setterValueParameter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("valueParameter.kt")
|
||||
public void testValueParameter() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByReference/valueParameter.kt");
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE_K1
|
||||
|
||||
class A {
|
||||
constructor(abc: Int) {
|
||||
ab<caret>c
|
||||
}
|
||||
}
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
abc: kotlin.Int
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
KtValueParameterSymbol:
|
||||
annotationsList: []
|
||||
callableIdIfNonLocal: null
|
||||
contextReceivers: []
|
||||
generatedPrimaryConstructorProperty: null
|
||||
hasDefaultValue: false
|
||||
isCrossinline: false
|
||||
isExtension: false
|
||||
isImplicitLambdaParameter: false
|
||||
isNoinline: false
|
||||
isVararg: false
|
||||
name: abc
|
||||
origin: SOURCE
|
||||
receiverType: null
|
||||
returnType: kotlin/Int
|
||||
symbolKind: LOCAL
|
||||
typeParameters: []
|
||||
getContainingModule: KtSourceModule "Sources of main"
|
||||
deprecationStatus: null
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
// DO_NOT_CHECK_SYMBOL_RESTORE
|
||||
// DO_NOT_CHECK_SYMBOL_RESTORE_K1
|
||||
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
|
||||
|
||||
inline fun <T, R> T.use(block: (T) -> R): R {
|
||||
return block(this)
|
||||
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE_K1
|
||||
|
||||
class A(abc: Int) {
|
||||
init {
|
||||
ab<caret>c
|
||||
}
|
||||
}
|
||||
analysis/analysis-api/testData/symbols/symbolByReference/primaryConstructorValueParameter.pretty.txt
Vendored
+1
@@ -0,0 +1 @@
|
||||
abc: kotlin.Int
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
KtValueParameterSymbol:
|
||||
annotationsList: []
|
||||
callableIdIfNonLocal: null
|
||||
contextReceivers: []
|
||||
generatedPrimaryConstructorProperty: null
|
||||
hasDefaultValue: false
|
||||
isCrossinline: false
|
||||
isExtension: false
|
||||
isImplicitLambdaParameter: false
|
||||
isNoinline: false
|
||||
isVararg: false
|
||||
name: abc
|
||||
origin: SOURCE
|
||||
receiverType: null
|
||||
returnType: kotlin/Int
|
||||
symbolKind: LOCAL
|
||||
typeParameters: []
|
||||
getContainingModule: KtSourceModule "Sources of main"
|
||||
deprecationStatus: null
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
|
||||
|
||||
var i: Int
|
||||
set(value) {
|
||||
valu<caret>e
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
value: kotlin.Int
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
KtValueParameterSymbol:
|
||||
annotationsList: []
|
||||
callableIdIfNonLocal: null
|
||||
contextReceivers: []
|
||||
generatedPrimaryConstructorProperty: null
|
||||
hasDefaultValue: false
|
||||
isCrossinline: false
|
||||
isExtension: false
|
||||
isImplicitLambdaParameter: false
|
||||
isNoinline: false
|
||||
isVararg: false
|
||||
name: value
|
||||
origin: SOURCE
|
||||
receiverType: null
|
||||
returnType: kotlin/Int
|
||||
symbolKind: LOCAL
|
||||
typeParameters: []
|
||||
getContainingModule: KtSourceModule "Sources of main"
|
||||
deprecationStatus: null
|
||||
@@ -0,0 +1,5 @@
|
||||
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE_K1
|
||||
|
||||
fun check(abc: Int) {
|
||||
a<caret>bc
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
abc: kotlin.Int
|
||||
@@ -0,0 +1,19 @@
|
||||
KtValueParameterSymbol:
|
||||
annotationsList: []
|
||||
callableIdIfNonLocal: null
|
||||
contextReceivers: []
|
||||
generatedPrimaryConstructorProperty: null
|
||||
hasDefaultValue: false
|
||||
isCrossinline: false
|
||||
isExtension: false
|
||||
isImplicitLambdaParameter: false
|
||||
isNoinline: false
|
||||
isVararg: false
|
||||
name: abc
|
||||
origin: SOURCE
|
||||
receiverType: null
|
||||
returnType: kotlin/Int
|
||||
symbolKind: LOCAL
|
||||
typeParameters: []
|
||||
getContainingModule: KtSourceModule "Sources of main"
|
||||
deprecationStatus: null
|
||||
Reference in New Issue
Block a user