From 0582cf5db1c3af49a0a75a3facbc92c4bb5edbba Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Wed, 24 Sep 2014 15:54:31 +0400 Subject: [PATCH] Create Function From Usage: Quick-fix for binary operations --- .../plugin/quickfix/QuickFixRegistrar.java | 6 ++ .../CreateBinaryOperationActionFactory.kt | 42 ++++++++ .../createFunction/FunctionInfo.kt | 2 +- .../createFunction/functionBuilder.kt | 1 + .../afterCustomOperationOnUserType.kt | 11 +++ .../afterGreaterOrEqualOnUserType.kt | 11 +++ .../binaryOperations/afterInOnUserType.kt | 11 +++ .../binaryOperations/afterLessOnUserType.kt | 11 +++ .../binaryOperations/afterNotInOnUserType.kt | 11 +++ .../afterPlusAssignOnUserType.kt | 11 +++ .../binaryOperations/afterPlusExtraArgs.kt | 12 +++ .../afterPlusForAssignmentOnUserType.kt | 12 +++ .../binaryOperations/afterPlusMissingArgs.kt | 12 +++ .../binaryOperations/afterPlusOnLibType.kt | 10 ++ .../binaryOperations/afterPlusOnUserType.kt | 11 +++ .../afterPlusOnUserTypeWithTypeParams.kt | 11 +++ .../binaryOperations/afterWhenInOnUserType.kt | 13 +++ .../afterWhenNotInOnUserType.kt | 13 +++ .../beforeCustomOperationOnUserType.kt | 7 ++ .../beforeGreaterOrEqualOnUserType.kt | 7 ++ .../binaryOperations/beforeInOnUserType.kt | 7 ++ .../binaryOperations/beforeLessOnUserType.kt | 7 ++ .../binaryOperations/beforeNotInOnUserType.kt | 7 ++ .../beforePlusAssignOnUserType.kt | 7 ++ .../binaryOperations/beforePlusExtraArgs.kt | 9 ++ .../beforePlusForAssignmentOnUserType.kt | 8 ++ .../binaryOperations/beforePlusMissingArgs.kt | 9 ++ .../binaryOperations/beforePlusOnLibType.kt | 7 ++ .../binaryOperations/beforePlusOnUserType.kt | 7 ++ .../beforePlusOnUserTypeWithTypeParams.kt | 7 ++ .../beforeWhenInOnUserType.kt | 9 ++ .../beforeWhenNotInOnUserType.kt | 9 ++ .../quickfix/QuickFixTestGenerated.java | 96 ++++++++++++++++++- 33 files changed, 412 insertions(+), 2 deletions(-) create mode 100644 idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateBinaryOperationActionFactory.kt create mode 100644 idea/testData/quickfix/createFromUsage/binaryOperations/afterCustomOperationOnUserType.kt create mode 100644 idea/testData/quickfix/createFromUsage/binaryOperations/afterGreaterOrEqualOnUserType.kt create mode 100644 idea/testData/quickfix/createFromUsage/binaryOperations/afterInOnUserType.kt create mode 100644 idea/testData/quickfix/createFromUsage/binaryOperations/afterLessOnUserType.kt create mode 100644 idea/testData/quickfix/createFromUsage/binaryOperations/afterNotInOnUserType.kt create mode 100644 idea/testData/quickfix/createFromUsage/binaryOperations/afterPlusAssignOnUserType.kt create mode 100644 idea/testData/quickfix/createFromUsage/binaryOperations/afterPlusExtraArgs.kt create mode 100644 idea/testData/quickfix/createFromUsage/binaryOperations/afterPlusForAssignmentOnUserType.kt create mode 100644 idea/testData/quickfix/createFromUsage/binaryOperations/afterPlusMissingArgs.kt create mode 100644 idea/testData/quickfix/createFromUsage/binaryOperations/afterPlusOnLibType.kt create mode 100644 idea/testData/quickfix/createFromUsage/binaryOperations/afterPlusOnUserType.kt create mode 100644 idea/testData/quickfix/createFromUsage/binaryOperations/afterPlusOnUserTypeWithTypeParams.kt create mode 100644 idea/testData/quickfix/createFromUsage/binaryOperations/afterWhenInOnUserType.kt create mode 100644 idea/testData/quickfix/createFromUsage/binaryOperations/afterWhenNotInOnUserType.kt create mode 100644 idea/testData/quickfix/createFromUsage/binaryOperations/beforeCustomOperationOnUserType.kt create mode 100644 idea/testData/quickfix/createFromUsage/binaryOperations/beforeGreaterOrEqualOnUserType.kt create mode 100644 idea/testData/quickfix/createFromUsage/binaryOperations/beforeInOnUserType.kt create mode 100644 idea/testData/quickfix/createFromUsage/binaryOperations/beforeLessOnUserType.kt create mode 100644 idea/testData/quickfix/createFromUsage/binaryOperations/beforeNotInOnUserType.kt create mode 100644 idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusAssignOnUserType.kt create mode 100644 idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusExtraArgs.kt create mode 100644 idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusForAssignmentOnUserType.kt create mode 100644 idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusMissingArgs.kt create mode 100644 idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusOnLibType.kt create mode 100644 idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusOnUserType.kt create mode 100644 idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusOnUserTypeWithTypeParams.kt create mode 100644 idea/testData/quickfix/createFromUsage/binaryOperations/beforeWhenInOnUserType.kt create mode 100644 idea/testData/quickfix/createFromUsage/binaryOperations/beforeWhenNotInOnUserType.kt diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixRegistrar.java b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixRegistrar.java index 6c5c8b0e4d4..bc9c2867835 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixRegistrar.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixRegistrar.java @@ -222,6 +222,12 @@ public class QuickFixRegistrar { QuickFixes.factories.put(EXPECTED_TYPE_MISMATCH, changeFunctionLiteralReturnTypeFix); QuickFixes.factories.put(ASSIGNMENT_TYPE_MISMATCH, changeFunctionLiteralReturnTypeFix); + QuickFixes.factories.put(UNRESOLVED_REFERENCE_WRONG_RECEIVER, CreateBinaryOperationActionFactory.INSTANCE$); + QuickFixes.factories.put(UNRESOLVED_REFERENCE, CreateBinaryOperationActionFactory.INSTANCE$); + QuickFixes.factories.put(NONE_APPLICABLE, CreateBinaryOperationActionFactory.INSTANCE$); + QuickFixes.factories.put(NO_VALUE_FOR_PARAMETER, CreateBinaryOperationActionFactory.INSTANCE$); + QuickFixes.factories.put(TOO_MANY_ARGUMENTS, CreateBinaryOperationActionFactory.INSTANCE$); + QuickFixes.factories.put(TYPE_MISMATCH, new QuickFixFactoryForTypeMismatchError()); QuickFixes.factories.put(AUTOCAST_IMPOSSIBLE, CastExpressionFix.createFactoryForAutoCastImpossible()); 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 new file mode 100644 index 00000000000..087333160de --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/CreateBinaryOperationActionFactory.kt @@ -0,0 +1,42 @@ +package org.jetbrains.jet.plugin.quickfix.createFromUsage.createFunction + +import org.jetbrains.jet.plugin.quickfix.JetSingleIntentionActionFactory +import org.jetbrains.jet.lang.diagnostics.Diagnostic +import com.intellij.codeInsight.intention.IntentionAction +import org.jetbrains.jet.lang.psi.JetBinaryExpression +import org.jetbrains.jet.lang.types.expressions.OperatorConventions +import org.jetbrains.jet.lexer.JetToken +import org.jetbrains.jet.lang.types.Variance +import java.util.Collections +import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns +import org.jetbrains.jet.lexer.JetTokens + +public object CreateBinaryOperationActionFactory: JetSingleIntentionActionFactory() { + override fun createAction(diagnostic: Diagnostic): IntentionAction? { + val callExpr = diagnostic.getPsiElement().getParent() as? JetBinaryExpression ?: return null + val token = callExpr.getOperationToken() as JetToken + val operationName = when (token) { + JetTokens.IDENTIFIER -> callExpr.getOperationReference().getReferencedName() + else -> OperatorConventions.getNameForOperationSymbol(token)?.asString() + } ?: return null + val inOperation = token in OperatorConventions.IN_OPERATIONS + val comparisonOperation = token in OperatorConventions.COMPARISON_OPERATIONS + + val leftExpr = callExpr.getLeft() ?: return null + val rightExpr = callExpr.getRight() ?: return null + + val receiverExpr = if (inOperation) rightExpr else leftExpr + val argumentExpr = if (inOperation) leftExpr else rightExpr + + val builtIns = KotlinBuiltIns.getInstance() + + val receiverType = TypeInfo(receiverExpr, Variance.IN_VARIANCE) + val returnType = when { + inOperation -> TypeInfo.ByType(builtIns.getBooleanType(), Variance.INVARIANT, true) + comparisonOperation -> TypeInfo.ByType(builtIns.getIntType(), Variance.INVARIANT, true) + else -> TypeInfo(callExpr, Variance.OUT_VARIANCE) + } + val parameters = Collections.singletonList(ParameterInfo(TypeInfo(argumentExpr, Variance.IN_VARIANCE))) + return CreateFunctionFromUsageFix(callExpr, FunctionInfo(operationName, receiverType, returnType, parameters)) + } +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/FunctionInfo.kt b/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/FunctionInfo.kt index 3f68ab46c9d..7b8621486c0 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/FunctionInfo.kt +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/FunctionInfo.kt @@ -24,7 +24,7 @@ abstract class TypeInfo(val variance: Variance) { expression.guessTypes(context).flatMap { it.getPossibleSupertypes(variance) } } - class ByType(val theType: JetType, variance: Variance): TypeInfo(variance) { + class ByType(val theType: JetType, variance: Variance, val keepUnsubstituted: Boolean = false): TypeInfo(variance) { override val possibleNamesFromExpression: Array = ArrayUtil.EMPTY_STRING_ARRAY diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/functionBuilder.kt b/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/functionBuilder.kt index f09fad6fb60..52dbd92243b 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/functionBuilder.kt +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/createFromUsage/createFunction/functionBuilder.kt @@ -113,6 +113,7 @@ class FunctionBuilder(val config: FunctionBuilderConfiguration) { typeInfo: TypeInfo, substitutions: Array, scope: JetScope): List { + if (typeInfo is TypeInfo.ByType && typeInfo.keepUnsubstituted) return computeTypeCandidates(typeInfo) return typeCandidates.getOrPut(typeInfo) { val types = typeInfo.getPossibleTypes(currentFileContext).reverse() diff --git a/idea/testData/quickfix/createFromUsage/binaryOperations/afterCustomOperationOnUserType.kt b/idea/testData/quickfix/createFromUsage/binaryOperations/afterCustomOperationOnUserType.kt new file mode 100644 index 00000000000..cb39d4799ed --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/binaryOperations/afterCustomOperationOnUserType.kt @@ -0,0 +1,11 @@ +// "Create function 'foo' from usage" "true" + +class A(val n: T) { + fun foo(arg: T): A { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } +} + +fun test() { + val a: A = A(1) foo 2 +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/binaryOperations/afterGreaterOrEqualOnUserType.kt b/idea/testData/quickfix/createFromUsage/binaryOperations/afterGreaterOrEqualOnUserType.kt new file mode 100644 index 00000000000..8c6add0cbb5 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/binaryOperations/afterGreaterOrEqualOnUserType.kt @@ -0,0 +1,11 @@ +// "Create function 'compareTo' from usage" "true" + +class A(val n: T) { + fun compareTo(arg: T): Int { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } +} + +fun test() { + A(1) >= 2 +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/binaryOperations/afterInOnUserType.kt b/idea/testData/quickfix/createFromUsage/binaryOperations/afterInOnUserType.kt new file mode 100644 index 00000000000..e2bdade79ca --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/binaryOperations/afterInOnUserType.kt @@ -0,0 +1,11 @@ +// "Create function 'contains' from usage" "true" + +class A(val n: T) { + fun contains(arg: T): Boolean { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } +} + +fun test() { + 2 in A(1) +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/binaryOperations/afterLessOnUserType.kt b/idea/testData/quickfix/createFromUsage/binaryOperations/afterLessOnUserType.kt new file mode 100644 index 00000000000..b5f3bdb597f --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/binaryOperations/afterLessOnUserType.kt @@ -0,0 +1,11 @@ +// "Create function 'compareTo' from usage" "true" + +class A(val n: T) { + fun compareTo(arg: T): Int { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } +} + +fun test() { + A(1) < 2 +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/binaryOperations/afterNotInOnUserType.kt b/idea/testData/quickfix/createFromUsage/binaryOperations/afterNotInOnUserType.kt new file mode 100644 index 00000000000..54c914bf2bc --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/binaryOperations/afterNotInOnUserType.kt @@ -0,0 +1,11 @@ +// "Create function 'contains' from usage" "true" + +class A(val n: T) { + fun contains(arg: T): Boolean { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } +} + +fun test() { + 2 !in A(1) +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/binaryOperations/afterPlusAssignOnUserType.kt b/idea/testData/quickfix/createFromUsage/binaryOperations/afterPlusAssignOnUserType.kt new file mode 100644 index 00000000000..b35a70c8e01 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/binaryOperations/afterPlusAssignOnUserType.kt @@ -0,0 +1,11 @@ +// "Create function 'plusAssign' from usage" "true" + +class A(val n: T) { + fun plusAssign(arg: T): Unit { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } +} + +fun test() { + A(1) += 2 +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/binaryOperations/afterPlusExtraArgs.kt b/idea/testData/quickfix/createFromUsage/binaryOperations/afterPlusExtraArgs.kt new file mode 100644 index 00000000000..72110a178fc --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/binaryOperations/afterPlusExtraArgs.kt @@ -0,0 +1,12 @@ +// "Create function 'plus' from usage" "true" + +class A(val n: T) { + fun plus(): A = throw Exception() + fun plus(arg: T): A { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } +} + +fun test() { + val a: A = A(1) + 2 +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/binaryOperations/afterPlusForAssignmentOnUserType.kt b/idea/testData/quickfix/createFromUsage/binaryOperations/afterPlusForAssignmentOnUserType.kt new file mode 100644 index 00000000000..a1e45a4ecbf --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/binaryOperations/afterPlusForAssignmentOnUserType.kt @@ -0,0 +1,12 @@ +// "Create function 'plus' from usage" "true" + +class A(val n: T) { + fun plus(arg: T): A { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } +} + +fun test() { + var a = A(1) + a = a + 2 +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/binaryOperations/afterPlusMissingArgs.kt b/idea/testData/quickfix/createFromUsage/binaryOperations/afterPlusMissingArgs.kt new file mode 100644 index 00000000000..f7b5bc2aa1c --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/binaryOperations/afterPlusMissingArgs.kt @@ -0,0 +1,12 @@ +// "Create function 'plus' from usage" "true" + +class A(val n: T) { + fun plus(i: Int, s: String): A = throw Exception() + fun plus(arg: T): A { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } +} + +fun test() { + val a: A = A(1) + 2 +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/binaryOperations/afterPlusOnLibType.kt b/idea/testData/quickfix/createFromUsage/binaryOperations/afterPlusOnLibType.kt new file mode 100644 index 00000000000..610eeebfa20 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/binaryOperations/afterPlusOnLibType.kt @@ -0,0 +1,10 @@ +// "Create function 'plus' from usage" "true" + +class A(val n: T) + +fun test() { + val a: A = 2 + A(1) +} +fun Int.plus(A: A): A { + 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/binaryOperations/afterPlusOnUserType.kt b/idea/testData/quickfix/createFromUsage/binaryOperations/afterPlusOnUserType.kt new file mode 100644 index 00000000000..5580c4a1fc3 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/binaryOperations/afterPlusOnUserType.kt @@ -0,0 +1,11 @@ +// "Create function 'plus' from usage" "true" + +class A(val n: T) { + fun plus(arg: T): A { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } +} + +fun test() { + val a: A = A(1) + 2 +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/binaryOperations/afterPlusOnUserTypeWithTypeParams.kt b/idea/testData/quickfix/createFromUsage/binaryOperations/afterPlusOnUserTypeWithTypeParams.kt new file mode 100644 index 00000000000..106db3dd584 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/binaryOperations/afterPlusOnUserTypeWithTypeParams.kt @@ -0,0 +1,11 @@ +// "Create function 'plus' from usage" "true" + +class A(val n: T) { + fun plus(i: Int): A { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } +} + +fun test(u: U) { + val a: A = A(u) + 2 +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/binaryOperations/afterWhenInOnUserType.kt b/idea/testData/quickfix/createFromUsage/binaryOperations/afterWhenInOnUserType.kt new file mode 100644 index 00000000000..42eaff80114 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/binaryOperations/afterWhenInOnUserType.kt @@ -0,0 +1,13 @@ +// "Create function 'contains' from usage" "true" + +class A(val n: T) { + fun contains(arg: T): Boolean { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } +} + +fun test() { + when { + 2 in A(1) -> {} + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/binaryOperations/afterWhenNotInOnUserType.kt b/idea/testData/quickfix/createFromUsage/binaryOperations/afterWhenNotInOnUserType.kt new file mode 100644 index 00000000000..cf4c39bce87 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/binaryOperations/afterWhenNotInOnUserType.kt @@ -0,0 +1,13 @@ +// "Create function 'contains' from usage" "true" + +class A(val n: T) { + fun contains(arg: T): Boolean { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } +} + +fun test() { + when { + 2 !in A(1) -> {} + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/binaryOperations/beforeCustomOperationOnUserType.kt b/idea/testData/quickfix/createFromUsage/binaryOperations/beforeCustomOperationOnUserType.kt new file mode 100644 index 00000000000..6e4506d8c69 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/binaryOperations/beforeCustomOperationOnUserType.kt @@ -0,0 +1,7 @@ +// "Create function 'foo' from usage" "true" + +class A(val n: T) + +fun test() { + val a: A = A(1) foo 2 +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/binaryOperations/beforeGreaterOrEqualOnUserType.kt b/idea/testData/quickfix/createFromUsage/binaryOperations/beforeGreaterOrEqualOnUserType.kt new file mode 100644 index 00000000000..f97ce4416de --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/binaryOperations/beforeGreaterOrEqualOnUserType.kt @@ -0,0 +1,7 @@ +// "Create function 'compareTo' from usage" "true" + +class A(val n: T) + +fun test() { + A(1) >= 2 +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/binaryOperations/beforeInOnUserType.kt b/idea/testData/quickfix/createFromUsage/binaryOperations/beforeInOnUserType.kt new file mode 100644 index 00000000000..e6f1ebf5679 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/binaryOperations/beforeInOnUserType.kt @@ -0,0 +1,7 @@ +// "Create function 'contains' from usage" "true" + +class A(val n: T) + +fun test() { + 2 in A(1) +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/binaryOperations/beforeLessOnUserType.kt b/idea/testData/quickfix/createFromUsage/binaryOperations/beforeLessOnUserType.kt new file mode 100644 index 00000000000..ee06d1a9ddb --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/binaryOperations/beforeLessOnUserType.kt @@ -0,0 +1,7 @@ +// "Create function 'compareTo' from usage" "true" + +class A(val n: T) + +fun test() { + A(1) < 2 +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/binaryOperations/beforeNotInOnUserType.kt b/idea/testData/quickfix/createFromUsage/binaryOperations/beforeNotInOnUserType.kt new file mode 100644 index 00000000000..f6dbb7bd683 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/binaryOperations/beforeNotInOnUserType.kt @@ -0,0 +1,7 @@ +// "Create function 'contains' from usage" "true" + +class A(val n: T) + +fun test() { + 2 !in A(1) +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusAssignOnUserType.kt b/idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusAssignOnUserType.kt new file mode 100644 index 00000000000..679e414a248 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusAssignOnUserType.kt @@ -0,0 +1,7 @@ +// "Create function 'plusAssign' from usage" "true" + +class A(val n: T) + +fun test() { + A(1) += 2 +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusExtraArgs.kt b/idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusExtraArgs.kt new file mode 100644 index 00000000000..7fc7c527993 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusExtraArgs.kt @@ -0,0 +1,9 @@ +// "Create function 'plus' from usage" "true" + +class A(val n: T) { + fun plus(): A = throw Exception() +} + +fun test() { + val a: A = A(1) + 2 +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusForAssignmentOnUserType.kt b/idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusForAssignmentOnUserType.kt new file mode 100644 index 00000000000..d5fe3355a93 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusForAssignmentOnUserType.kt @@ -0,0 +1,8 @@ +// "Create function 'plus' from usage" "true" + +class A(val n: T) + +fun test() { + var a = A(1) + a = a + 2 +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusMissingArgs.kt b/idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusMissingArgs.kt new file mode 100644 index 00000000000..7c2beeb360d --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusMissingArgs.kt @@ -0,0 +1,9 @@ +// "Create function 'plus' from usage" "true" + +class A(val n: T) { + fun plus(i: Int, s: String): A = throw Exception() +} + +fun test() { + val a: A = A(1) + 2 +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusOnLibType.kt b/idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusOnLibType.kt new file mode 100644 index 00000000000..054fbc570f7 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusOnLibType.kt @@ -0,0 +1,7 @@ +// "Create function 'plus' from usage" "true" + +class A(val n: T) + +fun test() { + val a: A = 2 + A(1) +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusOnUserType.kt b/idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusOnUserType.kt new file mode 100644 index 00000000000..cf1b0343c74 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusOnUserType.kt @@ -0,0 +1,7 @@ +// "Create function 'plus' from usage" "true" + +class A(val n: T) + +fun test() { + val a: A = A(1) + 2 +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusOnUserTypeWithTypeParams.kt b/idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusOnUserTypeWithTypeParams.kt new file mode 100644 index 00000000000..98e0d156c3d --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusOnUserTypeWithTypeParams.kt @@ -0,0 +1,7 @@ +// "Create function 'plus' from usage" "true" + +class A(val n: T) + +fun test(u: U) { + val a: A = A(u) + 2 +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/binaryOperations/beforeWhenInOnUserType.kt b/idea/testData/quickfix/createFromUsage/binaryOperations/beforeWhenInOnUserType.kt new file mode 100644 index 00000000000..40e29ee5d02 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/binaryOperations/beforeWhenInOnUserType.kt @@ -0,0 +1,9 @@ +// "Create function 'contains' from usage" "true" + +class A(val n: T) + +fun test() { + when { + 2 in A(1) -> {} + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/binaryOperations/beforeWhenNotInOnUserType.kt b/idea/testData/quickfix/createFromUsage/binaryOperations/beforeWhenNotInOnUserType.kt new file mode 100644 index 00000000000..bbd41494536 --- /dev/null +++ b/idea/testData/quickfix/createFromUsage/binaryOperations/beforeWhenNotInOnUserType.kt @@ -0,0 +1,9 @@ +// "Create function 'contains' from usage" "true" + +class A(val n: T) + +fun test() { + when { + 2 !in A(1) -> {} + } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/plugin/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/quickfix/QuickFixTestGenerated.java index a6bc092b339..ed805b5cf0e 100644 --- a/idea/tests/org/jetbrains/jet/plugin/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/plugin/quickfix/QuickFixTestGenerated.java @@ -618,13 +618,107 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { @TestMetadata("idea/testData/quickfix/createFromUsage") @TestDataPath("$PROJECT_ROOT") - @InnerTestClasses({CreateFromUsage.Component.class, CreateFromUsage.Get.class, CreateFromUsage.HasNext.class, CreateFromUsage.Iterator.class, CreateFromUsage.Next.class, CreateFromUsage.Set.class}) + @InnerTestClasses({CreateFromUsage.BinaryOperations.class, CreateFromUsage.Component.class, CreateFromUsage.Get.class, CreateFromUsage.HasNext.class, CreateFromUsage.Iterator.class, CreateFromUsage.Next.class, CreateFromUsage.Set.class}) @RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class) public static class CreateFromUsage extends AbstractQuickFixTest { public void testAllFilesPresentInCreateFromUsage() throws Exception { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/createFromUsage"), Pattern.compile("^before(\\w+)\\.kt$"), true); } + @TestMetadata("idea/testData/quickfix/createFromUsage/binaryOperations") + @TestDataPath("$PROJECT_ROOT") + @RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class) + public static class BinaryOperations extends AbstractQuickFixTest { + public void testAllFilesPresentInBinaryOperations() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/createFromUsage/binaryOperations"), Pattern.compile("^before(\\w+)\\.kt$"), true); + } + + @TestMetadata("beforeCustomOperationOnUserType.kt") + public void testCustomOperationOnUserType() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/binaryOperations/beforeCustomOperationOnUserType.kt"); + doTest(fileName); + } + + @TestMetadata("beforeGreaterOrEqualOnUserType.kt") + public void testGreaterOrEqualOnUserType() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/binaryOperations/beforeGreaterOrEqualOnUserType.kt"); + doTest(fileName); + } + + @TestMetadata("beforeInOnUserType.kt") + public void testInOnUserType() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/binaryOperations/beforeInOnUserType.kt"); + doTest(fileName); + } + + @TestMetadata("beforeLessOnUserType.kt") + public void testLessOnUserType() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/binaryOperations/beforeLessOnUserType.kt"); + doTest(fileName); + } + + @TestMetadata("beforeNotInOnUserType.kt") + public void testNotInOnUserType() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/binaryOperations/beforeNotInOnUserType.kt"); + doTest(fileName); + } + + @TestMetadata("beforePlusAssignOnUserType.kt") + public void testPlusAssignOnUserType() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusAssignOnUserType.kt"); + doTest(fileName); + } + + @TestMetadata("beforePlusExtraArgs.kt") + public void testPlusExtraArgs() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusExtraArgs.kt"); + doTest(fileName); + } + + @TestMetadata("beforePlusForAssignmentOnUserType.kt") + public void testPlusForAssignmentOnUserType() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusForAssignmentOnUserType.kt"); + doTest(fileName); + } + + @TestMetadata("beforePlusMissingArgs.kt") + public void testPlusMissingArgs() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusMissingArgs.kt"); + doTest(fileName); + } + + @TestMetadata("beforePlusOnLibType.kt") + public void testPlusOnLibType() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusOnLibType.kt"); + doTest(fileName); + } + + @TestMetadata("beforePlusOnUserType.kt") + public void testPlusOnUserType() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusOnUserType.kt"); + doTest(fileName); + } + + @TestMetadata("beforePlusOnUserTypeWithTypeParams.kt") + public void testPlusOnUserTypeWithTypeParams() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/binaryOperations/beforePlusOnUserTypeWithTypeParams.kt"); + doTest(fileName); + } + + @TestMetadata("beforeWhenInOnUserType.kt") + public void testWhenInOnUserType() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/binaryOperations/beforeWhenInOnUserType.kt"); + doTest(fileName); + } + + @TestMetadata("beforeWhenNotInOnUserType.kt") + public void testWhenNotInOnUserType() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/binaryOperations/beforeWhenNotInOnUserType.kt"); + doTest(fileName); + } + + } + @TestMetadata("idea/testData/quickfix/createFromUsage/component") @TestDataPath("$PROJECT_ROOT") @RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class)