Smart completion includes constructor parameters for instantiation items

This commit is contained in:
Valentin Kipyatkov
2014-11-14 15:03:33 +03:00
parent d421e7ac72
commit b7e9d96af2
4 changed files with 24 additions and 9 deletions
@@ -99,14 +99,18 @@ class TypeInstantiationItems(val resolveSession: ResolveSessionForBodies, val bi
} }
else { else {
//TODO: when constructor has one parameter of lambda type with more than one parameter, generate special additional item //TODO: when constructor has one parameter of lambda type with more than one parameter, generate special additional item
itemText += "()" itemText += when (visibleConstructors.size) {
val baseInsertHandler = 0 -> "()"
(if (visibleConstructors.size == 0) 1 -> DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderFunctionParameters(visibleConstructors.single())
KotlinFunctionInsertHandler.NO_PARAMETERS_HANDLER else -> "(...)"
else if (visibleConstructors.size == 1) }
KotlinLookupElementFactory.getDefaultInsertHandler(visibleConstructors.single())
else val baseInsertHandler = when (visibleConstructors.size) {
KotlinFunctionInsertHandler.WITH_PARAMETERS_HANDLER) as KotlinFunctionInsertHandler 0 -> KotlinFunctionInsertHandler.NO_PARAMETERS_HANDLER
1 -> KotlinLookupElementFactory.getDefaultInsertHandler(visibleConstructors.single()) as KotlinFunctionInsertHandler
else -> KotlinFunctionInsertHandler.WITH_PARAMETERS_HANDLER
}
insertHandler = object : InsertHandler<LookupElement> { insertHandler = object : InsertHandler<LookupElement> {
override fun handleInsert(context: InsertionContext, item: LookupElement) { override fun handleInsert(context: InsertionContext, item: LookupElement) {
context.getDocument().replaceString(context.getStartOffset(), context.getTailOffset(), typeText) context.getDocument().replaceString(context.getStartOffset(), context.getTailOffset(), typeText)
@@ -2,4 +2,4 @@ import java.util.Date
var a : Date = <caret> var a : Date = <caret>
// EXIST: { lookupString:"Date", itemText:"Date()" } // EXIST: { lookupString:"Date", itemText:"Date(...)" }
@@ -0,0 +1,5 @@
class Foo(val p1: String, val p2: Any?)
var a : Foo = <caret>
// EXIST: { lookupString:"Foo", itemText:"Foo(p1: String, p2: Any?)" }
@@ -186,6 +186,12 @@ public class JvmSmartCompletionTestGenerated extends AbstractJvmSmartCompletionT
doTest(fileName); doTest(fileName);
} }
@TestMetadata("ConstructorWithParameters.kt")
public void testConstructorWithParameters() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/smart/ConstructorWithParameters.kt");
doTest(fileName);
}
@TestMetadata("EmptyPrefix.kt") @TestMetadata("EmptyPrefix.kt")
public void testEmptyPrefix() throws Exception { public void testEmptyPrefix() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/smart/EmptyPrefix.kt"); String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/smart/EmptyPrefix.kt");