FIR IDE: add API to get KtType from KtTypeParameter
This commit is contained in:
committed by
Ilya Kirillov
parent
d91170ed2c
commit
205866a516
+18
-2
@@ -9,16 +9,21 @@ import org.jetbrains.kotlin.analysis.api.KtStarProjectionTypeArgument
|
||||
import org.jetbrains.kotlin.analysis.api.KtTypeArgumentWithVariance
|
||||
import org.jetbrains.kotlin.analysis.api.components.KtClassTypeBuilder
|
||||
import org.jetbrains.kotlin.analysis.api.components.KtTypeCreator
|
||||
import org.jetbrains.kotlin.analysis.api.components.KtTypeParameterTypeBuilder
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.KtFe10AnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.components.base.Fe10KtAnalysisSessionComponent
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.getSymbolDescriptor
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.toKtType
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.types.KtFe10ClassErrorType
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.types.KtFe10UsualClassType
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.types.base.KtFe10Type
|
||||
import org.jetbrains.kotlin.analysis.api.tokens.ValidityToken
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtClassType
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtTypeNullability
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtTypeParameterType
|
||||
import org.jetbrains.kotlin.analysis.api.withValidityAssertion
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
@@ -29,7 +34,7 @@ internal class KtFe10TypeCreator(
|
||||
override val token: ValidityToken
|
||||
get() = analysisSession.token
|
||||
|
||||
override fun buildClassType(builder: KtClassTypeBuilder): KtClassType {
|
||||
override fun buildClassType(builder: KtClassTypeBuilder): KtClassType = withValidityAssertion {
|
||||
val descriptor: ClassDescriptor? = when (builder) {
|
||||
is KtClassTypeBuilder.ByClassId -> {
|
||||
val fqName = builder.classId.asSingleFqName()
|
||||
@@ -64,4 +69,15 @@ internal class KtFe10TypeCreator(
|
||||
val typeWithNullability = TypeUtils.makeNullableAsSpecified(type, builder.nullability == KtTypeNullability.NULLABLE)
|
||||
return KtFe10UsualClassType(typeWithNullability as SimpleType, descriptor, analysisContext)
|
||||
}
|
||||
}
|
||||
|
||||
override fun buildTypeParameterType(builder: KtTypeParameterTypeBuilder): KtTypeParameterType = withValidityAssertion {
|
||||
val descriptor = when (builder) {
|
||||
is KtTypeParameterTypeBuilder.BySymbol -> {
|
||||
getSymbolDescriptor(builder.symbol) as? TypeParameterDescriptor
|
||||
}
|
||||
}
|
||||
val kotlinType = descriptor?.defaultType
|
||||
?: ErrorUtils.createErrorType("Cannot build type parameter type, descriptor not found for builder $builder")
|
||||
return kotlinType.toKtType(analysisContext) as KtTypeParameterType
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -467,4 +467,4 @@ private class KtFe10BuiltinTypes(private val analysisContext: Fe10AnalysisContex
|
||||
override val NULLABLE_NOTHING: KtType
|
||||
get() = withValidityAssertion { analysisContext.builtIns.nullableNothingType.toKtType(analysisContext) }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.descriptors.test.components.typeCreator
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.test.KtFe10FrontendApiTestConfiguratorService
|
||||
import org.jetbrains.kotlin.analysis.api.impl.base.test.components.typeCreator.AbstractTypeParameterTypeTest
|
||||
|
||||
abstract class AbstractKtFe10TypeParameterTypeTest : AbstractTypeParameterTypeTest(KtFe10FrontendApiTestConfiguratorService)
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.descriptors.test.components.typeCreator;
|
||||
|
||||
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 GenerateNewCompilerTests.kt}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("analysis/analysis-api/testData/components/typeCreator/typeParameter")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class KtFe10TypeParameterTypeTestGenerated extends AbstractKtFe10TypeParameterTypeTest {
|
||||
@Test
|
||||
public void testAllFilesPresentInTypeParameter() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/typeCreator/typeParameter"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("multipleBounds.kt")
|
||||
public void testMultipleBounds() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/typeCreator/typeParameter/multipleBounds.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("regular.kt")
|
||||
public void testRegular() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/typeCreator/typeParameter/regular.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("reified.kt")
|
||||
public void testReified() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/typeCreator/typeParameter/reified.kt");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user