FIR IDE: add API to get KtType from KtTypeParameter
This commit is contained in:
committed by
Ilya Kirillov
parent
d91170ed2c
commit
205866a516
+15
@@ -7,14 +7,18 @@ package org.jetbrains.kotlin.analysis.api.fir.components
|
||||
|
||||
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.fir.KtFirAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.fir.symbols.KtFirSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.tokens.ValidityToken
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtClassType
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtTypeParameterType
|
||||
import org.jetbrains.kotlin.analysis.api.withValidityAssertion
|
||||
import org.jetbrains.kotlin.fir.declarations.FirClassLikeDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
|
||||
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeUnresolvedSymbolError
|
||||
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.toConeType
|
||||
import org.jetbrains.kotlin.fir.types.ConeClassErrorType
|
||||
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
|
||||
import org.jetbrains.kotlin.fir.types.typeContext
|
||||
@@ -47,4 +51,15 @@ internal class KtFirTypeCreator(
|
||||
|
||||
return coneType.asKtType() as KtClassType
|
||||
}
|
||||
|
||||
override fun buildTypeParameterType(builder: KtTypeParameterTypeBuilder): KtTypeParameterType = withValidityAssertion {
|
||||
val coneType = when (builder) {
|
||||
is KtTypeParameterTypeBuilder.BySymbol -> {
|
||||
val symbol = builder.symbol
|
||||
check(symbol is KtFirSymbol<*>)
|
||||
symbol.firRef.withFir { (it as FirTypeParameter).toConeType() }
|
||||
}
|
||||
}
|
||||
return coneType.asKtType() as KtTypeParameterType
|
||||
}
|
||||
}
|
||||
|
||||
+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.fir.components.typeCreator
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.fir.FirFrontendApiTestConfiguratorService
|
||||
import org.jetbrains.kotlin.analysis.api.impl.base.test.components.typeCreator.AbstractTypeParameterTypeTest
|
||||
|
||||
abstract class AbstractFirTypeParameterTypeTest : AbstractTypeParameterTypeTest(FirFrontendApiTestConfiguratorService)
|
||||
+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.fir.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 FirTypeParameterTypeTestGenerated extends AbstractFirTypeParameterTypeTest {
|
||||
@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