Fixed KT-5211 Code completion in IntelliJ for generating anonymous class creates code with compile error "Projections are not allowed for immediate arguments of a super type"

#KT-5211 Fixed
This commit is contained in:
Valentin Kipyatkov
2014-11-26 21:01:06 +03:00
parent 3566ac1510
commit 52acd223a2
5 changed files with 44 additions and 5 deletions
@@ -55,9 +55,10 @@ import org.jetbrains.jet.lang.types.JetTypeImpl
import org.jetbrains.jet.lang.descriptors.annotations.Annotations
import org.jetbrains.jet.lang.resolve.DescriptorUtils
import org.jetbrains.jet.lang.resolve.java.mapping.KotlinToJavaTypesMap
import org.jetbrains.jet.lang.resolve.lazy.ResolveSessionUtils
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor
import org.jetbrains.jet.lang.resolve.resolveTopLevelClass
import org.jetbrains.jet.lang.types.TypeProjectionImpl
import org.jetbrains.jet.lang.types.Variance
class TypeInstantiationItems(
val resolutionFacade: ResolutionFacade,
@@ -142,11 +143,14 @@ class TypeInstantiationItems(
var lookupString = lookupElement.getLookupString()
var allLookupStrings = setOf(lookupString)
var itemText = lookupString + DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderTypeArguments(typeArgs)
// drop "in" and "out" from type arguments - they cannot be used in constructor call
val typeArgsToUse = typeArgs.map { if (it != null) TypeProjectionImpl(Variance.INVARIANT, it.getType()) else null }
var itemText = lookupString + DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderTypeArguments(typeArgsToUse)
var signatureText: String? = null
val insertHandler: InsertHandler<LookupElement>
val typeText = qualifiedNameForSourceCode(classifier) + IdeDescriptorRenderers.SOURCE_CODE.renderTypeArguments(typeArgs)
val typeText = qualifiedNameForSourceCode(classifier) + IdeDescriptorRenderers.SOURCE_CODE.renderTypeArguments(typeArgsToUse)
if (isAbstract) {
val constructorParenthesis = if (classifier.getKind() != ClassKind.TRAIT) "()" else ""
itemText += constructorParenthesis
@@ -0,0 +1,13 @@
fun registerHandler(handler: Handler<out Message>) {}
fun test() {
registerHandler(<caret>)
}
trait Message
trait Handler<E> {
fun handle(e: E)
}
// ELEMENT: object
@@ -0,0 +1,17 @@
fun registerHandler(handler: Handler<out Message>) {}
fun test() {
registerHandler(object: Handler<Message> {
override fun handle(e: Message) {
<caret><selection>throw UnsupportedOperationException()</selection>
}
})
}
trait Message
trait Handler<E> {
fun handle(e: E)
}
// ELEMENT: object
@@ -10,6 +10,6 @@ fun foo(): KotlinTrait<I1, I2> {
// ABSENT: KotlinInheritor3
// EXIST: { lookupString: "object", itemText: "object: KotlinInheritor4<I1, I2>(){...}" }
// ABSENT: KotlinInheritor5
// EXIST: { lookupString: "KotlinInheritor6", itemText: "KotlinInheritor6<I1, out Any?, out I3>", tailText: "() (p)" }
// EXIST: { lookupString: "KotlinInheritor6", itemText: "KotlinInheritor6<I1, Any?, I3>", tailText: "() (p)" }
// EXIST: { lookupString: "JavaInheritor1", itemText: "JavaInheritor1", tailText: "() (<root>)" }
// ABSENT: JavaInheritor2
@@ -19,7 +19,6 @@ package org.jetbrains.jet.completion.handlers;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.jet.JUnit3RunnerWithInners;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.test.InnerTestClasses;
import org.jetbrains.jet.test.TestMetadata;
import org.junit.runner.RunWith;
@@ -240,6 +239,12 @@ public class SmartCompletionHandlerTestGenerated extends AbstractSmartCompletion
doTest(fileName);
}
@TestMetadata("ConstructorForGenericType2.kt")
public void testConstructorForGenericType2() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/handlers/smart/ConstructorForGenericType2.kt");
doTest(fileName);
}
@TestMetadata("ConstructorForJavaClass.kt")
public void testConstructorForJavaClass() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/handlers/smart/ConstructorForJavaClass.kt");