Analysis API: add KtType.isDenotable()
This commit is contained in:
+13
-3
@@ -5,16 +5,18 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.fir.components
|
||||
|
||||
import org.jetbrains.kotlin.fir.resolve.FirSamResolverImpl
|
||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||
import org.jetbrains.kotlin.fir.types.canBeNull
|
||||
import org.jetbrains.kotlin.analysis.api.components.KtTypeInfoProvider
|
||||
import org.jetbrains.kotlin.analysis.api.fir.KtFirAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.fir.types.KtFirType
|
||||
import org.jetbrains.kotlin.analysis.api.fir.types.PublicTypeApproximator
|
||||
import org.jetbrains.kotlin.analysis.api.tokens.ValidityToken
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionClassKind
|
||||
import org.jetbrains.kotlin.fir.resolve.FirSamResolverImpl
|
||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||
import org.jetbrains.kotlin.fir.types.canBeNull
|
||||
import org.jetbrains.kotlin.fir.types.functionClassKind
|
||||
import org.jetbrains.kotlin.fir.types.typeApproximator
|
||||
|
||||
internal class KtFirTypeInfoProvider(
|
||||
override val analysisSession: KtFirAnalysisSession,
|
||||
@@ -33,4 +35,12 @@ internal class KtFirTypeInfoProvider(
|
||||
}
|
||||
|
||||
override fun canBeNull(type: KtType): Boolean = (type as KtFirType).coneType.canBeNull
|
||||
|
||||
override fun isDenotable(type: KtType): Boolean {
|
||||
val coneType = (type as KtFirType).coneType
|
||||
return analysisSession.rootModuleSession.typeApproximator.approximateToSuperType(
|
||||
coneType,
|
||||
PublicTypeApproximator.PublicApproximatorConfiguration(false)
|
||||
) == null
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ internal object PublicTypeApproximator {
|
||||
return approximator.approximateToSuperType(type, PublicApproximatorConfiguration(approximateLocalTypes))
|
||||
}
|
||||
|
||||
private class PublicApproximatorConfiguration(
|
||||
internal class PublicApproximatorConfiguration(
|
||||
override val localTypes: Boolean
|
||||
) : TypeApproximatorConfiguration.AllFlexibleSameValue() {
|
||||
override val allFlexible: Boolean get() = false
|
||||
|
||||
+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.typeProvider
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.fir.FirFrontendApiTestConfiguratorService
|
||||
import org.jetbrains.kotlin.analysis.api.impl.base.test.components.typeInfoProvider.AbstractIsDenotableTest
|
||||
|
||||
abstract class AbstractFirIsDenotableTest : AbstractIsDenotableTest(FirFrontendApiTestConfiguratorService)
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.typeProvider;
|
||||
|
||||
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/typeInfoProvider/isDenotable")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class FirIsDenotableTestGenerated extends AbstractFirIsDenotableTest {
|
||||
@Test
|
||||
public void testAllFilesPresentInIsDenotable() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/typeInfoProvider/isDenotable"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile(".*\\.descriptors\\.kt$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("localTypes.kt")
|
||||
public void testLocalTypes() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/typeInfoProvider/isDenotable/localTypes.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("simpleTypes.kt")
|
||||
public void testSimpleTypes() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/typeInfoProvider/isDenotable/simpleTypes.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("smartcast.kt")
|
||||
public void testSmartcast() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/typeInfoProvider/isDenotable/smartcast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeParameter.kt")
|
||||
public void testTypeParameter() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/typeInfoProvider/isDenotable/typeParameter.kt");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user