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) {
|
private fun KtExpression.shouldShowType() = when(this) {
|
||||||
is KtFunction -> !hasBlockBody() && !hasDeclaredReturnType()
|
is KtFunction -> !hasBlockBody() && !hasDeclaredReturnType()
|
||||||
is KtProperty -> true
|
is KtProperty, is KtDestructuringDeclarationEntry -> true
|
||||||
is KtStatementExpression -> false
|
is KtStatementExpression, is KtDestructuringDeclaration -> false
|
||||||
else -> true
|
else -> true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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>
|
||||||
@@ -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>
|
||||||
@@ -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() {
|
abstract class AbstractExpressionTypeTest : KotlinLightCodeInsightFixtureTestCase() {
|
||||||
override fun getBasePath() = PluginTestCaseBase.TEST_DATA_PROJECT_RELATIVE + "/codeInsight/expressionType"
|
override fun getBasePath() = PluginTestCaseBase.TEST_DATA_PROJECT_RELATIVE + "/codeInsight/expressionType"
|
||||||
|
|
||||||
|
override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
|
||||||
|
|
||||||
protected fun doTest(path: String) {
|
protected fun doTest(path: String) {
|
||||||
myFixture.configureByFile(path)
|
myFixture.configureByFile(path)
|
||||||
val expressionTypeProvider = KotlinExpressionTypeProvider()
|
val expressionTypeProvider = KotlinExpressionTypeProvider()
|
||||||
val expressions = expressionTypeProvider.getExpressionsAt(myFixture.elementAtCaret)
|
val expressions = expressionTypeProvider.getExpressionsAt(myFixture.elementAtCaret)
|
||||||
val types = expressions.map { "${it.text.replace('\n', ' ')} -> ${expressionTypeProvider.getInformationHint(it)}" }
|
val types = expressions.map { "${it.text.replace('\n', ' ')} -> ${expressionTypeProvider.getInformationHint(it)}" }
|
||||||
val expectedTypes = InTextDirectivesUtils.findListWithPrefixes(myFixture.file.text, "// TYPE: ")
|
val expectedTypes = InTextDirectivesUtils.findLinesWithPrefixesRemoved(myFixture.file.text, "// TYPE: ")
|
||||||
UsefulTestCase.assertSameElements(types, expectedTypes)
|
UsefulTestCase.assertOrderedEquals(types, expectedTypes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,42 @@ public class ExpressionTypeTestGenerated extends AbstractExpressionTypeTest {
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("VariableDeclaration.kt")
|
||||||
public void testVariableDeclaration() throws Exception {
|
public void testVariableDeclaration() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/expressionType/VariableDeclaration.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/expressionType/VariableDeclaration.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user