mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-04-03 15:52:00 +00:00
handle multi-declarations in "show expression type"
This commit is contained in:
@@ -33,8 +33,8 @@ class KotlinExpressionTypeProvider : ExpressionTypeProvider<KtExpression>() {
|
||||
|
||||
private fun KtExpression.shouldShowType() = when(this) {
|
||||
is KtFunction -> !hasBlockBody() && !hasDeclaredReturnType()
|
||||
is KtProperty -> true
|
||||
is KtStatementExpression -> false
|
||||
is KtProperty, is KtDestructuringDeclarationEntry -> true
|
||||
is KtStatementExpression, is KtDestructuringDeclaration -> false
|
||||
else -> true
|
||||
}
|
||||
|
||||
|
||||
7
idea/testData/codeInsight/expressionType/MultiDeclaration.kt
vendored
Normal file
7
idea/testData/codeInsight/expressionType/MultiDeclaration.kt
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
data class IntStringPair(val x: Int, val s: String)
|
||||
|
||||
fun f(x: IntStringPair) {
|
||||
val (fir<caret>st, second) = x
|
||||
}
|
||||
|
||||
// TYPE: first -> <html>kotlin.Int</html>
|
||||
10
idea/testData/codeInsight/expressionType/MultiDeclarationInLambda.kt
vendored
Normal file
10
idea/testData/codeInsight/expressionType/MultiDeclarationInLambda.kt
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
data class IntStringPair(val x: Int, val s: String)
|
||||
|
||||
fun f(x: List<IntStringPair>) {
|
||||
x.forEach { (fir<caret>st, second) ->
|
||||
}
|
||||
}
|
||||
|
||||
// TYPE: first -> <html>Int</html>
|
||||
// TYPE: { (first, second) -> } -> <html>(IntStringPair) → Unit</html>
|
||||
// TYPE: x.forEach { (first, second) -> } -> <html>Unit</html>
|
||||
8
idea/testData/codeInsight/expressionType/MultiDeclarationInLoop.kt
vendored
Normal file
8
idea/testData/codeInsight/expressionType/MultiDeclarationInLoop.kt
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
data class IntStringPair(val x: Int, val s: String)
|
||||
|
||||
fun f(x: List<IntStringPair>) {
|
||||
for ((fir<caret>st, second) in x) {
|
||||
}
|
||||
}
|
||||
|
||||
// TYPE: first -> <html>Int</html>
|
||||
@@ -24,12 +24,14 @@ import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
abstract class AbstractExpressionTypeTest : KotlinLightCodeInsightFixtureTestCase() {
|
||||
override fun getBasePath() = PluginTestCaseBase.TEST_DATA_PROJECT_RELATIVE + "/codeInsight/expressionType"
|
||||
|
||||
override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
|
||||
|
||||
protected fun doTest(path: String) {
|
||||
myFixture.configureByFile(path)
|
||||
val expressionTypeProvider = KotlinExpressionTypeProvider()
|
||||
val expressions = expressionTypeProvider.getExpressionsAt(myFixture.elementAtCaret)
|
||||
val types = expressions.map { "${it.text.replace('\n', ' ')} -> ${expressionTypeProvider.getInformationHint(it)}" }
|
||||
val expectedTypes = InTextDirectivesUtils.findListWithPrefixes(myFixture.file.text, "// TYPE: ")
|
||||
UsefulTestCase.assertSameElements(types, expectedTypes)
|
||||
val expectedTypes = InTextDirectivesUtils.findLinesWithPrefixesRemoved(myFixture.file.text, "// TYPE: ")
|
||||
UsefulTestCase.assertOrderedEquals(types, expectedTypes)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,42 @@ public class ExpressionTypeTestGenerated extends AbstractExpressionTypeTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("MultiDeclaration.kt")
|
||||
public void testMultiDeclaration() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/expressionType/MultiDeclaration.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("MultiDeclarationInLambda.kt")
|
||||
public void testMultiDeclarationInLambda() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/expressionType/MultiDeclarationInLambda.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("MultiDeclarationInLoop.kt")
|
||||
public void testMultiDeclarationInLoop() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/expressionType/MultiDeclarationInLoop.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("PropertyAccessor.kt")
|
||||
public void testPropertyAccessor() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/expressionType/PropertyAccessor.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SmartCast.kt")
|
||||
public void testSmartCast() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/expressionType/SmartCast.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SoftSmartCast.kt")
|
||||
public void testSoftSmartCast() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/expressionType/SoftSmartCast.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("VariableDeclaration.kt")
|
||||
public void testVariableDeclaration() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/expressionType/VariableDeclaration.kt");
|
||||
|
||||
Reference in New Issue
Block a user