Analysis API: add KtType.isDenotable()
This commit is contained in:
+16
@@ -15,6 +15,9 @@ import org.jetbrains.kotlin.analysis.api.withValidityAssertion
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionClassKind
|
||||
import org.jetbrains.kotlin.builtins.getFunctionalClassKind
|
||||
import org.jetbrains.kotlin.load.java.sam.JavaSingleAbstractMethodUtils
|
||||
import org.jetbrains.kotlin.name.SpecialNames
|
||||
import org.jetbrains.kotlin.types.DefinitelyNotNullType
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
|
||||
internal class KtFe10TypeInfoProvider(
|
||||
@@ -37,4 +40,17 @@ internal class KtFe10TypeInfoProvider(
|
||||
require(type is KtFe10Type)
|
||||
return TypeUtils.isNullableType(type.type)
|
||||
}
|
||||
|
||||
override fun isDenotable(type: KtType): Boolean {
|
||||
require(type is KtFe10Type)
|
||||
val kotlinType = type.type
|
||||
return kotlinType.isDenotable()
|
||||
}
|
||||
|
||||
private fun KotlinType.isDenotable(): Boolean {
|
||||
if (this is DefinitelyNotNullType) return false
|
||||
return constructor.isDenotable &&
|
||||
constructor.declarationDescriptor?.name != SpecialNames.NO_NAME_PROVIDED &&
|
||||
arguments.all { it.type.isDenotable() }
|
||||
}
|
||||
}
|
||||
|
||||
+9
@@ -27,6 +27,9 @@ import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder
|
||||
import org.jetbrains.kotlin.test.model.TestModule
|
||||
import org.jetbrains.kotlin.test.services.TestServices
|
||||
import org.jetbrains.kotlin.test.services.compilerConfigurationProvider
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.extension
|
||||
import kotlin.io.path.nameWithoutExtension
|
||||
|
||||
object KtFe10FrontendApiTestConfiguratorService : FrontendApiTestConfiguratorService {
|
||||
override val testPrefix: String
|
||||
@@ -64,4 +67,10 @@ object KtFe10FrontendApiTestConfiguratorService : FrontendApiTestConfiguratorSer
|
||||
override fun doOutOfBlockModification(file: KtFile) {
|
||||
// TODO not supported yet
|
||||
}
|
||||
|
||||
override fun preprocessTestDataPath(path: Path): Path {
|
||||
val newPath = path.resolveSibling(path.nameWithoutExtension + "." + testPrefix + "." + path.extension)
|
||||
if (newPath.toFile().exists()) return newPath
|
||||
return path
|
||||
}
|
||||
}
|
||||
+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.typeProvider
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.test.KtFe10FrontendApiTestConfiguratorService
|
||||
import org.jetbrains.kotlin.analysis.api.impl.base.test.components.typeInfoProvider.AbstractIsDenotableTest
|
||||
|
||||
abstract class AbstractKtFe10IsDenotableTest : AbstractIsDenotableTest(KtFe10FrontendApiTestConfiguratorService)
|
||||
+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.descriptors.test.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 KtFe10IsDenotableTestGenerated extends AbstractKtFe10IsDenotableTest {
|
||||
@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