Create From Usage: Support EXPRESSION_EXPECTED_PACKAGE_FOUND diagnostic
This commit is contained in:
@@ -238,10 +238,13 @@ public class QuickFixRegistrar {
|
|||||||
QuickFixes.factories.put(UNRESOLVED_REFERENCE, CreateFunctionOrPropertyFromCallActionFactory.INSTANCE$);
|
QuickFixes.factories.put(UNRESOLVED_REFERENCE, CreateFunctionOrPropertyFromCallActionFactory.INSTANCE$);
|
||||||
QuickFixes.factories.put(NO_VALUE_FOR_PARAMETER, CreateFunctionOrPropertyFromCallActionFactory.INSTANCE$);
|
QuickFixes.factories.put(NO_VALUE_FOR_PARAMETER, CreateFunctionOrPropertyFromCallActionFactory.INSTANCE$);
|
||||||
QuickFixes.factories.put(TOO_MANY_ARGUMENTS, 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(UNRESOLVED_REFERENCE, CreateLocalVariableActionFactory.INSTANCE$);
|
||||||
|
QuickFixes.factories.put(EXPRESSION_EXPECTED_PACKAGE_FOUND, CreateLocalVariableActionFactory.INSTANCE$);
|
||||||
|
|
||||||
QuickFixes.factories.put(UNRESOLVED_REFERENCE, CreateParameterActionFactory.INSTANCE$);
|
QuickFixes.factories.put(UNRESOLVED_REFERENCE, CreateParameterActionFactory.INSTANCE$);
|
||||||
|
QuickFixes.factories.put(EXPRESSION_EXPECTED_PACKAGE_FOUND, CreateParameterActionFactory.INSTANCE$);
|
||||||
|
|
||||||
QuickFixes.factories.put(FUNCTION_EXPECTED, CreateInvokeFunctionActionFactory.INSTANCE$);
|
QuickFixes.factories.put(FUNCTION_EXPECTED, CreateInvokeFunctionActionFactory.INSTANCE$);
|
||||||
|
|
||||||
|
|||||||
+6
-3
@@ -23,12 +23,15 @@ import org.jetbrains.jet.lang.psi.JetClassBody
|
|||||||
import org.jetbrains.jet.lang.psi.JetFile
|
import org.jetbrains.jet.lang.psi.JetFile
|
||||||
import org.jetbrains.jet.lang.psi.psiUtil.getAssignmentByLHS
|
import org.jetbrains.jet.lang.psi.psiUtil.getAssignmentByLHS
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||||
|
import org.jetbrains.jet.lang.psi.JetTypeReference
|
||||||
|
|
||||||
object CreateFunctionOrPropertyFromCallActionFactory : JetSingleIntentionActionFactory() {
|
object CreateFunctionOrPropertyFromCallActionFactory : JetSingleIntentionActionFactory() {
|
||||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
||||||
val diagElement = diagnostic.getPsiElement()
|
val diagElement = diagnostic.getPsiElement()
|
||||||
|
if (diagElement.getParentByType(javaClass<JetTypeReference>()) != null) return null
|
||||||
|
|
||||||
val callExpr = when (diagnostic.getFactory()) {
|
val callExpr = when (diagnostic.getFactory()) {
|
||||||
in Errors.UNRESOLVED_REFERENCE_DIAGNOSTICS -> {
|
in Errors.UNRESOLVED_REFERENCE_DIAGNOSTICS, Errors.EXPRESSION_EXPECTED_PACKAGE_FOUND -> {
|
||||||
val parent = diagElement.getParent()
|
val parent = diagElement.getParent()
|
||||||
if (parent is JetCallExpression && parent.getCalleeExpression() == diagElement) parent else diagElement
|
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
|
if (callParent is JetQualifiedExpression && callParent.getSelectorExpression() == callExpr) callParent else callExpr
|
||||||
|
|
||||||
val context = AnalyzerFacadeWithCache.getContextForElement(callExpr)
|
val context = AnalyzerFacadeWithCache.getContextForElement(callExpr)
|
||||||
val receiver = callExpr.getCall(context)?.getExplicitReceiver() ?: return null
|
val receiver = callExpr.getCall(context)?.getExplicitReceiver()
|
||||||
|
|
||||||
val receiverType = when (receiver) {
|
val receiverType = when (receiver) {
|
||||||
ReceiverValue.NO_RECEIVER -> TypeInfo.Empty
|
null, ReceiverValue.NO_RECEIVER -> TypeInfo.Empty
|
||||||
is Qualifier -> {
|
is Qualifier -> {
|
||||||
val qualifierType = context[BindingContext.EXPRESSION_TYPE, receiver.expression] ?: return null
|
val qualifierType = context[BindingContext.EXPRESSION_TYPE, receiver.expression] ?: return null
|
||||||
TypeInfo(qualifierType, Variance.IN_VARIANCE)
|
TypeInfo(qualifierType, Variance.IN_VARIANCE)
|
||||||
|
|||||||
@@ -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.
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// "Create function 'foo' from usage" "true"
|
||||||
|
|
||||||
|
package foo
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
<caret>foo(2, "2")
|
||||||
|
}
|
||||||
+11
@@ -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
|
||||||
|
}
|
||||||
+9
@@ -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 <caret>foo
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
|
||||||
|
package foo
|
||||||
|
|
||||||
|
fun test(n: Int,
|
||||||
|
foo: Int) {
|
||||||
|
val t: Int = foo
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
// "Create parameter 'foo'" "true"
|
||||||
|
|
||||||
|
package foo
|
||||||
|
|
||||||
|
fun test(n: Int) {
|
||||||
|
val t: Int = <caret>foo
|
||||||
|
}
|
||||||
+10
@@ -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
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
// "Create property 'foo' from usage" "true"
|
||||||
|
// ERROR: Property must be initialized
|
||||||
|
|
||||||
|
package foo
|
||||||
|
|
||||||
|
fun test(): Int {
|
||||||
|
return <caret>foo
|
||||||
|
}
|
||||||
@@ -814,6 +814,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("beforeInLambda.kt")
|
||||||
public void testInLambda() throws Exception {
|
public void testInLambda() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createFunction/call/beforeInLambda.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createFunction/call/beforeInLambda.kt");
|
||||||
@@ -1263,6 +1269,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("beforeOnTopLevel.kt")
|
||||||
public void testOnTopLevel() throws Exception {
|
public void testOnTopLevel() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/localVariable/beforeOnTopLevel.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/localVariable/beforeOnTopLevel.kt");
|
||||||
@@ -1495,6 +1507,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("idea/testData/quickfix/createFromUsage/createVariable/property")
|
||||||
@@ -1565,6 +1583,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("beforeValOnClassNoClassObject.kt")
|
||||||
public void testValOnClassNoClassObject() throws Exception {
|
public void testValOnClassNoClassObject() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/property/beforeValOnClassNoClassObject.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/property/beforeValOnClassNoClassObject.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user