AA: handle underscore as type arguments
^KTIJ-24742 Fixed
This commit is contained in:
committed by
Ilya Kirillov
parent
d73d3c46e2
commit
5455942859
+18
-3
@@ -30,12 +30,15 @@ import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
import org.jetbrains.kotlin.psi.KtCallElement
|
||||
import org.jetbrains.kotlin.psi.KtDoubleColonExpression
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.psi.KtTypeReference
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.CapturedType
|
||||
import org.jetbrains.kotlin.resolve.calls.util.getResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.getImplicitReceiversHierarchy
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.checker.NewCapturedType
|
||||
@@ -65,18 +68,19 @@ internal class KtFe10TypeProvider(
|
||||
|
||||
override fun approximateToSuperPublicDenotableType(type: KtType, approximateLocalTypes: Boolean): KtType? {
|
||||
require(type is KtFe10Type)
|
||||
return typeApproximator.approximateToSuperType(type.fe10Type, PublicApproximatorConfiguration(approximateLocalTypes))?.toKtType(analysisContext)
|
||||
return typeApproximator.approximateToSuperType(type.fe10Type, PublicApproximatorConfiguration(approximateLocalTypes))
|
||||
?.toKtType(analysisContext)
|
||||
}
|
||||
|
||||
override fun approximateToSubPublicDenotableType(type: KtType, approximateLocalTypes: Boolean): KtType? {
|
||||
require(type is KtFe10Type)
|
||||
return typeApproximator.approximateToSubType(type.fe10Type, PublicApproximatorConfiguration(approximateLocalTypes))?.toKtType(analysisContext)
|
||||
return typeApproximator.approximateToSubType(type.fe10Type, PublicApproximatorConfiguration(approximateLocalTypes))
|
||||
?.toKtType(analysisContext)
|
||||
}
|
||||
|
||||
override fun buildSelfClassType(symbol: KtNamedClassOrObjectSymbol): KtType {
|
||||
val kotlinType = (getSymbolDescriptor(symbol) as? ClassDescriptor)?.defaultType
|
||||
?: ErrorUtils.createErrorType(ErrorTypeKind.UNRESOLVED_CLASS_TYPE, symbol.nameOrAnonymous.toString())
|
||||
|
||||
return kotlinType.toKtType(analysisContext)
|
||||
}
|
||||
|
||||
@@ -88,10 +92,21 @@ internal class KtFe10TypeProvider(
|
||||
override fun getKtType(ktTypeReference: KtTypeReference): KtType {
|
||||
val bindingContext = analysisContext.analyze(ktTypeReference, AnalysisMode.PARTIAL)
|
||||
val kotlinType = bindingContext[BindingContext.TYPE, ktTypeReference]
|
||||
?: getKtTypeAsTypeArgument(ktTypeReference)
|
||||
?: ErrorUtils.createErrorType(ErrorTypeKind.UNRESOLVED_TYPE, ktTypeReference.text)
|
||||
return kotlinType.toKtType(analysisContext)
|
||||
}
|
||||
|
||||
private fun getKtTypeAsTypeArgument(ktTypeReference: KtTypeReference): KotlinType? {
|
||||
val call = ktTypeReference.getParentOfType<KtCallElement>(strict = true) ?: return null
|
||||
val bindingContext = analysisContext.analyze(ktTypeReference, AnalysisMode.PARTIAL)
|
||||
val resolvedCall = call.getResolvedCall(bindingContext) ?: return null
|
||||
val typeProjection = call.typeArguments.find { it.typeReference == ktTypeReference } ?: return null
|
||||
val index = call.typeArguments.indexOf(typeProjection)
|
||||
val paramDescriptor = resolvedCall.candidateDescriptor.typeParameters.find { it.index == index } ?: return null
|
||||
return resolvedCall.typeArguments[paramDescriptor]
|
||||
}
|
||||
|
||||
override fun getReceiverTypeForDoubleColonExpression(expression: KtDoubleColonExpression): KtType? {
|
||||
val bindingContext = analysisContext.analyze(expression, AnalysisMode.PARTIAL)
|
||||
val lhs = bindingContext[BindingContext.DOUBLE_COLON_LHS, expression] ?: return null
|
||||
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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.analysis.api.fe10.test.cases.generated.cases.components.typeProvider;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.analysis.api.fe10.test.configurator.AnalysisApiFe10TestConfiguratorFactory;
|
||||
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisApiTestConfiguratorFactoryData;
|
||||
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisApiTestConfigurator;
|
||||
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.TestModuleKind;
|
||||
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.FrontendKind;
|
||||
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisSessionMode;
|
||||
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisApiMode;
|
||||
import org.jetbrains.kotlin.analysis.api.impl.base.test.cases.components.typeProvider.AbstractTypeReferenceTest;
|
||||
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/analysis-api/testData/components/typeProvider/typeReference")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class Fe10IdeNormalAnalysisSourceModuleTypeReferenceTestGenerated extends AbstractTypeReferenceTest {
|
||||
@NotNull
|
||||
@Override
|
||||
public AnalysisApiTestConfigurator getConfigurator() {
|
||||
return AnalysisApiFe10TestConfiguratorFactory.INSTANCE.createConfigurator(
|
||||
new AnalysisApiTestConfiguratorFactoryData(
|
||||
FrontendKind.Fe10,
|
||||
TestModuleKind.Source,
|
||||
AnalysisSessionMode.Normal,
|
||||
AnalysisApiMode.Ide
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllFilesPresentInTypeReference() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/typeProvider/typeReference"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("starProjection.kt")
|
||||
public void testStarProjection() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/starProjection.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("superTypeEntry.kt")
|
||||
public void testSuperTypeEntry() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/superTypeEntry.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("superTypeEntry_withTypeArgument.kt")
|
||||
public void testSuperTypeEntry_withTypeArgument() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/superTypeEntry_withTypeArgument.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeArgument_functionCall.kt")
|
||||
public void testTypeArgument_functionCall() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/typeArgument_functionCall.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeArgument_superTypeEntry.kt")
|
||||
public void testTypeArgument_superTypeEntry() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/typeArgument_superTypeEntry.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("underscoreTypeArgument_inferred.kt")
|
||||
public void testUnderscoreTypeArgument_inferred() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/underscoreTypeArgument_inferred.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("underscoreTypeArgument_reified.kt")
|
||||
public void testUnderscoreTypeArgument_reified() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/underscoreTypeArgument_reified.kt");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user