KT-7815 Smart completion after "as" inserts fq-name for type parameter

#KT-7815 Fixed
This commit is contained in:
Valentin Kipyatkov
2015-06-02 22:34:54 +03:00
parent d3e4b346ce
commit e597532c7a
4 changed files with 23 additions and 10 deletions
@@ -377,8 +377,8 @@ class SmartCompletion(
val expectedInfosGrouped: Map<JetType, List<ExpectedInfo>> = expectedInfos.groupBy { it.type.makeNotNullable() }
val items = ArrayList<LookupElement>()
for ((jetType, infos) in expectedInfosGrouped) {
val lookupElement = lookupElementForType(jetType) ?: continue
for ((type, infos) in expectedInfosGrouped) {
val lookupElement = lookupElementForType(type) ?: continue
items.add(lookupElement.addTailAndNameSimilarity(infos))
}
return Result(null, items, null)
@@ -446,16 +446,13 @@ class SmartCompletion(
return Result(::filterDeclaration, listOf(), null)
}
private fun lookupElementForType(jetType: JetType): LookupElement? {
if (jetType.isError()) return null
val classifier = jetType.getConstructor().getDeclarationDescriptor() ?: return null
private fun lookupElementForType(type: JetType): LookupElement? {
if (type.isError()) return null
val classifier = type.getConstructor().getDeclarationDescriptor() ?: return null
val lookupElement = lookupElementFactory.createLookupElement(classifier, bindingContext, false)
val lookupString = lookupElement.getLookupString()
val typeArgs = jetType.getArguments()
var itemText = lookupString + IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.renderTypeArguments(typeArgs)
val typeText = DescriptorUtils.getFqName(classifier).toString() + IdeDescriptorRenderers.SOURCE_CODE.renderTypeArguments(typeArgs)
var itemText = IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.renderType(type)
val typeText = IdeDescriptorRenderers.SOURCE_CODE.renderType(type)
val insertHandler: InsertHandler<LookupElement> = object : InsertHandler<LookupElement> {
override fun handleInsert(context: InsertionContext, item: LookupElement) {
@@ -0,0 +1,5 @@
package ppp
fun <T> foo(o: Any): T {
return o as <caret>
}
@@ -0,0 +1,5 @@
package ppp
fun <T> foo(o: Any): T {
return o as T<caret>
}
@@ -719,6 +719,12 @@ public class SmartCompletionHandlerTestGenerated extends AbstractSmartCompletion
doTest(fileName);
}
@TestMetadata("TypeParameterAfterAs.kt")
public void testTypeParameterAfterAs() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/smart/TypeParameterAfterAs.kt");
doTest(fileName);
}
@TestMetadata("Vararg1.kt")
public void testVararg1() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/smart/Vararg1.kt");