diff --git a/idea/idea-analysis/src/org/jetbrains/jet/plugin/JetBundle.properties b/idea/idea-analysis/src/org/jetbrains/jet/plugin/JetBundle.properties index f2d25090879..0b5ffe4cb42 100644 --- a/idea/idea-analysis/src/org/jetbrains/jet/plugin/JetBundle.properties +++ b/idea/idea-analysis/src/org/jetbrains/jet/plugin/JetBundle.properties @@ -185,6 +185,7 @@ map.platform.class.to.kotlin.advertisement=Choose an appropriate Kotlin class map.platform.class.to.kotlin.family=Change to Kotlin class create.from.usage.family=Create from usage create.function.from.usage=Create function ''{0}'' from usage +create.property.from.usage=Create property ''{0}'' from usage create.local.variable.from.usage=Create local variable ''{0}'' create.parameter.from.usage=Create parameter ''{0}'' choose.target.class.or.trait.title=Choose target class or trait diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixRegistrar.java b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixRegistrar.java index 6cfa8173586..8fba22af954 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixRegistrar.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixRegistrar.java @@ -233,10 +233,10 @@ public class QuickFixRegistrar { QuickFixes.factories.put(NO_VALUE_FOR_PARAMETER, CreateBinaryOperationActionFactory.INSTANCE$); QuickFixes.factories.put(TOO_MANY_ARGUMENTS, CreateBinaryOperationActionFactory.INSTANCE$); - QuickFixes.factories.put(UNRESOLVED_REFERENCE_WRONG_RECEIVER, CreateFunctionFromCallActionFactory.INSTANCE$); - QuickFixes.factories.put(UNRESOLVED_REFERENCE, CreateFunctionFromCallActionFactory.INSTANCE$); - QuickFixes.factories.put(NO_VALUE_FOR_PARAMETER, CreateFunctionFromCallActionFactory.INSTANCE$); - QuickFixes.factories.put(TOO_MANY_ARGUMENTS, CreateFunctionFromCallActionFactory.INSTANCE$); + QuickFixes.factories.put(UNRESOLVED_REFERENCE_WRONG_RECEIVER, CreateFunctionOrPropertyFromCallActionFactory.INSTANCE$); + QuickFixes.factories.put(UNRESOLVED_REFERENCE, CreateFunctionOrPropertyFromCallActionFactory.INSTANCE$); + QuickFixes.factories.put(NO_VALUE_FOR_PARAMETER, CreateFunctionOrPropertyFromCallActionFactory.INSTANCE$); + QuickFixes.factories.put(TOO_MANY_ARGUMENTS, CreateFunctionOrPropertyFromCallActionFactory.INSTANCE$); QuickFixes.factories.put(UNRESOLVED_REFERENCE, CreateLocalVariableActionFactory.INSTANCE$); diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt b/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt index 51c0d1d8c78..aa1b0194193 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt @@ -298,9 +298,13 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { classBody = containingElement.add(psiFactory.createEmptyClassBody()) as JetClassBody containingElement.addBefore(psiFactory.createWhiteSpace(), classBody) } - val rBrace = classBody!!.getRBrace() - return (rBrace?.let { append(declaration, it, true) } - ?: append(declaration, classBody!!.getLastChild()!!, false)) as JetCallableDeclaration + + if (declaration is JetNamedFunction) { + val rBrace = classBody!!.getRBrace() + return (rBrace?.let { append(declaration, it, true) } + ?: append(declaration, classBody!!.getLastChild()!!, false)) as JetCallableDeclaration + } + return prepend(declaration, classBody!!.getLBrace()!!, true) as JetCallableDeclaration } is JetBlockExpression -> { diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/callableBuilder/CallableInfo.kt b/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/callableBuilder/CallableInfo.kt index 2f1b2500ff4..5a9d7035e76 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/callableBuilder/CallableInfo.kt +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/callableBuilder/CallableInfo.kt @@ -13,6 +13,7 @@ import org.jetbrains.jet.plugin.util.supertypes import org.jetbrains.jet.lang.types.TypeUtils import org.jetbrains.jet.lang.types.ErrorUtils import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns +import org.jetbrains.jet.lang.psi.JetElement /** * Represents a concrete type or a set of types yet to be inferred from an expression. @@ -75,6 +76,7 @@ class CallableInfo ( val kind: CallableKind, val receiverTypeInfo: TypeInfo, val returnTypeInfo: TypeInfo, + val possibleContainers: List, val parameterInfos: List = Collections.emptyList() ) { { @@ -83,14 +85,16 @@ class CallableInfo ( } fun createFunctionInfo(name: String, - receiverTypeInfo: TypeInfo, - returnTypeInfo: TypeInfo, - parameterInfos: List = Collections.emptyList()): CallableInfo { - return CallableInfo(name, CallableKind.FUNCTION, receiverTypeInfo, returnTypeInfo, parameterInfos) + receiverTypeInfo: TypeInfo, + returnTypeInfo: TypeInfo, + possibleContainers: List = Collections.emptyList(), + parameterInfos: List = Collections.emptyList()): CallableInfo { + return CallableInfo(name, CallableKind.FUNCTION, receiverTypeInfo, returnTypeInfo, possibleContainers, parameterInfos) } fun createPropertyInfo(name: String, - receiverTypeInfo: TypeInfo, - returnTypeInfo: TypeInfo): CallableInfo { - return CallableInfo(name, CallableKind.PROPERTY, receiverTypeInfo, returnTypeInfo) + receiverTypeInfo: TypeInfo, + returnTypeInfo: TypeInfo, + possibleContainers: List): CallableInfo { + return CallableInfo(name, CallableKind.PROPERTY, receiverTypeInfo, returnTypeInfo, possibleContainers) } \ No newline at end of file diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateBinaryOperationActionFactory.kt b/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateBinaryOperationActionFactory.kt index d23b8f0ad98..cbfbdf85b27 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateBinaryOperationActionFactory.kt +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateBinaryOperationActionFactory.kt @@ -38,6 +38,6 @@ public object CreateBinaryOperationActionFactory: JetSingleIntentionActionFactor else -> TypeInfo(callExpr, Variance.OUT_VARIANCE) } val parameters = Collections.singletonList(ParameterInfo(TypeInfo(argumentExpr, Variance.IN_VARIANCE))) - return CreateFunctionFromUsageFix(callExpr, createFunctionInfo(operationName, receiverType, returnType, parameters)) + return CreateFunctionFromUsageFix(callExpr, createFunctionInfo(operationName, receiverType, returnType, Collections.emptyList(), parameters)) } } \ No newline at end of file diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateFunctionFromUsageFix.kt b/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateFunctionFromUsageFix.kt index bdd1c7a6cd6..5eb4d222e2e 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateFunctionFromUsageFix.kt +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateFunctionFromUsageFix.kt @@ -17,7 +17,11 @@ import org.jetbrains.jet.plugin.quickfix.createFromUsage.callableBuilder.* public class CreateFunctionFromUsageFix(element: PsiElement, val functionInfo: CallableInfo) : CreateFromUsageFixBase(element) { override fun getText(): String { - return JetBundle.message("create.function.from.usage", functionInfo.name) + val key = when (functionInfo.kind) { + CallableKind.FUNCTION -> "create.function.from.usage" + CallableKind.PROPERTY -> "create.property.from.usage" + } + return JetBundle.message(key, functionInfo.name) } override fun invoke(project: Project, editor: Editor?, file: JetFile?) { @@ -42,7 +46,7 @@ public class CreateFunctionFromUsageFix(element: PsiElement, val functionInfo: C else { assert(functionInfo.receiverTypeInfo is TypeInfo.Empty, "No receiver type candidates: ${element.getText()} in ${file.getText()}") - chooseContainerElementIfNecessary(element.getExtractionContainers(), editor, popupTitle, true, { it }) { + chooseContainerElementIfNecessary(functionInfo.possibleContainers, editor, popupTitle, true, { it }) { val container = if (it is JetClassBody) it.getParent() as JetClassOrObject else it runBuilder(CallablePlacement.NoReceiver(container)) } diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateFunctionFromCallActionFactory.kt b/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateFunctionOrPropertyFromCallActionFactory.kt similarity index 56% rename from idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateFunctionFromCallActionFactory.kt rename to idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateFunctionOrPropertyFromCallActionFactory.kt index 8f28e63a209..80cba609b2e 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateFunctionFromCallActionFactory.kt +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateFunctionOrPropertyFromCallActionFactory.kt @@ -6,7 +6,6 @@ import com.intellij.codeInsight.intention.IntentionAction import org.jetbrains.jet.lang.psi.JetCallExpression import org.jetbrains.jet.lang.types.Variance import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns -import org.jetbrains.jet.plugin.quickfix.QuickFixUtil import org.jetbrains.jet.lang.psi.JetSimpleNameExpression import org.jetbrains.jet.lexer.JetTokens import org.jetbrains.jet.lang.psi.JetQualifiedExpression @@ -17,9 +16,13 @@ import org.jetbrains.jet.lang.resolve.scopes.receivers.Qualifier import org.jetbrains.jet.plugin.quickfix.createFromUsage.callableBuilder.* import org.jetbrains.jet.lang.diagnostics.Errors import org.jetbrains.jet.lang.psi.psiUtil.getParentByType -import org.jetbrains.jet.lang.psi.psiUtil.getParentByTypeAndBranch +import org.jetbrains.jet.lang.psi.JetExpression +import java.util.Collections +import org.jetbrains.jet.plugin.refactoring.getExtractionContainers +import org.jetbrains.jet.lang.psi.JetClassBody +import org.jetbrains.jet.lang.psi.JetFile -object CreateFunctionFromCallActionFactory : JetSingleIntentionActionFactory() { +object CreateFunctionOrPropertyFromCallActionFactory : JetSingleIntentionActionFactory() { override fun createAction(diagnostic: Diagnostic): IntentionAction? { val diagElement = diagnostic.getPsiElement() val callExpr = when (diagnostic.getFactory()) { @@ -32,10 +35,14 @@ object CreateFunctionFromCallActionFactory : JetSingleIntentionActionFactory() { Errors.TOO_MANY_ARGUMENTS -> diagElement.getParentByType(javaClass()) else -> throw AssertionError("Unexpected diagnostic: ${diagnostic.getFactory()}") - } - if (callExpr !is JetCallExpression) return null + } as? JetExpression ?: return null + + val calleeExpr = when (callExpr) { + is JetCallExpression -> callExpr.getCalleeExpression() + is JetSimpleNameExpression -> callExpr + else -> null + } as? JetSimpleNameExpression ?: return null - val calleeExpr = callExpr.getCalleeExpression() as? JetSimpleNameExpression ?: return null if (calleeExpr.getReferencedNameElementType() != JetTokens.IDENTIFIER) return null val callParent = callExpr.getParent() @@ -54,15 +61,34 @@ object CreateFunctionFromCallActionFactory : JetSingleIntentionActionFactory() { else -> TypeInfo(receiver.getType(), Variance.IN_VARIANCE) } - val anyType = KotlinBuiltIns.getInstance().getNullableAnyType() - val parameters = callExpr.getValueArguments().map { - ParameterInfo( - it.getArgumentExpression()?.let { TypeInfo(it, Variance.IN_VARIANCE) } ?: TypeInfo(anyType, Variance.IN_VARIANCE), - it.getArgumentName()?.getReferenceExpression()?.getReferencedName() - ) - } + val possibleContainers = + if (receiverType is TypeInfo.Empty) { + val containers = with(fullCallExpr.getExtractionContainers()) { + if (callExpr is JetCallExpression) this else filter { it is JetClassBody || it is JetFile } + } + if (containers.isNotEmpty()) containers else return null + } + else Collections.emptyList() val returnType = TypeInfo(fullCallExpr, Variance.OUT_VARIANCE) - return CreateFunctionFromUsageFix(callExpr, createFunctionInfo(calleeExpr.getReferencedName(), receiverType, returnType, parameters)) + + val callableInfo = when (callExpr) { + is JetCallExpression -> { + val anyType = KotlinBuiltIns.getInstance().getNullableAnyType() + val parameters = callExpr.getValueArguments().map { + ParameterInfo( + it.getArgumentExpression()?.let { TypeInfo(it, Variance.IN_VARIANCE) } ?: TypeInfo(anyType, Variance.IN_VARIANCE), + it.getArgumentName()?.getReferenceExpression()?.getReferencedName() + ) + } + createFunctionInfo(calleeExpr.getReferencedName(), receiverType, returnType, possibleContainers, parameters) + } + + is JetSimpleNameExpression -> createPropertyInfo(calleeExpr.getReferencedName(), receiverType, returnType, possibleContainers) + + else -> return null + } + + return CreateFunctionFromUsageFix(callExpr, callableInfo) } } \ No newline at end of file diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateGetFunctionActionFactory.kt b/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateGetFunctionActionFactory.kt index fd181870527..b1c995439a4 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateGetFunctionActionFactory.kt +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateGetFunctionActionFactory.kt @@ -7,6 +7,7 @@ import org.jetbrains.jet.plugin.quickfix.QuickFixUtil import org.jetbrains.jet.lang.psi.JetArrayAccessExpression import org.jetbrains.jet.lang.types.Variance import org.jetbrains.jet.plugin.quickfix.createFromUsage.callableBuilder.* +import java.util.Collections object CreateGetFunctionActionFactory : JetSingleIntentionActionFactory() { override fun createAction(diagnostic: Diagnostic): IntentionAction? { @@ -19,6 +20,6 @@ object CreateGetFunctionActionFactory : JetSingleIntentionActionFactory() { } val returnType = TypeInfo(accessExpr, Variance.OUT_VARIANCE) - return CreateFunctionFromUsageFix(accessExpr, createFunctionInfo("get", arrayType, returnType, parameters)) + return CreateFunctionFromUsageFix(accessExpr, createFunctionInfo("get", arrayType, returnType, Collections.emptyList(), parameters)) } } \ No newline at end of file diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateInvokeFunctionActionFactory.kt b/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateInvokeFunctionActionFactory.kt index 56962c3e1a1..73361d6164e 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateInvokeFunctionActionFactory.kt +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateInvokeFunctionActionFactory.kt @@ -10,6 +10,7 @@ import org.jetbrains.jet.lang.psi.JetCallExpression import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns import org.jetbrains.jet.lang.diagnostics.Errors import org.jetbrains.jet.plugin.quickfix.createFromUsage.callableBuilder.* +import java.util.Collections object CreateInvokeFunctionActionFactory : JetSingleIntentionActionFactory() { override fun createAction(diagnostic: Diagnostic): IntentionAction? { @@ -29,6 +30,6 @@ object CreateInvokeFunctionActionFactory : JetSingleIntentionActionFactory() { } val returnType = TypeInfo(callExpr, Variance.OUT_VARIANCE) - return CreateFunctionFromUsageFix(callExpr, createFunctionInfo("invoke", receiverType, returnType, parameters)) + return CreateFunctionFromUsageFix(callExpr, createFunctionInfo("invoke", receiverType, returnType, Collections.emptyList(), parameters)) } } diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateSetFunctionActionFactory.kt b/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateSetFunctionActionFactory.kt index c6164102c0a..5c4353455a6 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateSetFunctionActionFactory.kt +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateSetFunctionActionFactory.kt @@ -10,6 +10,7 @@ import java.util.ArrayList import org.jetbrains.jet.lang.psi.JetBinaryExpression import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns import org.jetbrains.jet.plugin.quickfix.createFromUsage.callableBuilder.* +import java.util.Collections object CreateSetFunctionActionFactory : JetSingleIntentionActionFactory() { override fun createAction(diagnostic: Diagnostic): IntentionAction? { @@ -27,6 +28,6 @@ object CreateSetFunctionActionFactory : JetSingleIntentionActionFactory() { parameters.add(ParameterInfo(valType, "value")) val returnType = TypeInfo(KotlinBuiltIns.getInstance().getUnitType(), Variance.OUT_VARIANCE) - return CreateFunctionFromUsageFix(accessExpr, createFunctionInfo("set", arrayType, returnType, parameters)) + return CreateFunctionFromUsageFix(accessExpr, createFunctionInfo("set", arrayType, returnType, Collections.emptyList(), parameters)) } } \ No newline at end of file diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createVariable/CreateLocalVariableActionFactory.kt b/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createVariable/CreateLocalVariableActionFactory.kt index 985456cdc69..a905a835320 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createVariable/CreateLocalVariableActionFactory.kt +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createVariable/CreateLocalVariableActionFactory.kt @@ -25,6 +25,8 @@ import org.jetbrains.jet.lang.psi.JetPropertyAccessor import org.jetbrains.jet.lang.psi.JetElement import org.jetbrains.jet.plugin.intentions.ConvertToBlockBodyAction import org.jetbrains.jet.lang.psi.JetDeclarationWithBody +import org.jetbrains.jet.plugin.refactoring.getExtractionContainers +import org.jetbrains.jet.lang.psi.JetClassBody object CreateLocalVariableActionFactory: JetSingleIntentionActionFactory() { override fun createAction(diagnostic: Diagnostic): IntentionAction? { @@ -35,7 +37,9 @@ object CreateLocalVariableActionFactory: JetSingleIntentionActionFactory() { .filter { it is JetBlockExpression || it is JetDeclarationWithBody } .firstOrNull() as? JetElement ?: return null - val propertyInfo = createPropertyInfo(refExpr.getReferencedName(), TypeInfo.Empty, TypeInfo(refExpr, Variance.OUT_VARIANCE)) + val containers = refExpr.getExtractionContainers().filterNot { it is JetClassBody || it is JetFile } + val propertyInfo = + createPropertyInfo(refExpr.getReferencedName(), TypeInfo.Empty, TypeInfo(refExpr, Variance.OUT_VARIANCE), containers) return object: CreateFromUsageFixBase(refExpr) { override fun getText(): String = JetBundle.message("create.local.variable.from.usage", propertyInfo.name) diff --git a/idea/testData/quickfix/autoImports/noImportForPrivateClass.before.Main.kt b/idea/testData/quickfix/autoImports/noImportForPrivateClass.before.Main.kt index c4b9a46068a..c643483bf22 100644 --- a/idea/testData/quickfix/autoImports/noImportForPrivateClass.before.Main.kt +++ b/idea/testData/quickfix/autoImports/noImportForPrivateClass.before.Main.kt @@ -1,6 +1,7 @@ // "class com.intellij.codeInsight.daemon.impl.quickfix.ImportClassFixBase" "false" // ACTION: Create local variable 'PrivateClass' // ACTION: Create parameter 'PrivateClass' +// ACTION: Create property 'PrivateClass' from usage // ERROR: Unresolved reference: PrivateClass fun test() { diff --git a/idea/testData/quickfix/createFromUsage/createVariable/localVariable/beforeInClass.kt b/idea/testData/quickfix/createFromUsage/createVariable/localVariable/beforeInClass.kt index 1d209062a30..17a79e62a9a 100644 --- a/idea/testData/quickfix/createFromUsage/createVariable/localVariable/beforeInClass.kt +++ b/idea/testData/quickfix/createFromUsage/createVariable/localVariable/beforeInClass.kt @@ -1,5 +1,6 @@ // "Create local variable 'foo'" "false" // ACTION: Create parameter 'foo' +// ACTION: Create property 'foo' from usage // ERROR: Unresolved reference: foo class A { diff --git a/idea/testData/quickfix/createFromUsage/createVariable/localVariable/beforeOnTopLevel.kt b/idea/testData/quickfix/createFromUsage/createVariable/localVariable/beforeOnTopLevel.kt index bbcf3b207e4..9b26afa8d04 100644 --- a/idea/testData/quickfix/createFromUsage/createVariable/localVariable/beforeOnTopLevel.kt +++ b/idea/testData/quickfix/createFromUsage/createVariable/localVariable/beforeOnTopLevel.kt @@ -1,4 +1,5 @@ // "Create local variable 'foo'" "false" +// ACTION: Create property 'foo' from usage // ERROR: Unresolved reference: foo val t: Int = foo \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/createVariable/localVariable/beforeQualifiedInFun.kt b/idea/testData/quickfix/createFromUsage/createVariable/localVariable/beforeQualifiedInFun.kt index 506bc2ae5a0..38d63b5621b 100644 --- a/idea/testData/quickfix/createFromUsage/createVariable/localVariable/beforeQualifiedInFun.kt +++ b/idea/testData/quickfix/createFromUsage/createVariable/localVariable/beforeQualifiedInFun.kt @@ -1,4 +1,5 @@ // "Create local variable 'foo'" "false" +// ACTION: Create property 'foo' from usage // ACTION: Split property declaration // ERROR: Unresolved reference: foo diff --git a/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInAccessorInClassObject.kt b/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInAccessorInClassObject.kt index 603526716e1..1b03f756871 100644 --- a/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInAccessorInClassObject.kt +++ b/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInAccessorInClassObject.kt @@ -1,6 +1,7 @@ // "Create parameter 'foo'" "false" // ACTION: Convert to expression body // ACTION: Create local variable 'foo' +// ACTION: Create property 'foo' from usage // ERROR: Unresolved reference: foo class A { diff --git a/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInAccessorInObject.kt b/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInAccessorInObject.kt index f1b7bb547dd..a08c82bb5f1 100644 --- a/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInAccessorInObject.kt +++ b/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInAccessorInObject.kt @@ -1,6 +1,7 @@ // "Create parameter 'foo'" "false" // ACTION: Convert to expression body // ACTION: Create local variable 'foo' +// ACTION: Create property 'foo' from usage // ERROR: Unresolved reference: foo object A { diff --git a/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInAccessorInTrait.kt b/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInAccessorInTrait.kt index 133988a22b2..d7ceb4533ae 100644 --- a/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInAccessorInTrait.kt +++ b/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInAccessorInTrait.kt @@ -1,6 +1,7 @@ // "Create parameter 'foo'" "false" // ACTION: Convert to expression body // ACTION: Create local variable 'foo' +// ACTION: Create property 'foo' from usage // ERROR: Unresolved reference: foo trait A { diff --git a/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInAccessorNoClass.kt b/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInAccessorNoClass.kt index fe65f26eb97..40a09f17e0e 100644 --- a/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInAccessorNoClass.kt +++ b/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInAccessorNoClass.kt @@ -1,6 +1,7 @@ // "Create parameter 'foo'" "false" // ACTION: Convert to expression body // ACTION: Create local variable 'foo' +// ACTION: Create property 'foo' from usage // ERROR: Unresolved reference: foo val test: Int get() { diff --git a/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInGenAccessorInClass.kt b/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInGenAccessorInClass.kt index e885816cb20..78839639522 100644 --- a/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInGenAccessorInClass.kt +++ b/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInGenAccessorInClass.kt @@ -1,6 +1,7 @@ // "Create parameter 'foo'" "false" // ACTION: Convert to expression body // ACTION: Create local variable 'foo' +// ACTION: Create property 'foo' from usage // ERROR: Unresolved reference: foo class A { diff --git a/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInGenAccessorInGenClass.kt b/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInGenAccessorInGenClass.kt index 068083341d1..cdbfa87626f 100644 --- a/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInGenAccessorInGenClass.kt +++ b/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInGenAccessorInGenClass.kt @@ -1,6 +1,7 @@ // "Create parameter 'foo'" "false" // ACTION: Convert to expression body // ACTION: Create local variable 'foo' +// ACTION: Create property 'foo' from usage // ERROR: Unresolved reference: foo class A { diff --git a/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInGenPropertyInitializerInClass.kt b/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInGenPropertyInitializerInClass.kt index 3b1a4a2973e..e2a7a45d88f 100644 --- a/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInGenPropertyInitializerInClass.kt +++ b/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInGenPropertyInitializerInClass.kt @@ -1,5 +1,6 @@ // "Create parameter 'foo'" "false" // ERROR: Unresolved reference: foo +// ACTION: Create property 'foo' from usage class A { val test: T = foo diff --git a/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInGenPropertyInitializerInGenClass.kt b/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInGenPropertyInitializerInGenClass.kt index a9663cd93f8..369afdcad87 100644 --- a/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInGenPropertyInitializerInGenClass.kt +++ b/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInGenPropertyInitializerInGenClass.kt @@ -1,4 +1,5 @@ // "Create parameter 'foo'" "false" +// ACTION: Create property 'foo' from usage // ERROR: Unresolved reference: foo class A { diff --git a/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInPropertyInitializerInClassObject.kt b/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInPropertyInitializerInClassObject.kt index 0a7ebd0a406..b03bfbb822b 100644 --- a/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInPropertyInitializerInClassObject.kt +++ b/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInPropertyInitializerInClassObject.kt @@ -1,4 +1,5 @@ // "Create parameter 'foo'" "false" +// ACTION: Create property 'foo' from usage // ERROR: Unresolved reference: foo class A { diff --git a/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInPropertyInitializerInObject.kt b/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInPropertyInitializerInObject.kt index 153dd275601..2c0347835c6 100644 --- a/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInPropertyInitializerInObject.kt +++ b/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInPropertyInitializerInObject.kt @@ -1,4 +1,5 @@ // "Create parameter 'foo'" "false" +// ACTION: Create property 'foo' from usage // ERROR: Unresolved reference: foo object A { diff --git a/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInPropertyInitializerNoClass.kt b/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInPropertyInitializerNoClass.kt index 53dc31dea12..a242938b754 100644 --- a/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInPropertyInitializerNoClass.kt +++ b/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInPropertyInitializerNoClass.kt @@ -1,4 +1,5 @@ // "Create parameter 'foo'" "false" +// ACTION: Create property 'foo' from usage // ERROR: Unresolved reference: foo val test: Int = foo \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeQualifiedInFun.kt b/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeQualifiedInFun.kt index 59a29b62fc2..2a41b670499 100644 --- a/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeQualifiedInFun.kt +++ b/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeQualifiedInFun.kt @@ -1,5 +1,6 @@ // "Create parameter 'foo'" "false" // ACTION: Split property declaration +// ACTION: Create property 'foo' from usage // ERROR: Unresolved reference: foo class A diff --git a/idea/testData/quickfix/createFromUsage/createVariable/property/afterInconsistentTypes.kt b/idea/testData/quickfix/createFromUsage/createVariable/property/afterInconsistentTypes.kt new file mode 100644 index 00000000000..abaab3090ce --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/property/afterInconsistentTypes.kt @@ -0,0 +1,12 @@ +// "Create property 'foo' from usage" "true" +// ERROR: Type mismatch.
Required:kotlin.Int
Found:A<kotlin.Int>
+// ERROR: Property must be initialized or be abstract + +class A(val n: T) { + val foo: Any + +} + +fun test(): Int { + return A(1).foo as A +} diff --git a/idea/testData/quickfix/createFromUsage/createVariable/property/afterLocalValNoReceiver.kt b/idea/testData/quickfix/createFromUsage/createVariable/property/afterLocalValNoReceiver.kt new file mode 100644 index 00000000000..f9291eab9dd --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/property/afterLocalValNoReceiver.kt @@ -0,0 +1,9 @@ +// "Create property 'foo' from usage" "true" + +fun test() { + val foo: Int + + fun nestedTest(): Int { + return foo + } +} diff --git a/idea/testData/quickfix/createFromUsage/createVariable/property/afterMemberValNoReceiver.kt b/idea/testData/quickfix/createFromUsage/createVariable/property/afterMemberValNoReceiver.kt new file mode 100644 index 00000000000..9ecd18c6e8f --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/property/afterMemberValNoReceiver.kt @@ -0,0 +1,12 @@ +// "Create property 'foo' from usage" "true" +// ERROR: Property must be initialized or be abstract + +class A { + class B { + val foo: Int + + fun test(): Int { + return foo + } + } +} diff --git a/idea/testData/quickfix/createFromUsage/createVariable/property/afterObjectMemberValNoReceiver.kt b/idea/testData/quickfix/createFromUsage/createVariable/property/afterObjectMemberValNoReceiver.kt new file mode 100644 index 00000000000..123802741ef --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/property/afterObjectMemberValNoReceiver.kt @@ -0,0 +1,12 @@ +// "Create property 'foo' from usage" "true" +// ERROR: Property must be initialized or be abstract + +class A { + object B { + val foo: Int + + fun test(): Int { + return foo + } + } +} diff --git a/idea/testData/quickfix/createFromUsage/createVariable/property/afterThisInClass.kt b/idea/testData/quickfix/createFromUsage/createVariable/property/afterThisInClass.kt new file mode 100644 index 00000000000..9f0ff7b3689 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/property/afterThisInClass.kt @@ -0,0 +1,10 @@ +// "Create property 'foo' from usage" "true" +// ERROR: Property must be initialized or be abstract + +class A(val n: T) { + val foo: A + + fun test(): A { + return this.foo + } +} diff --git a/idea/testData/quickfix/createFromUsage/createVariable/property/afterThisInExtension.kt b/idea/testData/quickfix/createFromUsage/createVariable/property/afterThisInExtension.kt new file mode 100644 index 00000000000..a53e119d516 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/property/afterThisInExtension.kt @@ -0,0 +1,11 @@ +// "Create property 'foo' from usage" "true" +// ERROR: Property must be initialized or be abstract + +class A(val n: T) { + val foo: A + +} + +fun A.test(): A { + return this.foo +} diff --git a/idea/testData/quickfix/createFromUsage/createVariable/property/afterThisInNestedClass1.kt b/idea/testData/quickfix/createFromUsage/createVariable/property/afterThisInNestedClass1.kt new file mode 100644 index 00000000000..c7b177f5de5 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/property/afterThisInNestedClass1.kt @@ -0,0 +1,12 @@ +// "Create property 'foo' from usage" "true" +// ERROR: Property must be initialized or be abstract + +class A(val n: T) { + inner class B(val m: U) { + val foo: A + + fun test(): A { + return this.foo + } + } +} diff --git a/idea/testData/quickfix/createFromUsage/createVariable/property/afterThisInNestedClass2.kt b/idea/testData/quickfix/createFromUsage/createVariable/property/afterThisInNestedClass2.kt new file mode 100644 index 00000000000..9d8c1656ccb --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/property/afterThisInNestedClass2.kt @@ -0,0 +1,12 @@ +// "Create property 'foo' from usage" "true" +// ERROR: Property must be initialized or be abstract + +class A(val n: T) { + val foo: A + + inner class B(val m: U) { + fun test(): A { + return this@A.foo + } + } +} diff --git a/idea/testData/quickfix/createFromUsage/createVariable/property/afterTopLevelValNoReceiver.kt b/idea/testData/quickfix/createFromUsage/createVariable/property/afterTopLevelValNoReceiver.kt new file mode 100644 index 00000000000..bc2f32754a9 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/property/afterTopLevelValNoReceiver.kt @@ -0,0 +1,8 @@ +// "Create property 'foo' from usage" "true" +// ERROR: Property must be initialized + +fun test(): Int { + return foo +} + +val foo: Int diff --git a/idea/testData/quickfix/createFromUsage/createVariable/property/afterValOnClassObject.kt b/idea/testData/quickfix/createFromUsage/createVariable/property/afterValOnClassObject.kt new file mode 100644 index 00000000000..86a034f25cc --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/property/afterValOnClassObject.kt @@ -0,0 +1,14 @@ +// "Create property 'foo' from usage" "true" +// ERROR: Property must be initialized or be abstract + +class A(val n: T) { + class object { + + val foo: Int + + } +} + +fun test() { + val a: Int = A.foo +} diff --git a/idea/testData/quickfix/createFromUsage/createVariable/property/afterValOnLibObject.kt b/idea/testData/quickfix/createFromUsage/createVariable/property/afterValOnLibObject.kt new file mode 100644 index 00000000000..44efed131d2 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/property/afterValOnLibObject.kt @@ -0,0 +1,8 @@ +// "Create property 'foo' from usage" "true" +// ERROR: Property must be initialized + +fun test() { + val a: Int = Unit.foo +} + +val Unit.foo: Int diff --git a/idea/testData/quickfix/createFromUsage/createVariable/property/afterValOnLibType.kt b/idea/testData/quickfix/createFromUsage/createVariable/property/afterValOnLibType.kt new file mode 100644 index 00000000000..733f3b0cdf4 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/property/afterValOnLibType.kt @@ -0,0 +1,10 @@ +// "Create property 'foo' from usage" "true" +// ERROR: Property must be initialized + +class A(val n: T) + +fun test() { + val a: A = 2.foo +} + +val Int.foo: A diff --git a/idea/testData/quickfix/createFromUsage/createVariable/property/afterValOnUserObject.kt b/idea/testData/quickfix/createFromUsage/createVariable/property/afterValOnUserObject.kt new file mode 100644 index 00000000000..b75ed1c2dd4 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/property/afterValOnUserObject.kt @@ -0,0 +1,11 @@ +// "Create property 'foo' from usage" "true" +// ERROR: Property must be initialized or be abstract + +object A { + val foo: Int + +} + +fun test() { + val a: Int = A.foo +} diff --git a/idea/testData/quickfix/createFromUsage/createVariable/property/afterValOnUserType.kt b/idea/testData/quickfix/createFromUsage/createVariable/property/afterValOnUserType.kt new file mode 100644 index 00000000000..ee3d9f91c4f --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/property/afterValOnUserType.kt @@ -0,0 +1,11 @@ +// "Create property 'foo' from usage" "true" +// ERROR: Property must be initialized or be abstract + +class A(val n: T) { + val foo: A + +} + +fun test() { + val a: A = A(1).foo +} diff --git a/idea/testData/quickfix/createFromUsage/createVariable/property/afterValOnUserTypeWithTypeParams.kt b/idea/testData/quickfix/createFromUsage/createVariable/property/afterValOnUserTypeWithTypeParams.kt new file mode 100644 index 00000000000..e7eb85a8215 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/property/afterValOnUserTypeWithTypeParams.kt @@ -0,0 +1,11 @@ +// "Create property 'foo' from usage" "true" +// ERROR: Property must be initialized or be abstract + +class A(val n: T) { + val foo: A + +} + +fun test(u: U) { + val a: A = A(u).foo +} diff --git a/idea/testData/quickfix/createFromUsage/createVariable/property/beforeCallOnUserType.kt b/idea/testData/quickfix/createFromUsage/createVariable/property/beforeCallOnUserType.kt new file mode 100644 index 00000000000..7ff4ab6ef1b --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/property/beforeCallOnUserType.kt @@ -0,0 +1,13 @@ +// "Create property 'foo' from usage" "false" +// ACTION: Create function 'bar' from usage +// ACTION: Replace with infix function call +// ERROR: Unresolved reference: bar +// ERROR: Unresolved reference: foo + +class A(val n: T) { + val foo: Int = 1 +} + +fun test() { + A(1).bar(foo) +} diff --git a/idea/testData/quickfix/createFromUsage/createVariable/property/beforeInconsistentTypes.kt b/idea/testData/quickfix/createFromUsage/createVariable/property/beforeInconsistentTypes.kt new file mode 100644 index 00000000000..0c3c7b590c6 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/property/beforeInconsistentTypes.kt @@ -0,0 +1,9 @@ +// "Create property 'foo' from usage" "true" +// ERROR: Type mismatch.
Required:kotlin.Int
Found:A<kotlin.Int>
+// ERROR: Property must be initialized or be abstract + +class A(val n: T) + +fun test(): Int { + return A(1).foo as A +} diff --git a/idea/testData/quickfix/createFromUsage/createVariable/property/beforeLocalValNoReceiver.kt b/idea/testData/quickfix/createFromUsage/createVariable/property/beforeLocalValNoReceiver.kt new file mode 100644 index 00000000000..17699d290e1 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/property/beforeLocalValNoReceiver.kt @@ -0,0 +1,13 @@ +// "Create property 'foo' from usage" "false" +// ACTION: Convert to expression body +// ACTION: Disable 'Convert to Expression Body' +// ACTION: Edit intention settings +// ACTION: Create parameter 'foo' +// ACTION: Create local variable 'foo' +// ERROR: Unresolved reference: foo + +fun test() { + fun nestedTest(): Int { + return foo + } +} diff --git a/idea/testData/quickfix/createFromUsage/createVariable/property/beforeMemberValNoReceiver.kt b/idea/testData/quickfix/createFromUsage/createVariable/property/beforeMemberValNoReceiver.kt new file mode 100644 index 00000000000..517447139e0 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/property/beforeMemberValNoReceiver.kt @@ -0,0 +1,10 @@ +// "Create property 'foo' from usage" "true" +// ERROR: Property must be initialized or be abstract + +class A { + class B { + fun test(): Int { + return foo + } + } +} diff --git a/idea/testData/quickfix/createFromUsage/createVariable/property/beforeObjectMemberValNoReceiver.kt b/idea/testData/quickfix/createFromUsage/createVariable/property/beforeObjectMemberValNoReceiver.kt new file mode 100644 index 00000000000..21332038780 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/property/beforeObjectMemberValNoReceiver.kt @@ -0,0 +1,10 @@ +// "Create property 'foo' from usage" "true" +// ERROR: Property must be initialized or be abstract + +class A { + object B { + fun test(): Int { + return foo + } + } +} diff --git a/idea/testData/quickfix/createFromUsage/createVariable/property/beforeThisInClass.kt b/idea/testData/quickfix/createFromUsage/createVariable/property/beforeThisInClass.kt new file mode 100644 index 00000000000..2ebc9852e12 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/property/beforeThisInClass.kt @@ -0,0 +1,8 @@ +// "Create property 'foo' from usage" "true" +// ERROR: Property must be initialized or be abstract + +class A(val n: T) { + fun test(): A { + return this.foo + } +} diff --git a/idea/testData/quickfix/createFromUsage/createVariable/property/beforeThisInExtension.kt b/idea/testData/quickfix/createFromUsage/createVariable/property/beforeThisInExtension.kt new file mode 100644 index 00000000000..3232d9996b9 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/property/beforeThisInExtension.kt @@ -0,0 +1,8 @@ +// "Create property 'foo' from usage" "true" +// ERROR: Property must be initialized or be abstract + +class A(val n: T) + +fun A.test(): A { + return this.foo +} diff --git a/idea/testData/quickfix/createFromUsage/createVariable/property/beforeThisInNestedClass1.kt b/idea/testData/quickfix/createFromUsage/createVariable/property/beforeThisInNestedClass1.kt new file mode 100644 index 00000000000..79a01cee5b9 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/property/beforeThisInNestedClass1.kt @@ -0,0 +1,10 @@ +// "Create property 'foo' from usage" "true" +// ERROR: Property must be initialized or be abstract + +class A(val n: T) { + inner class B(val m: U) { + fun test(): A { + return this.foo + } + } +} diff --git a/idea/testData/quickfix/createFromUsage/createVariable/property/beforeThisInNestedClass2.kt b/idea/testData/quickfix/createFromUsage/createVariable/property/beforeThisInNestedClass2.kt new file mode 100644 index 00000000000..4fcb6ed5579 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/property/beforeThisInNestedClass2.kt @@ -0,0 +1,10 @@ +// "Create property 'foo' from usage" "true" +// ERROR: Property must be initialized or be abstract + +class A(val n: T) { + inner class B(val m: U) { + fun test(): A { + return this@A.foo + } + } +} diff --git a/idea/testData/quickfix/createFromUsage/createVariable/property/beforeTopLevelValNoReceiver.kt b/idea/testData/quickfix/createFromUsage/createVariable/property/beforeTopLevelValNoReceiver.kt new file mode 100644 index 00000000000..904ffa6c375 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/property/beforeTopLevelValNoReceiver.kt @@ -0,0 +1,6 @@ +// "Create property 'foo' from usage" "true" +// ERROR: Property must be initialized + +fun test(): Int { + return foo +} diff --git a/idea/testData/quickfix/createFromUsage/createVariable/property/beforeValOnClassObject.kt b/idea/testData/quickfix/createFromUsage/createVariable/property/beforeValOnClassObject.kt new file mode 100644 index 00000000000..38c3e10cbb1 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/property/beforeValOnClassObject.kt @@ -0,0 +1,12 @@ +// "Create property 'foo' from usage" "true" +// ERROR: Property must be initialized or be abstract + +class A(val n: T) { + class object { + + } +} + +fun test() { + val a: Int = A.foo +} diff --git a/idea/testData/quickfix/createFromUsage/createVariable/property/beforeValOnLibObject.kt b/idea/testData/quickfix/createFromUsage/createVariable/property/beforeValOnLibObject.kt new file mode 100644 index 00000000000..7617373f46e --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/property/beforeValOnLibObject.kt @@ -0,0 +1,6 @@ +// "Create property 'foo' from usage" "true" +// ERROR: Property must be initialized + +fun test() { + val a: Int = Unit.foo +} diff --git a/idea/testData/quickfix/createFromUsage/createVariable/property/beforeValOnLibType.kt b/idea/testData/quickfix/createFromUsage/createVariable/property/beforeValOnLibType.kt new file mode 100644 index 00000000000..a572b65c878 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/property/beforeValOnLibType.kt @@ -0,0 +1,8 @@ +// "Create property 'foo' from usage" "true" +// ERROR: Property must be initialized + +class A(val n: T) + +fun test() { + val a: A = 2.foo +} diff --git a/idea/testData/quickfix/createFromUsage/createVariable/property/beforeValOnUserObject.kt b/idea/testData/quickfix/createFromUsage/createVariable/property/beforeValOnUserObject.kt new file mode 100644 index 00000000000..30db135bb67 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/property/beforeValOnUserObject.kt @@ -0,0 +1,8 @@ +// "Create property 'foo' from usage" "true" +// ERROR: Property must be initialized or be abstract + +object A + +fun test() { + val a: Int = A.foo +} diff --git a/idea/testData/quickfix/createFromUsage/createVariable/property/beforeValOnUserType.kt b/idea/testData/quickfix/createFromUsage/createVariable/property/beforeValOnUserType.kt new file mode 100644 index 00000000000..be99e00488f --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/property/beforeValOnUserType.kt @@ -0,0 +1,8 @@ +// "Create property 'foo' from usage" "true" +// ERROR: Property must be initialized or be abstract + +class A(val n: T) + +fun test() { + val a: A = A(1).foo +} diff --git a/idea/testData/quickfix/createFromUsage/createVariable/property/beforeValOnUserTypeWithTypeParams.kt b/idea/testData/quickfix/createFromUsage/createVariable/property/beforeValOnUserTypeWithTypeParams.kt new file mode 100644 index 00000000000..dab4ad13c24 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/property/beforeValOnUserTypeWithTypeParams.kt @@ -0,0 +1,8 @@ +// "Create property 'foo' from usage" "true" +// ERROR: Property must be initialized or be abstract + +class A(val n: T) + +fun test(u: U) { + val a: A = A(u).foo +} diff --git a/idea/tests/org/jetbrains/jet/plugin/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/quickfix/QuickFixTestGenerated.java index 11b08dc63c5..5eca104a315 100644 --- a/idea/tests/org/jetbrains/jet/plugin/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/plugin/quickfix/QuickFixTestGenerated.java @@ -1164,7 +1164,7 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { @TestMetadata("idea/testData/quickfix/createFromUsage/createVariable") @TestDataPath("$PROJECT_ROOT") - @InnerTestClasses({CreateVariable.LocalVariable.class, CreateVariable.Parameter.class}) + @InnerTestClasses({CreateVariable.LocalVariable.class, CreateVariable.Parameter.class, CreateVariable.Property.class}) @RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class) public static class CreateVariable extends AbstractQuickFixTest { public void testAllFilesPresentInCreateVariable() throws Exception { @@ -1455,6 +1455,112 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { } + @TestMetadata("idea/testData/quickfix/createFromUsage/createVariable/property") + @TestDataPath("$PROJECT_ROOT") + @RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class) + public static class Property extends AbstractQuickFixTest { + public void testAllFilesPresentInProperty() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/createFromUsage/createVariable/property"), Pattern.compile("^before(\\w+)\\.kt$"), true); + } + + @TestMetadata("beforeCallOnUserType.kt") + public void testCallOnUserType() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/property/beforeCallOnUserType.kt"); + doTest(fileName); + } + + @TestMetadata("beforeInconsistentTypes.kt") + public void testInconsistentTypes() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/property/beforeInconsistentTypes.kt"); + doTest(fileName); + } + + @TestMetadata("beforeLocalValNoReceiver.kt") + public void testLocalValNoReceiver() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/property/beforeLocalValNoReceiver.kt"); + doTest(fileName); + } + + @TestMetadata("beforeMemberValNoReceiver.kt") + public void testMemberValNoReceiver() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/property/beforeMemberValNoReceiver.kt"); + doTest(fileName); + } + + @TestMetadata("beforeObjectMemberValNoReceiver.kt") + public void testObjectMemberValNoReceiver() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/property/beforeObjectMemberValNoReceiver.kt"); + doTest(fileName); + } + + @TestMetadata("beforeThisInClass.kt") + public void testThisInClass() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/property/beforeThisInClass.kt"); + doTest(fileName); + } + + @TestMetadata("beforeThisInExtension.kt") + public void testThisInExtension() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/property/beforeThisInExtension.kt"); + doTest(fileName); + } + + @TestMetadata("beforeThisInNestedClass1.kt") + public void testThisInNestedClass1() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/property/beforeThisInNestedClass1.kt"); + doTest(fileName); + } + + @TestMetadata("beforeThisInNestedClass2.kt") + public void testThisInNestedClass2() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/property/beforeThisInNestedClass2.kt"); + doTest(fileName); + } + + @TestMetadata("beforeTopLevelValNoReceiver.kt") + public void testTopLevelValNoReceiver() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/property/beforeTopLevelValNoReceiver.kt"); + doTest(fileName); + } + + @TestMetadata("beforeValOnClassObject.kt") + public void testValOnClassObject() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/property/beforeValOnClassObject.kt"); + doTest(fileName); + } + + @TestMetadata("beforeValOnLibObject.kt") + public void testValOnLibObject() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/property/beforeValOnLibObject.kt"); + doTest(fileName); + } + + @TestMetadata("beforeValOnLibType.kt") + public void testValOnLibType() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/property/beforeValOnLibType.kt"); + doTest(fileName); + } + + @TestMetadata("beforeValOnUserObject.kt") + public void testValOnUserObject() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/property/beforeValOnUserObject.kt"); + doTest(fileName); + } + + @TestMetadata("beforeValOnUserType.kt") + public void testValOnUserType() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/property/beforeValOnUserType.kt"); + doTest(fileName); + } + + @TestMetadata("beforeValOnUserTypeWithTypeParams.kt") + public void testValOnUserTypeWithTypeParams() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/property/beforeValOnUserTypeWithTypeParams.kt"); + doTest(fileName); + } + + } + } }