handle multi-declarations in "show expression type"

This commit is contained in:
Dmitry Jemerov
2016-08-25 20:58:07 +02:00
parent fbd2c48fbd
commit 032d50bbbf
6 changed files with 67 additions and 4 deletions

View File

@@ -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
}

View 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>

View 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) &rarr; Unit</html>
// TYPE: x.forEach { (first, second) -> } -> <html>Unit</html>

View 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>

View File

@@ -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)
}
}

View File

@@ -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");