diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixRegistrar.java b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixRegistrar.java index 72d87114f73..1c51c136b49 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixRegistrar.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixRegistrar.java @@ -238,10 +238,13 @@ public class QuickFixRegistrar { 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(EXPRESSION_EXPECTED_PACKAGE_FOUND, CreateFunctionOrPropertyFromCallActionFactory.INSTANCE$); QuickFixes.factories.put(UNRESOLVED_REFERENCE, CreateLocalVariableActionFactory.INSTANCE$); + QuickFixes.factories.put(EXPRESSION_EXPECTED_PACKAGE_FOUND, CreateLocalVariableActionFactory.INSTANCE$); QuickFixes.factories.put(UNRESOLVED_REFERENCE, CreateParameterActionFactory.INSTANCE$); + QuickFixes.factories.put(EXPRESSION_EXPECTED_PACKAGE_FOUND, CreateParameterActionFactory.INSTANCE$); QuickFixes.factories.put(FUNCTION_EXPECTED, CreateInvokeFunctionActionFactory.INSTANCE$); diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateFunctionOrPropertyFromCallActionFactory.kt b/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateFunctionOrPropertyFromCallActionFactory.kt index 423834e3352..5534112a2b4 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateFunctionOrPropertyFromCallActionFactory.kt +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateFunctionOrPropertyFromCallActionFactory.kt @@ -23,12 +23,15 @@ import org.jetbrains.jet.lang.psi.JetClassBody 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 object CreateFunctionOrPropertyFromCallActionFactory : JetSingleIntentionActionFactory() { override fun createAction(diagnostic: Diagnostic): IntentionAction? { val diagElement = diagnostic.getPsiElement() + if (diagElement.getParentByType(javaClass()) != null) return null + val callExpr = when (diagnostic.getFactory()) { - in Errors.UNRESOLVED_REFERENCE_DIAGNOSTICS -> { + in Errors.UNRESOLVED_REFERENCE_DIAGNOSTICS, Errors.EXPRESSION_EXPECTED_PACKAGE_FOUND -> { val parent = diagElement.getParent() if (parent is JetCallExpression && parent.getCalleeExpression() == diagElement) parent else diagElement } @@ -52,10 +55,10 @@ object CreateFunctionOrPropertyFromCallActionFactory : JetSingleIntentionActionF if (callParent is JetQualifiedExpression && callParent.getSelectorExpression() == callExpr) callParent else callExpr val context = AnalyzerFacadeWithCache.getContextForElement(callExpr) - val receiver = callExpr.getCall(context)?.getExplicitReceiver() ?: return null + val receiver = callExpr.getCall(context)?.getExplicitReceiver() val receiverType = when (receiver) { - ReceiverValue.NO_RECEIVER -> TypeInfo.Empty + null, ReceiverValue.NO_RECEIVER -> TypeInfo.Empty is Qualifier -> { val qualifierType = context[BindingContext.EXPRESSION_TYPE, receiver.expression] ?: return null TypeInfo(qualifierType, Variance.IN_VARIANCE) diff --git a/idea/testData/quickfix/createFromUsage/createFunction/call/afterFunWithPackageName.kt b/idea/testData/quickfix/createFromUsage/createFunction/call/afterFunWithPackageName.kt new file mode 100644 index 00000000000..a56526cc5c5 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createFunction/call/afterFunWithPackageName.kt @@ -0,0 +1,11 @@ +// "Create function 'foo' from usage" "true" + +package foo + +fun test() { + foo(2, "2") +} + +fun foo(i: Int, s: String) { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/createFunction/call/beforeFunWithPackageName.kt b/idea/testData/quickfix/createFromUsage/createFunction/call/beforeFunWithPackageName.kt new file mode 100644 index 00000000000..d696f571c91 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createFunction/call/beforeFunWithPackageName.kt @@ -0,0 +1,7 @@ +// "Create function 'foo' from usage" "true" + +package foo + +fun test() { + foo(2, "2") +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/createVariable/localVariable/afterLocalWithPackageName.kt b/idea/testData/quickfix/createFromUsage/createVariable/localVariable/afterLocalWithPackageName.kt new file mode 100644 index 00000000000..eaad2f4871c --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/localVariable/afterLocalWithPackageName.kt @@ -0,0 +1,11 @@ +// "Create local variable 'foo'" "true" +// ACTION: Create parameter 'foo' +// ERROR: Variable 'foo' must be initialized + +package foo + +fun test(): Int { + val foo: Int + + return foo +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/createVariable/localVariable/beforeLocalWithPackageName.kt b/idea/testData/quickfix/createFromUsage/createVariable/localVariable/beforeLocalWithPackageName.kt new file mode 100644 index 00000000000..71b27a05bc9 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/localVariable/beforeLocalWithPackageName.kt @@ -0,0 +1,9 @@ +// "Create local variable 'foo'" "true" +// ACTION: Create parameter 'foo' +// ERROR: Variable 'foo' must be initialized + +package foo + +fun test(): Int { + return foo +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/createVariable/parameter/afterWithPackageName.kt b/idea/testData/quickfix/createFromUsage/createVariable/parameter/afterWithPackageName.kt new file mode 100644 index 00000000000..ae6e3b9276b --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/parameter/afterWithPackageName.kt @@ -0,0 +1,8 @@ +// "Create parameter 'foo'" "true" + +package foo + +fun test(n: Int, + foo: Int) { + val t: Int = foo +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeWithPackageName.kt b/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeWithPackageName.kt new file mode 100644 index 00000000000..e7719b16166 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeWithPackageName.kt @@ -0,0 +1,7 @@ +// "Create parameter 'foo'" "true" + +package foo + +fun test(n: Int) { + val t: Int = foo +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/createVariable/property/afterTopLevelValWithPackageName.kt b/idea/testData/quickfix/createFromUsage/createVariable/property/afterTopLevelValWithPackageName.kt new file mode 100644 index 00000000000..6e4ca6aea86 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/property/afterTopLevelValWithPackageName.kt @@ -0,0 +1,10 @@ +// "Create property 'foo' from usage" "true" +// ERROR: Property must be initialized + +package foo + +fun test(): Int { + return foo +} + +val foo: Int diff --git a/idea/testData/quickfix/createFromUsage/createVariable/property/beforeTopLevelValWithPackageName.kt b/idea/testData/quickfix/createFromUsage/createVariable/property/beforeTopLevelValWithPackageName.kt new file mode 100644 index 00000000000..e30e463ebfc --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/createVariable/property/beforeTopLevelValWithPackageName.kt @@ -0,0 +1,8 @@ +// "Create property 'foo' from usage" "true" +// ERROR: Property must be initialized + +package foo + +fun test(): Int { + return foo +} diff --git a/idea/tests/org/jetbrains/jet/plugin/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/quickfix/QuickFixTestGenerated.java index 254e149d1af..d493588a33f 100644 --- a/idea/tests/org/jetbrains/jet/plugin/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/plugin/quickfix/QuickFixTestGenerated.java @@ -814,6 +814,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { doTest(fileName); } + @TestMetadata("beforeFunWithPackageName.kt") + public void testFunWithPackageName() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createFunction/call/beforeFunWithPackageName.kt"); + doTest(fileName); + } + @TestMetadata("beforeInLambda.kt") public void testInLambda() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createFunction/call/beforeInLambda.kt"); @@ -1263,6 +1269,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { doTest(fileName); } + @TestMetadata("beforeLocalWithPackageName.kt") + public void testLocalWithPackageName() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/localVariable/beforeLocalWithPackageName.kt"); + doTest(fileName); + } + @TestMetadata("beforeOnTopLevel.kt") public void testOnTopLevel() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/localVariable/beforeOnTopLevel.kt"); @@ -1495,6 +1507,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { doTest(fileName); } + @TestMetadata("beforeWithPackageName.kt") + public void testWithPackageName() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeWithPackageName.kt"); + doTest(fileName); + } + } @TestMetadata("idea/testData/quickfix/createFromUsage/createVariable/property") @@ -1565,6 +1583,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { doTest(fileName); } + @TestMetadata("beforeTopLevelValWithPackageName.kt") + public void testTopLevelValWithPackageName() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/property/beforeTopLevelValWithPackageName.kt"); + doTest(fileName); + } + @TestMetadata("beforeValOnClassNoClassObject.kt") public void testValOnClassNoClassObject() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/property/beforeValOnClassNoClassObject.kt");