KT-38027 Support Code Vision feature in Kotlin
This commit is contained in:
+47
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2010-2020 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.idea.codeInsight.codevision
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.testFramework.utils.inlays.InlayHintsProviderTestCase
|
||||
import org.jetbrains.kotlin.idea.codeInsight.codevision.KotlinCodeVisionProvider.KotlinCodeVisionSettings
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
import java.io.File
|
||||
|
||||
open class AbstractKotlinCodeVisionProviderTest : InlayHintsProviderTestCase() { // Abstract- prefix is just a convention for GenerateTests
|
||||
|
||||
fun doTest(testPath: String) { // named according to the convention imposed by GenerateTests
|
||||
assertThatActualHintsMatch(testPath)
|
||||
}
|
||||
|
||||
private fun assertThatActualHintsMatch(fileName: String) {
|
||||
val fileContents = FileUtil.loadFile(File(fileName), true)
|
||||
|
||||
val usagesLimit = InTextDirectivesUtils.findStringWithPrefixes(fileContents, "// USAGES-LIMIT: ")?.toInt() ?: 100
|
||||
val inheritorsLimit = InTextDirectivesUtils.findStringWithPrefixes(fileContents, "// INHERITORS-LIMIT: ")?.toInt() ?: 100
|
||||
|
||||
val codeVisionProvider = KotlinCodeVisionProvider()
|
||||
codeVisionProvider.usagesLimit = usagesLimit
|
||||
codeVisionProvider.inheritorsLimit = inheritorsLimit
|
||||
|
||||
val mode: KotlinCodeVisionSettings = when (InTextDirectivesUtils.findStringWithPrefixes(fileContents, "// MODE: ")) {
|
||||
"inheritors" -> inheritorsEnabled()
|
||||
"usages" -> usagesEnabled()
|
||||
"usages-&-inheritors" -> usagesAndInheritorsEnabled()
|
||||
else -> codeVisionDisabled()
|
||||
}
|
||||
|
||||
testProvider("kotlinCodeVision.kt", fileContents, codeVisionProvider, mode)
|
||||
}
|
||||
|
||||
private fun usagesAndInheritorsEnabled(): KotlinCodeVisionSettings = KotlinCodeVisionSettings(showUsages = true, showInheritors = true)
|
||||
|
||||
private fun inheritorsEnabled(): KotlinCodeVisionSettings = KotlinCodeVisionSettings(showUsages = false, showInheritors = true)
|
||||
|
||||
private fun usagesEnabled(): KotlinCodeVisionSettings = KotlinCodeVisionSettings(showUsages = true, showInheritors = false)
|
||||
|
||||
private fun codeVisionDisabled(): KotlinCodeVisionSettings = KotlinCodeVisionSettings(showUsages = false, showInheritors = false)
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
package org.jetbrains.kotlin.idea.codeInsight.codevision
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright 2010-2020 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.idea.codeInsight.codevision;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.TestMetadata;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("idea/testData/codeInsight/codeVision")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class KotlinCodeVisionProviderTestGenerated extends AbstractKotlinCodeVisionProviderTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInCodeVision() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/codeInsight/codeVision"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("ClassFunctionOverrides.kt")
|
||||
public void testClassFunctionOverrides() throws Exception {
|
||||
runTest("idea/testData/codeInsight/codeVision/ClassFunctionOverrides.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ClassInheritors.kt")
|
||||
public void testClassInheritors() throws Exception {
|
||||
runTest("idea/testData/codeInsight/codeVision/ClassInheritors.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ClassMethodUsages.kt")
|
||||
public void testClassMethodUsages() throws Exception {
|
||||
runTest("idea/testData/codeInsight/codeVision/ClassMethodUsages.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ClassPropertiesOverrides.kt")
|
||||
public void testClassPropertiesOverrides() throws Exception {
|
||||
runTest("idea/testData/codeInsight/codeVision/ClassPropertiesOverrides.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ClassPropertyUsages.kt")
|
||||
public void testClassPropertyUsages() throws Exception {
|
||||
runTest("idea/testData/codeInsight/codeVision/ClassPropertyUsages.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ClassUsages.kt")
|
||||
public void testClassUsages() throws Exception {
|
||||
runTest("idea/testData/codeInsight/codeVision/ClassUsages.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("GlobalFunctionUsages.kt")
|
||||
public void testGlobalFunctionUsages() throws Exception {
|
||||
runTest("idea/testData/codeInsight/codeVision/GlobalFunctionUsages.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InterfaceAbstractMethodImplementation.kt")
|
||||
public void testInterfaceAbstractMethodImplementation() throws Exception {
|
||||
runTest("idea/testData/codeInsight/codeVision/InterfaceAbstractMethodImplementation.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InterfaceImplementations.kt")
|
||||
public void testInterfaceImplementations() throws Exception {
|
||||
runTest("idea/testData/codeInsight/codeVision/InterfaceImplementations.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InterfaceMethodUsages.kt")
|
||||
public void testInterfaceMethodUsages() throws Exception {
|
||||
runTest("idea/testData/codeInsight/codeVision/InterfaceMethodUsages.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InterfaceMethodsOverrides.kt")
|
||||
public void testInterfaceMethodsOverrides() throws Exception {
|
||||
runTest("idea/testData/codeInsight/codeVision/InterfaceMethodsOverrides.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InterfacePropertiesOverrides.kt")
|
||||
public void testInterfacePropertiesOverrides() throws Exception {
|
||||
runTest("idea/testData/codeInsight/codeVision/InterfacePropertiesOverrides.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InterfacePropertyUsages.kt")
|
||||
public void testInterfacePropertyUsages() throws Exception {
|
||||
runTest("idea/testData/codeInsight/codeVision/InterfacePropertyUsages.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("InterfaceUsages.kt")
|
||||
public void testInterfaceUsages() throws Exception {
|
||||
runTest("idea/testData/codeInsight/codeVision/InterfaceUsages.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("TooManyUsagesAndInheritors.kt")
|
||||
public void testTooManyUsagesAndInheritors() throws Exception {
|
||||
runTest("idea/testData/codeInsight/codeVision/TooManyUsagesAndInheritors.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("UsagesAndInheritanceTogether.kt")
|
||||
public void testUsagesAndInheritanceTogether() throws Exception {
|
||||
runTest("idea/testData/codeInsight/codeVision/UsagesAndInheritanceTogether.kt");
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
package org.jetbrains.kotlin.idea.codeInsight.codevision;
|
||||
Reference in New Issue
Block a user