don't offer functions with block body and functions with declared return type as candidates for "show expression type"
This commit is contained in:
@@ -29,10 +29,13 @@ import org.jetbrains.kotlin.types.KotlinType
|
|||||||
|
|
||||||
class KotlinExpressionTypeProvider : ExpressionTypeProvider<KtExpression>() {
|
class KotlinExpressionTypeProvider : ExpressionTypeProvider<KtExpression>() {
|
||||||
override fun getExpressionsAt(elementAt: PsiElement): List<KtExpression> =
|
override fun getExpressionsAt(elementAt: PsiElement): List<KtExpression> =
|
||||||
elementAt.parentsWithSelf.filterIsInstance<KtExpression>().filterNot { it.shouldSkip() }.toList()
|
elementAt.parentsWithSelf.filterIsInstance<KtExpression>().filter { it.shouldShowType() }.toList()
|
||||||
|
|
||||||
private fun KtExpression.shouldSkip(): Boolean {
|
private fun KtExpression.shouldShowType() = when(this) {
|
||||||
return this is KtStatementExpression && this !is KtFunction && this !is KtProperty
|
is KtFunction -> !hasBlockBody() && !hasDeclaredReturnType()
|
||||||
|
is KtProperty -> true
|
||||||
|
is KtStatementExpression -> false
|
||||||
|
else -> true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getInformationHint(element: KtExpression): String {
|
override fun getInformationHint(element: KtExpression): String {
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo() {
|
||||||
|
val <caret>x = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
// TYPE: val x = 1 -> <html>kotlin.Int</html>
|
||||||
@@ -28,7 +28,7 @@ abstract class AbstractExpressionTypeTest : KotlinLightCodeInsightFixtureTestCas
|
|||||||
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} -> ${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.findListWithPrefixes(myFixture.file.text, "// TYPE: ")
|
||||||
UsefulTestCase.assertSameElements(types, expectedTypes)
|
UsefulTestCase.assertSameElements(types, expectedTypes)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,12 @@ public class ExpressionTypeTestGenerated extends AbstractExpressionTypeTest {
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/codeInsight/expressionType"), Pattern.compile("^(.+)\\.kt$"), true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/codeInsight/expressionType"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("BlockBodyFunction.kt")
|
||||||
|
public void testBlockBodyFunction() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/expressionType/BlockBodyFunction.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