Create From Usage: Create class by constructor call

This commit is contained in:
Alexey Sedunov
2014-10-31 20:19:35 +03:00
parent b8f68acdbb
commit 1b1eb10979
90 changed files with 1068 additions and 5 deletions
@@ -18,6 +18,7 @@ package org.jetbrains.jet.plugin.quickfix;
import org.jetbrains.jet.lang.psi.JetClass;
import org.jetbrains.jet.plugin.codeInsight.ImplementMethodsHandler;
import org.jetbrains.jet.plugin.quickfix.createFromUsage.createClass.CreateClassFromConstructorCallActionFactory;
import org.jetbrains.jet.plugin.quickfix.createFromUsage.createClass.CreateClassFromTypeReferenceActionFactory;
import org.jetbrains.jet.plugin.quickfix.createFromUsage.createClass.CreateClassFromReferenceExpressionActionFactory;
import org.jetbrains.jet.plugin.quickfix.createFromUsage.createFunction.*;
@@ -242,6 +243,10 @@ public class QuickFixRegistrar {
QuickFixes.factories.put(TOO_MANY_ARGUMENTS, CreateFunctionOrPropertyFromCallActionFactory.INSTANCE$);
QuickFixes.factories.put(EXPRESSION_EXPECTED_PACKAGE_FOUND, CreateFunctionOrPropertyFromCallActionFactory.INSTANCE$);
QuickFixes.factories.put(UNRESOLVED_REFERENCE_WRONG_RECEIVER, CreateClassFromConstructorCallActionFactory.INSTANCE$);
QuickFixes.factories.put(UNRESOLVED_REFERENCE, CreateClassFromConstructorCallActionFactory.INSTANCE$);
QuickFixes.factories.put(EXPRESSION_EXPECTED_PACKAGE_FOUND, CreateClassFromConstructorCallActionFactory.INSTANCE$);
QuickFixes.factories.put(UNRESOLVED_REFERENCE, CreateLocalVariableActionFactory.INSTANCE$);
QuickFixes.factories.put(EXPRESSION_EXPECTED_PACKAGE_FOUND, CreateLocalVariableActionFactory.INSTANCE$);
@@ -34,6 +34,8 @@ import org.jetbrains.jet.lang.resolve.name.FqName
import kotlin.properties.Delegates
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor
import org.jetbrains.jet.plugin.util.makeNotNullable
import org.jetbrains.jet.lang.psi.JetAnnotationEntry
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
private fun JetType.contains(inner: JetType): Boolean {
return JetTypeChecker.DEFAULT.equalTypes(this, inner) || getArguments().any { inner in it.getType() }
@@ -90,7 +92,10 @@ fun JetExpression.guessTypes(
): Array<JetType> {
val builtIns = KotlinBuiltIns.getInstance()
if (coerceUnusedToUnit && this !is JetDeclaration && isUsedAsStatement(context)) return array(builtIns.getUnitType())
if (coerceUnusedToUnit
&& this !is JetDeclaration
&& isUsedAsStatement(context)
&& getParentByType(javaClass<JetAnnotationEntry>()) == null) return array(builtIns.getUnitType())
// if we know the actual type of the expression
val theType1 = context[BindingContext.EXPRESSION_TYPE, this]
@@ -0,0 +1,82 @@
package org.jetbrains.jet.plugin.quickfix.createFromUsage.createClass
import org.jetbrains.jet.lang.diagnostics.Diagnostic
import com.intellij.codeInsight.intention.IntentionAction
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
import org.jetbrains.jet.lang.psi.JetTypeReference
import org.jetbrains.jet.lang.psi.JetCallExpression
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression
import org.jetbrains.jet.lang.psi.JetQualifiedExpression
import org.jetbrains.jet.lang.resolve.calls.callUtil.getCall
import org.jetbrains.jet.plugin.quickfix.createFromUsage.callableBuilder.TypeInfo
import org.jetbrains.jet.lang.types.Variance
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
import org.jetbrains.jet.plugin.quickfix.createFromUsage.callableBuilder.ParameterInfo
import org.jetbrains.jet.plugin.quickfix.JetSingleIntentionActionFactory
import org.jetbrains.jet.plugin.caches.resolve.getAnalysisResults
import org.jetbrains.jet.lang.psi.JetFile
import org.jetbrains.jet.lang.psi.JetAnnotationEntry
import java.util.Collections
public object CreateClassFromConstructorCallActionFactory: JetSingleIntentionActionFactory() {
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
val diagElement = diagnostic.getPsiElement()
if (diagElement.getParentByType(javaClass<JetTypeReference>()) != null) return null
val inAnnotationEntry = diagElement.getParentByType(javaClass<JetAnnotationEntry>()) != null
val callExpr = diagElement.getParent() as? JetCallExpression ?: return null
if (callExpr.getCalleeExpression() != diagElement) return null
val calleeExpr = callExpr.getCalleeExpression() as? JetSimpleNameExpression ?: return null
val name = calleeExpr.getReferencedName()
if (!inAnnotationEntry && !name.checkClassName()) return null
val callParent = callExpr.getParent()
val fullCallExpr =
if (callParent is JetQualifiedExpression && callParent.getSelectorExpression() == callExpr) callParent else callExpr
val file = fullCallExpr.getContainingFile() as? JetFile ?: return null
val exhaust = callExpr.getAnalysisResults()
val context = exhaust.getBindingContext()
val call = callExpr.getCall(context) ?: return null
val targetParent = getTargetParentByCall(call, file) ?: return null
val inner = isInnerClassExpected(call)
val valueArguments = callExpr.getValueArguments()
val defaultParamName = if (inAnnotationEntry && valueArguments.size == 1) "value" else null
val anyType = KotlinBuiltIns.getInstance().getNullableAnyType()
val parameterInfos = valueArguments.map {
ParameterInfo(
it.getArgumentExpression()?.let { TypeInfo(it, Variance.IN_VARIANCE) } ?: TypeInfo(anyType, Variance.IN_VARIANCE),
it.getArgumentName()?.getReferenceExpression()?.getReferencedName() ?: defaultParamName
)
}
val classKind = if (inAnnotationEntry) ClassKind.ANNOTATION_CLASS else ClassKind.PLAIN_CLASS
val (expectedTypeInfo, filter) = fullCallExpr.getInheritableTypeInfo(context, exhaust.getModuleDescriptor(), targetParent)
if (!filter(classKind)) return null
val typeArgumentInfos = if (inAnnotationEntry) {
Collections.emptyList()
}
else {
callExpr.getTypeArguments().map { TypeInfo(it.getTypeReference(), Variance.INVARIANT) }
}
val classInfo = ClassInfo(
kind = classKind,
name = name,
targetParent = targetParent,
expectedTypeInfo = expectedTypeInfo,
inner = inner,
typeArguments = typeArgumentInfos,
parameterInfos = parameterInfos
)
return CreateClassFromUsageFix(callExpr, classInfo)
}
}
@@ -23,6 +23,7 @@ import org.jetbrains.jet.lang.psi.Call
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.jet.lang.resolve.scopes.receivers.Qualifier
import org.jetbrains.jet.plugin.util.ProjectRootsUtil
import org.jetbrains.jet.plugin.quickfix.createFromUsage.callableBuilder.noSubstitutions
import org.jetbrains.jet.lang.resolve.DescriptorUtils
import org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils
@@ -90,7 +91,7 @@ private fun JetExpression.getInheritableTypeInfo(
if (!(canHaveSubtypes || isEnum)
|| descriptor is TypeParameterDescriptor) return TypeInfo.Empty to { classKind -> false }
return TypeInfo.ByType(type, Variance.OUT_VARIANCE) to { classKind ->
return TypeInfo.ByType(type, Variance.OUT_VARIANCE).noSubstitutions() to { classKind ->
when (classKind) {
ClassKind.ENUM_ENTRY -> isEnum && containingDeclaration == DescriptorToSourceUtils.descriptorToDeclaration(descriptor)
else -> canHaveSubtypes
@@ -24,11 +24,13 @@ import org.jetbrains.jet.lang.psi.JetFile
import org.jetbrains.jet.lang.psi.psiUtil.getAssignmentByLHS
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.lang.psi.JetTypeReference
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.jet.lang.psi.JetAnnotationEntry
object CreateFunctionOrPropertyFromCallActionFactory : JetSingleIntentionActionFactory() {
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
val diagElement = diagnostic.getPsiElement()
if (diagElement.getParentByType(javaClass<JetTypeReference>()) != null) return null
if (PsiTreeUtil.getParentOfType(diagElement, javaClass<JetTypeReference>(), javaClass<JetAnnotationEntry>()) != null) return null
val callExpr = when (diagnostic.getFactory()) {
in Errors.UNRESOLVED_REFERENCE_DIAGNOSTICS, Errors.EXPRESSION_EXPECTED_PACKAGE_FOUND -> {
@@ -1,4 +1,5 @@
// "class com.intellij.codeInsight.daemon.impl.quickfix.ImportClassFixBase" "false"
// ACTION: Create class 'SomeTest'
// ERROR: Unresolved reference: SomeTest
package testing
@@ -1,5 +1,6 @@
// "class com.intellij.codeInsight.daemon.impl.quickfix.ImportClassFixBase" "false"
// ERROR: Unresolved reference: SomeTest
// ACTION: Create class 'SomeTest'
// ACTION: Edit intention settings
// ACTION: Replace safe access expression with 'if' expression
// ACTION: Disable 'Replace Safe Access Expression with 'if' Expression'
@@ -1,5 +1,6 @@
// "class com.intellij.codeInsight.daemon.impl.quickfix.ImportClassFixBase" "false"
// ACTION: Create function 'FooPackage'
// ACTION: Create class 'FooPackage'
// ERROR: Unresolved reference: FooPackage
package packageClass
@@ -0,0 +1,8 @@
// "Create annotation 'bar'" "true"
// ERROR: Unresolved reference: foo
[foo(1, "2", bar("3", 4))] fun test() {
}
annotation class bar(val s: String, val i: Int)
@@ -0,0 +1,11 @@
// "Create class 'Foo'" "true"
fun run<T>(f: () -> T) = f()
fun test() {
run { Foo() }
}
class Foo {
}
@@ -0,0 +1,9 @@
// "Create class 'Foo'" "true"
fun test() {
fun nestedTest() = Foo(2, "2")
}
class Foo(i: Int, s: String) {
}
@@ -0,0 +1,11 @@
// "Create class 'Foo'" "true"
class A {
class B {
fun test() = Foo(2, "2")
}
}
class Foo(i: Int, s: String) {
}
@@ -0,0 +1,14 @@
// "Create class 'Foo'" "true"
// ERROR: <html>Class 'Foo' must be declared abstract or implement abstract member<br/><b>public</b> <b>abstract</b> <b>fun</b> get(thisRef: A&lt;T&gt;, desc: kotlin.PropertyMetadata): B <i>defined in</i> kotlin.properties.ReadOnlyProperty</html>
import kotlin.properties.ReadOnlyProperty
open class B
class A<T>(val t: T) {
val x: B by Foo(t, "")
}
class Foo<T>(t: T, s: String) : ReadOnlyProperty<A<T>, B> {
}
@@ -0,0 +1,14 @@
// "Create class 'Foo'" "true"
// DISABLE-ERRORS
import kotlin.properties.ReadWriteProperty
open class B
class A<T>(val t: T) {
var x: B by Foo(t, "")
}
class Foo<T>(t: T, s: String) : ReadWriteProperty<A<T>, B> {
}
@@ -0,0 +1,7 @@
// "Create class 'Foo'" "true"
fun test() = Foo(2, "2")
class Foo(i: Int, s: String) {
}
@@ -0,0 +1,13 @@
// "Create class 'Foo'" "true"
class A<T>(val n: T) {
class Foo(i: Int) {
}
}
fun test() {
val a = A.Foo(2)
}
@@ -0,0 +1,9 @@
// "Create class 'Foo'" "true"
class A(n: Int)
fun test() = Foo(abc = 1, ghi = A(2), def = "s")
class Foo(abc: Int, ghi: A, def: String) {
}
@@ -0,0 +1,15 @@
// "Create class 'Foo'" "true"
// ERROR: <html>Type inference failed: <table><tr><td width="10%"></td><td align="right" colspan="2" style="white-space:nowrap;font-weight:bold;"><b>constructor</b> Foo&lt;U&gt;</td><td style="white-space:nowrap;font-weight:bold;">(</td><td align="right" style="white-space:nowrap;font-weight:bold;">u: U</td><td style="white-space:nowrap;font-weight:bold;">)</td><td style="white-space:nowrap;font-weight:bold;"></td></tr><tr><td colspan="7" style="white-space:nowrap;">cannot be applied to</td></tr><tr><td width="10%"></td><td style="white-space:nowrap;"></td><td style="white-space:nowrap;"></td><td style="white-space:nowrap;"><b>(</b></td><td align="right" style="white-space:nowrap;"><font color=red><b>U</b></font></td><td style="white-space:nowrap;"><b>)</b></td></tr></table></html>
// ERROR: <html>Type mismatch.<table><tr><td>Required:</td><td>U</td></tr><tr><td>Found:</td><td>U</td></tr></table></html>
class A<T>(val n: T) {
inner class Foo<U>(u: U) {
}
}
fun test<U>(u: U) {
val a = A(u).Foo(u)
}
@@ -0,0 +1,9 @@
// "Create class 'Foo'" "true"
fun test() {
val a = Foo(2, "2") { (p: Int) -> p + 1 }
}
class Foo(i: Int, s: String, function: Function1<Int, Int>) {
}
@@ -0,0 +1,9 @@
// "Create class 'Foo'" "true"
fun test() {
val a = Foo { (p: Int) -> p + 1 }
}
class Foo(function: Function1<Int, Int>) {
}
@@ -0,0 +1,13 @@
// "Create class 'Foo'" "true"
object A {
class Foo(i: Int) {
}
}
fun test() {
val a = A.Foo(2)
}
@@ -0,0 +1,9 @@
// "Create class 'Foo'" "true"
package Foo
fun test() = Foo(2, "2")
class Foo(i: Int, s: String) {
}
@@ -0,0 +1,13 @@
// "Create class 'Foo'" "true"
class A<T>(val n: T) {
inner class Foo(i: Int) {
}
}
fun test() {
val a = A(1).Foo(2)
}
@@ -0,0 +1,9 @@
// "Create class 'Foo'" "true"
open class A
fun test(): A = Foo(2, "2")
class Foo(i: Int, s: String) : A() {
}
@@ -0,0 +1,10 @@
// "Create class 'Foo'" "true"
// ERROR: No value passed for parameter n
open class A(n: Int)
fun test(): A = Foo(2, "2")
class Foo(i: Int, s: String) : A() {
}
@@ -0,0 +1,9 @@
// "Create class 'Foo'" "true"
trait A
fun test(): A = Foo(2, "2")
class Foo(i: Int, s: String) : A {
}
@@ -0,0 +1,9 @@
// "Create class 'Foo'" "true"
class A<T>(val n: T) {
inner class Foo(i: Int, s: String) {
}
fun test() = this.Foo(2, "2")
}
@@ -0,0 +1,11 @@
// "Create class 'Foo'" "true"
class A<T>(val n: T) {
inner class Foo(i: Int, s: String) {
}
}
fun <U> A<U>.test() = this.Foo(2, "2")
@@ -0,0 +1,11 @@
// "Create class 'Foo'" "true"
class A<T>(val n: T) {
inner class B<U>(val m: U) {
inner class Foo(i: Int, s: String) {
}
fun test() = this.Foo(2, "2")
}
}
@@ -0,0 +1,11 @@
// "Create class 'Foo'" "true"
class A<T>(val n: T) {
inner class Foo(i: Int, s: String) {
}
inner class B<U>(val m: U) {
fun test() = this@A.Foo(2, "2")
}
}
@@ -0,0 +1,8 @@
// "Create annotation 'bar'" "true"
// ERROR: Unresolved reference: foo
[foo(1, "2", bar("3", 4))] fun test() {
}
annotation class bar(val s: String, val i: Int)
@@ -0,0 +1,8 @@
// "Create annotation 'bar'" "true"
// ERROR: Unresolved reference: foo
[foo(1, "2", bar("3"))] fun test() {
}
annotation class bar(val value: String)
@@ -0,0 +1,8 @@
// "Create annotation 'bar'" "true"
// ERROR: Unresolved reference: foo
[foo(1, "2", bar(fooBar = "3"))] fun test() {
}
annotation class bar(val fooBar: String)
@@ -0,0 +1,9 @@
// "Create class 'Foo'" "true"
fun test() {
Foo(2, "2")
}
class Foo(i: Int, s: String) {
}
@@ -0,0 +1,6 @@
// "Create annotation 'bar'" "true"
// ERROR: Unresolved reference: foo
[foo(1, "2", <caret>bar("3", 4))] fun test() {
}
@@ -0,0 +1,7 @@
// "Create class 'Foo'" "true"
fun run<T>(f: () -> T) = f()
fun test() {
run { <caret>Foo() }
}
@@ -0,0 +1,5 @@
// "Create class 'Foo'" "true"
fun test() {
fun nestedTest() = <caret>Foo(2, "2")
}
@@ -0,0 +1,7 @@
// "Create class 'Foo'" "true"
class A {
class B {
fun test() = <caret>Foo(2, "2")
}
}
@@ -0,0 +1,8 @@
// "Create class 'Foo'" "true"
// ERROR: <html>Class 'Foo' must be declared abstract or implement abstract member<br/><b>public</b> <b>abstract</b> <b>fun</b> get(thisRef: A&lt;T&gt;, desc: kotlin.PropertyMetadata): B <i>defined in</i> kotlin.properties.ReadOnlyProperty</html>
open class B
class A<T>(val t: T) {
val x: B by <caret>Foo(t, "")
}
@@ -0,0 +1,8 @@
// "Create class 'Foo'" "true"
// DISABLE-ERRORS
open class B
class A<T>(val t: T) {
var x: B by <caret>Foo(t, "")
}
@@ -0,0 +1,3 @@
// "Create class 'Foo'" "true"
fun test() = <caret>Foo(2, "2")
@@ -0,0 +1,9 @@
// "Create class 'Foo'" "true"
class A<T>(val n: T) {
}
fun test() {
val a = A.<caret>Foo(2)
}
@@ -0,0 +1,5 @@
// "Create class 'Foo'" "true"
class A(n: Int)
fun test() = <caret>Foo(abc = 1, ghi = A(2), def = "s")
@@ -0,0 +1,11 @@
// "Create class 'Foo'" "false"
// ACTION: Create function 'Foo'
// ACTION: Add parameter to constructor 'Foo'
// ACTION: Split property declaration
// ERROR: Too many arguments for public constructor Foo(a: kotlin.Int) defined in Foo
class Foo(a: Int)
fun test() {
val a = Foo(2, <caret>"2")
}
@@ -0,0 +1,8 @@
// "Create class 'Foo'" "false"
// ACTION: Create function 'Foo'
// ACTION: Convert to block body
// ERROR: Unresolved reference: Foo
final class A
fun test(): A = <caret>Foo(2, "2")
@@ -0,0 +1,11 @@
// "Create class 'Foo'" "true"
// ERROR: <html>Type inference failed: <table><tr><td width="10%"></td><td align="right" colspan="2" style="white-space:nowrap;font-weight:bold;"><b>constructor</b> Foo&lt;U&gt;</td><td style="white-space:nowrap;font-weight:bold;">(</td><td align="right" style="white-space:nowrap;font-weight:bold;">u: U</td><td style="white-space:nowrap;font-weight:bold;">)</td><td style="white-space:nowrap;font-weight:bold;"></td></tr><tr><td colspan="7" style="white-space:nowrap;">cannot be applied to</td></tr><tr><td width="10%"></td><td style="white-space:nowrap;"></td><td style="white-space:nowrap;"></td><td style="white-space:nowrap;"><b>(</b></td><td align="right" style="white-space:nowrap;"><font color=red><b>U</b></font></td><td style="white-space:nowrap;"><b>)</b></td></tr></table></html>
// ERROR: <html>Type mismatch.<table><tr><td>Required:</td><td>U</td></tr><tr><td>Found:</td><td>U</td></tr></table></html>
class A<T>(val n: T) {
}
fun test<U>(u: U) {
val a = A(u).<caret>Foo(u)
}
@@ -0,0 +1,5 @@
// "Create class 'Foo'" "true"
fun test() {
val a = <caret>Foo(2, "2") { (p: Int) -> p + 1 }
}
@@ -0,0 +1,5 @@
// "Create class 'Foo'" "true"
fun test() {
val a = <caret>Foo { (p: Int) -> p + 1 }
}
@@ -0,0 +1,9 @@
// "Create class 'Foo'" "false"
// ACTION: Create function 'Foo'
// ACTION: Replace with infix function call
// ACTION: Split property declaration
// ERROR: Unresolved reference: Foo
fun test() {
val a = 2.<caret>Foo(1)
}
@@ -0,0 +1,11 @@
// "Create class 'Foo'" "false"
// ACTION: Create function 'Foo'
// ACTION: Remove parameter 's'
// ACTION: Split property declaration
// ERROR: No value passed for parameter s
class Foo(i: Int, s: String)
fun test() {
val a = Foo(2<caret>)
}
@@ -0,0 +1,9 @@
// "Create class 'Foo'" "true"
object A {
}
fun test() {
val a = A.<caret>Foo(2)
}
@@ -0,0 +1,5 @@
// "Create class 'Foo'" "true"
package Foo
fun test() = <caret>Foo(2, "2")
@@ -0,0 +1,9 @@
// "Create class 'Foo'" "true"
class A<T>(val n: T) {
}
fun test() {
val a = A(1).<caret>Foo(2)
}
@@ -0,0 +1,5 @@
// "Create class 'Foo'" "true"
open class A
fun test(): A = <caret>Foo(2, "2")
@@ -0,0 +1,6 @@
// "Create class 'Foo'" "true"
// ERROR: No value passed for parameter n
open class A(n: Int)
fun test(): A = <caret>Foo(2, "2")
@@ -0,0 +1,5 @@
// "Create class 'Foo'" "true"
trait A
fun test(): A = <caret>Foo(2, "2")
@@ -0,0 +1,5 @@
// "Create class 'Foo'" "true"
class A<T>(val n: T) {
fun test() = this.<caret>Foo(2, "2")
}
@@ -0,0 +1,7 @@
// "Create class 'Foo'" "true"
class A<T>(val n: T) {
}
fun <U> A<U>.test() = this.<caret>Foo(2, "2")
@@ -0,0 +1,7 @@
// "Create class 'Foo'" "true"
class A<T>(val n: T) {
inner class B<U>(val m: U) {
fun test() = this.<caret>Foo(2, "2")
}
}
@@ -0,0 +1,7 @@
// "Create class 'Foo'" "true"
class A<T>(val n: T) {
inner class B<U>(val m: U) {
fun test() = this@A.<caret>Foo(2, "2")
}
}
@@ -0,0 +1,6 @@
// "Create annotation 'bar'" "true"
// ERROR: Unresolved reference: foo
[foo(1, "2", <caret>bar<String, Int>("3", 4))] fun test() {
}
@@ -0,0 +1,6 @@
// "Create annotation 'bar'" "true"
// ERROR: Unresolved reference: foo
[foo(1, "2", <caret>bar("3"))] fun test() {
}
@@ -0,0 +1,6 @@
// "Create annotation 'bar'" "true"
// ERROR: Unresolved reference: foo
[foo(1, "2", <caret>bar(fooBar = "3"))] fun test() {
}
@@ -0,0 +1,5 @@
// "Create class 'Foo'" "true"
fun test() {
<caret>Foo(2, "2")
}
@@ -0,0 +1,8 @@
// "Create class 'Foo'" "false"
// ACTION: Create function 'Foo'
// ACTION: Convert to expression body
// ERROR: Unresolved reference: Foo
fun test(): Int {
return A().<caret>Foo(1, "2")
}
@@ -0,0 +1,13 @@
// "Create class 'Foo'" "true"
class B<T>(val t: T) {
class Foo<U, V>(u: U, v: V) {
}
}
class A<T>(val b: B<T>) {
fun test() = B.Foo<Int, String>(2, "2")
}
@@ -0,0 +1,15 @@
// "Create class 'Foo'" "true"
// ERROR: <html>Type mismatch.<table><tr><td>Required:</td><td>V</td></tr><tr><td>Found:</td><td>kotlin.String</td></tr></table></html>
// ERROR: An integer literal does not conform to the expected type U
class B<T>(val t: T) {
inner class Foo<U, V>(u: U, v: V) {
}
}
class A<T>(val b: B<T>) {
fun test() = b.Foo<Int, String>(2, "2")
}
@@ -0,0 +1,14 @@
// "Create class 'Foo'" "true"
// ERROR: <html>Type mismatch.<table><tr><td>Required:</td><td>U</td></tr><tr><td>Found:</td><td>kotlin.String</td></tr></table></html>
class B<T>(val t: T) {
inner class Foo<U>(i: Int, u: U) {
}
}
class A<T>(val b: B<T>) {
fun test() = b.Foo<String>(2, "2")
}
@@ -0,0 +1,15 @@
// "Create class 'Foo'" "true"
// ERROR: <html>Type mismatch.<table><tr><td>Required:</td><td>W</td></tr><tr><td>Found:</td><td>kotlin.String</td></tr></table></html>
// ERROR: An integer literal does not conform to the expected type V
class B<T>(val t: T) {
inner class Foo<U, V, W>(v: V, w: W) {
}
}
class A<T>(val b: B<T>) {
fun test() = b.Foo<T, Int, String>(2, "2")
}
@@ -0,0 +1,13 @@
// "Create class 'Foo'" "true"
class B<T>(val t: T) {
class Foo<U>(i: Int, u: U) {
}
}
class A<T>(val b: B<T>) {
fun test() = B.Foo<String>(2, "2")
}
@@ -0,0 +1,7 @@
// "Create class 'Foo'" "true"
fun test() = Foo<String, Int>(2, "2")
class Foo<T, U>(u: U, t: T) {
}
@@ -0,0 +1,7 @@
// "Create class 'Foo'" "true"
fun test() = Foo<String, Int, Boolean>(2, "2")
class Foo<T, U, V>(u: U, t: T) {
}
@@ -0,0 +1,7 @@
// "Create class 'Foo'" "true"
fun test() = Foo<String, Int>(2, "2")
class Foo<T, U>(u: U, t: T) {
}
@@ -0,0 +1,7 @@
// "Create class 'Foo'" "true"
fun test() = Foo<Int>(2, "2")
class Foo<T>(t: T, s: String) {
}
@@ -0,0 +1,11 @@
// "Create class 'Foo'" "true"
open class A {
}
fun test(a: A): A = Foo<A, Int>(a, 1)
class Foo<T, U>(a: T, u: U) : A() {
}
@@ -0,0 +1,9 @@
// "Create class 'Foo'" "true"
class B<T>(val t: T) {
}
class A<T>(val b: B<T>) {
fun test() = B.<caret>Foo<Int, String>(2, "2")
}
@@ -0,0 +1,11 @@
// "Create class 'Foo'" "true"
// ERROR: <html>Type mismatch.<table><tr><td>Required:</td><td>V</td></tr><tr><td>Found:</td><td>kotlin.String</td></tr></table></html>
// ERROR: An integer literal does not conform to the expected type U
class B<T>(val t: T) {
}
class A<T>(val b: B<T>) {
fun test() = b.<caret>Foo<Int, String>(2, "2")
}
@@ -0,0 +1,10 @@
// "Create class 'Foo'" "true"
// ERROR: <html>Type mismatch.<table><tr><td>Required:</td><td>U</td></tr><tr><td>Found:</td><td>kotlin.String</td></tr></table></html>
class B<T>(val t: T) {
}
class A<T>(val b: B<T>) {
fun test() = b.<caret>Foo<String>(2, "2")
}
@@ -0,0 +1,11 @@
// "Create class 'Foo'" "true"
// ERROR: <html>Type mismatch.<table><tr><td>Required:</td><td>W</td></tr><tr><td>Found:</td><td>kotlin.String</td></tr></table></html>
// ERROR: An integer literal does not conform to the expected type V
class B<T>(val t: T) {
}
class A<T>(val b: B<T>) {
fun test() = b.<caret>Foo<T, Int, String>(2, "2")
}
@@ -0,0 +1,9 @@
// "Create class 'Foo'" "true"
class B<T>(val t: T) {
}
class A<T>(val b: B<T>) {
fun test() = B.<caret>Foo<String>(2, "2")
}
@@ -0,0 +1,7 @@
// "Create class 'Foo'" "false"
// ACTION: Create function 'Foo'
// ERROR: Unresolved reference: Foo
class A<T>(val items: List<T>) {
fun test() = items.<caret>Foo<Int, String>(2, "2")
}
@@ -0,0 +1,3 @@
// "Create class 'Foo'" "true"
fun test() = <caret>Foo<String, Int>(2, "2")
@@ -0,0 +1,3 @@
// "Create class 'Foo'" "true"
fun test() = <caret>Foo<String, Int, Boolean>(2, "2")
@@ -0,0 +1,3 @@
// "Create class 'Foo'" "true"
fun test() = <caret>Foo<kotlin.String, Int>(2, "2")
@@ -0,0 +1,3 @@
// "Create class 'Foo'" "true"
fun test() = <caret>Foo<Int>(2, "2")
@@ -0,0 +1,7 @@
// "Create class 'Foo'" "true"
open class A {
}
fun test(a: A): A = <caret>Foo<A, Int>(a, 1)
@@ -0,0 +1,8 @@
// "Create function 'bar'" "false"
// ACTION: Create annotation 'bar'
// ERROR: Unresolved reference: foo
// ERROR: Unresolved reference: bar
[foo(1, "2", <caret>bar("3", 4))] fun test() {
}
@@ -230,13 +230,30 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes
@TestMetadata("idea/testData/quickfix/createFromUsage/createClass")
@TestDataPath("$PROJECT_ROOT")
@InnerTestClasses({})
@InnerTestClasses({CreateClass.CallExpression.class})
@RunWith(JUnit3RunnerWithInners.class)
public static class CreateClass extends AbstractQuickFixMultiFileTest {
public void testAllFilesPresentInCreateClass() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/createFromUsage/createClass"), Pattern.compile("^(\\w+)\\.before\\.Main\\.kt$"), true);
}
@TestMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression")
@TestDataPath("$PROJECT_ROOT")
@InnerTestClasses({})
@RunWith(JUnit3RunnerWithInners.class)
public static class CallExpression extends AbstractQuickFixMultiFileTest {
public void testAllFilesPresentInCallExpression() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/createFromUsage/createClass/callExpression"), Pattern.compile("^(\\w+)\\.before\\.Main\\.kt$"), true);
}
@TestMetadata("callWithJavaClassReceiver.before.Main.kt")
public void testCallWithJavaClassReceiver() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/callWithJavaClassReceiver.before.Main.kt");
doTestWithExtraFile(fileName);
}
}
}
@TestMetadata("idea/testData/quickfix/createFromUsage/createFunction")
@@ -628,13 +628,278 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
@TestMetadata("idea/testData/quickfix/createFromUsage/createClass")
@TestDataPath("$PROJECT_ROOT")
@InnerTestClasses({CreateClass.DelegationSpecifier.class, CreateClass.ImportDirective.class, CreateClass.ReferenceExpression.class, CreateClass.TypeReference.class})
@InnerTestClasses({CreateClass.CallExpression.class, CreateClass.DelegationSpecifier.class, CreateClass.ImportDirective.class, CreateClass.ReferenceExpression.class, CreateClass.TypeReference.class})
@RunWith(JUnit3RunnerWithInners.class)
public static class CreateClass extends AbstractQuickFixTest {
public void testAllFilesPresentInCreateClass() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/createFromUsage/createClass"), Pattern.compile("^before(\\w+)\\.kt$"), true);
}
@TestMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression")
@TestDataPath("$PROJECT_ROOT")
@InnerTestClasses({CallExpression.TypeArguments.class})
@RunWith(JUnit3RunnerWithInners.class)
public static class CallExpression extends AbstractQuickFixTest {
public void testAllFilesPresentInCallExpression() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/createFromUsage/createClass/callExpression"), Pattern.compile("^before(\\w+)\\.kt$"), true);
}
@TestMetadata("beforeCallInAnnotationEntry.kt")
public void testCallInAnnotationEntry() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/beforeCallInAnnotationEntry.kt");
doTest(fileName);
}
@TestMetadata("beforeCallInLambda.kt")
public void testCallInLambda() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/beforeCallInLambda.kt");
doTest(fileName);
}
@TestMetadata("beforeCallInLocalFunNoReceiver.kt")
public void testCallInLocalFunNoReceiver() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/beforeCallInLocalFunNoReceiver.kt");
doTest(fileName);
}
@TestMetadata("beforeCallInMemberFunNoReceiver.kt")
public void testCallInMemberFunNoReceiver() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/beforeCallInMemberFunNoReceiver.kt");
doTest(fileName);
}
@TestMetadata("beforeCallInMemberValDelegateRuntime.kt")
public void testCallInMemberValDelegateRuntime() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/beforeCallInMemberValDelegateRuntime.kt");
doTest(fileName);
}
@TestMetadata("beforeCallInMemberVarDelegateRuntime.kt")
public void testCallInMemberVarDelegateRuntime() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/beforeCallInMemberVarDelegateRuntime.kt");
doTest(fileName);
}
@TestMetadata("beforeCallNoReceiver.kt")
public void testCallNoReceiver() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/beforeCallNoReceiver.kt");
doTest(fileName);
}
@TestMetadata("beforeCallWithClassQualifier.kt")
public void testCallWithClassQualifier() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/beforeCallWithClassQualifier.kt");
doTest(fileName);
}
@TestMetadata("beforeCallWithExplicitParamNames.kt")
public void testCallWithExplicitParamNames() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/beforeCallWithExplicitParamNames.kt");
doTest(fileName);
}
@TestMetadata("beforeCallWithExtraArgs.kt")
public void testCallWithExtraArgs() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/beforeCallWithExtraArgs.kt");
doTest(fileName);
}
@TestMetadata("beforeCallWithFinalSupertype.kt")
public void testCallWithFinalSupertype() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/beforeCallWithFinalSupertype.kt");
doTest(fileName);
}
@TestMetadata("beforeCallWithGenericReceiver.kt")
public void testCallWithGenericReceiver() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/beforeCallWithGenericReceiver.kt");
doTest(fileName);
}
@TestMetadata("beforeCallWithLambdaArg.kt")
public void testCallWithLambdaArg() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/beforeCallWithLambdaArg.kt");
doTest(fileName);
}
@TestMetadata("beforeCallWithLambdaArgOnly.kt")
public void testCallWithLambdaArgOnly() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/beforeCallWithLambdaArgOnly.kt");
doTest(fileName);
}
@TestMetadata("beforeCallWithLibClassQualifier.kt")
public void testCallWithLibClassQualifier() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/beforeCallWithLibClassQualifier.kt");
doTest(fileName);
}
@TestMetadata("beforeCallWithMissingArgs.kt")
public void testCallWithMissingArgs() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/beforeCallWithMissingArgs.kt");
doTest(fileName);
}
@TestMetadata("beforeCallWithObjectQualifier.kt")
public void testCallWithObjectQualifier() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/beforeCallWithObjectQualifier.kt");
doTest(fileName);
}
@TestMetadata("beforeCallWithPackageName.kt")
public void testCallWithPackageName() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/beforeCallWithPackageName.kt");
doTest(fileName);
}
@TestMetadata("beforeCallWithReceiver.kt")
public void testCallWithReceiver() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/beforeCallWithReceiver.kt");
doTest(fileName);
}
@TestMetadata("beforeCallWithSuperclassNoConstructorParams.kt")
public void testCallWithSuperclassNoConstructorParams() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/beforeCallWithSuperclassNoConstructorParams.kt");
doTest(fileName);
}
@TestMetadata("beforeCallWithSuperclassWithConstructorParams.kt")
public void testCallWithSuperclassWithConstructorParams() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/beforeCallWithSuperclassWithConstructorParams.kt");
doTest(fileName);
}
@TestMetadata("beforeCallWithSupertrait.kt")
public void testCallWithSupertrait() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/beforeCallWithSupertrait.kt");
doTest(fileName);
}
@TestMetadata("beforeCallWithThisReceiverInClass.kt")
public void testCallWithThisReceiverInClass() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/beforeCallWithThisReceiverInClass.kt");
doTest(fileName);
}
@TestMetadata("beforeCallWithThisReceiverInExtension.kt")
public void testCallWithThisReceiverInExtension() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/beforeCallWithThisReceiverInExtension.kt");
doTest(fileName);
}
@TestMetadata("beforeCallWithThisReceiverInNestedClass1.kt")
public void testCallWithThisReceiverInNestedClass1() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/beforeCallWithThisReceiverInNestedClass1.kt");
doTest(fileName);
}
@TestMetadata("beforeCallWithThisReceiverInNestedClass2.kt")
public void testCallWithThisReceiverInNestedClass2() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/beforeCallWithThisReceiverInNestedClass2.kt");
doTest(fileName);
}
@TestMetadata("beforeCallWithTypeArgsInAnnotationEntry.kt")
public void testCallWithTypeArgsInAnnotationEntry() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/beforeCallWithTypeArgsInAnnotationEntry.kt");
doTest(fileName);
}
@TestMetadata("beforeSingleArgCallInAnnotationEntry.kt")
public void testSingleArgCallInAnnotationEntry() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/beforeSingleArgCallInAnnotationEntry.kt");
doTest(fileName);
}
@TestMetadata("beforeSingleNamedArgCallInAnnotationEntry.kt")
public void testSingleNamedArgCallInAnnotationEntry() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/beforeSingleNamedArgCallInAnnotationEntry.kt");
doTest(fileName);
}
@TestMetadata("beforeUnusedCallResult.kt")
public void testUnusedCallResult() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/beforeUnusedCallResult.kt");
doTest(fileName);
}
@TestMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/typeArguments")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class TypeArguments extends AbstractQuickFixTest {
public void testAllFilesPresentInTypeArguments() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/createFromUsage/createClass/callExpression/typeArguments"), Pattern.compile("^before(\\w+)\\.kt$"), true);
}
@TestMetadata("beforeClassMember.kt")
public void testClassMember() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/typeArguments/beforeClassMember.kt");
doTest(fileName);
}
@TestMetadata("beforeClassMemberInner.kt")
public void testClassMemberInner() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/typeArguments/beforeClassMemberInner.kt");
doTest(fileName);
}
@TestMetadata("beforeClassMemberInnerPartialSubstitution.kt")
public void testClassMemberInnerPartialSubstitution() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/typeArguments/beforeClassMemberInnerPartialSubstitution.kt");
doTest(fileName);
}
@TestMetadata("beforeClassMemberInnerWithReceiverArg.kt")
public void testClassMemberInnerWithReceiverArg() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/typeArguments/beforeClassMemberInnerWithReceiverArg.kt");
doTest(fileName);
}
@TestMetadata("beforeClassMemberPartialSubstitution.kt")
public void testClassMemberPartialSubstitution() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/typeArguments/beforeClassMemberPartialSubstitution.kt");
doTest(fileName);
}
@TestMetadata("beforeExtension.kt")
public void testExtension() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/typeArguments/beforeExtension.kt");
doTest(fileName);
}
@TestMetadata("beforeNoReceiver.kt")
public void testNoReceiver() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/typeArguments/beforeNoReceiver.kt");
doTest(fileName);
}
@TestMetadata("beforeNoReceiverExtraArgs.kt")
public void testNoReceiverExtraArgs() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/typeArguments/beforeNoReceiverExtraArgs.kt");
doTest(fileName);
}
@TestMetadata("beforeNoReceiverLongName.kt")
public void testNoReceiverLongName() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/typeArguments/beforeNoReceiverLongName.kt");
doTest(fileName);
}
@TestMetadata("beforeNoReceiverPartialSubstitution.kt")
public void testNoReceiverPartialSubstitution() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/typeArguments/beforeNoReceiverPartialSubstitution.kt");
doTest(fileName);
}
@TestMetadata("beforeWithExpectedTypeNoReceiver.kt")
public void testWithExpectedTypeNoReceiver() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/callExpression/typeArguments/beforeWithExpectedTypeNoReceiver.kt");
doTest(fileName);
}
}
}
@TestMetadata("idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -1137,6 +1402,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/createFromUsage/createFunction/call"), Pattern.compile("^before(\\w+)\\.kt$"), true);
}
@TestMetadata("beforeCallInAnnotationEntry.kt")
public void testCallInAnnotationEntry() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createFunction/call/beforeCallInAnnotationEntry.kt");
doTest(fileName);
}
@TestMetadata("beforeCallWithLambdaArg.kt")
public void testCallWithLambdaArg() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createFunction/call/beforeCallWithLambdaArg.kt");