Skip to content

Commit 406bac6

Browse files
cypressiousyole
authored andcommitted
Fix Quickfix for missing operator adds infix modifier to created function (JetBrains#1012)
Fixes #KT-14907
1 parent af1ed78 commit 406bac6

15 files changed

+19
-18
lines changed

idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateBinaryOperationActionFactory.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2015 JetBrains s.r.o.
2+
* Copyright 2010-2017 JetBrains s.r.o.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.types.Variance
2626
import org.jetbrains.kotlin.types.expressions.OperatorConventions
2727
import java.util.*
2828

29-
object CreateBinaryOperationActionFactory: CreateCallableMemberFromUsageFactory<KtBinaryExpression>() {
29+
object CreateBinaryOperationActionFactory : CreateCallableMemberFromUsageFactory<KtBinaryExpression>() {
3030
override fun getElementOfInterest(diagnostic: Diagnostic): KtBinaryExpression? {
3131
return diagnostic.psiElement.parent as? KtBinaryExpression
3232
}
@@ -54,8 +54,9 @@ object CreateBinaryOperationActionFactory: CreateCallableMemberFromUsageFactory<
5454
else -> TypeInfo(element, Variance.OUT_VARIANCE)
5555
}
5656
val parameters = Collections.singletonList(ParameterInfo(TypeInfo(argumentExpr, Variance.IN_VARIANCE)))
57+
val isOperator = token != KtTokens.IDENTIFIER
5758
return FunctionInfo(operationName, receiverType, returnType, parameterInfos = parameters,
58-
isOperator = token != KtTokens.IDENTIFIER,
59-
isInfix = true)
59+
isOperator = isOperator,
60+
isInfix = !isOperator)
6061
}
6162
}

idea/testData/quickfix/createFromUsage/createFunction/binaryOperations/greaterOrEqualOnUserType.kt.after

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// "Create member function 'A.compareTo'" "true"
22

33
class A<T>(val n: T) {
4-
infix operator fun compareTo(t: T): Int {
4+
operator fun compareTo(t: T): Int {
55
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
66
}
77
}

idea/testData/quickfix/createFromUsage/createFunction/binaryOperations/inOnUserType.kt.after

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// "Create member function 'A.contains'" "true"
22

33
class A<T>(val n: T) {
4-
infix operator fun contains(t: T): Boolean {
4+
operator fun contains(t: T): Boolean {
55
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
66
}
77
}

idea/testData/quickfix/createFromUsage/createFunction/binaryOperations/lessOnUserType.kt.after

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// "Create member function 'A.compareTo'" "true"
22

33
class A<T>(val n: T) {
4-
infix operator fun compareTo(t: T): Int {
4+
operator fun compareTo(t: T): Int {
55
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
66
}
77
}

idea/testData/quickfix/createFromUsage/createFunction/binaryOperations/notInOnUserType.kt.after

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// "Create member function 'A.contains'" "true"
22

33
class A<T>(val n: T) {
4-
infix operator fun contains(t: T): Boolean {
4+
operator fun contains(t: T): Boolean {
55
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
66
}
77
}

idea/testData/quickfix/createFromUsage/createFunction/binaryOperations/plusAssignOnUserType.kt.after

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// "Create member function 'A.plusAssign'" "true"
22

33
class A<T>(val n: T) {
4-
infix operator fun plusAssign(t: T) {
4+
operator fun plusAssign(t: T) {
55
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
66
}
77
}

idea/testData/quickfix/createFromUsage/createFunction/binaryOperations/plusExtraArgs.kt.after

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class A<T>(val n: T) {
44
operator fun unaryPlus(): A<T> = throw Exception()
5-
infix operator fun plus(t: T): A<T> {
5+
operator fun plus(t: T): A<T> {
66
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
77
}
88
}

idea/testData/quickfix/createFromUsage/createFunction/binaryOperations/plusForAssignmentOnUserType.kt.after

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// "Create member function 'A.plus'" "true"
22

33
class A<T>(val n: T) {
4-
infix operator fun plus(t: T): A<T> {
4+
operator fun plus(t: T): A<T> {
55
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
66
}
77
}

idea/testData/quickfix/createFromUsage/createFunction/binaryOperations/plusMissingArgs.kt.after

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class A<T>(val n: T) {
44
fun plus(i: Int, s: String): A<T> = throw Exception()
5-
infix operator fun plus(t: T): A<T> {
5+
operator fun plus(t: T): A<T> {
66
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
77
}
88
}

idea/testData/quickfix/createFromUsage/createFunction/binaryOperations/plusOnLibType.kt.after

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ fun test() {
77
val a: A<Int> = 2 + A(1)
88
}
99

10-
private infix operator fun Int.plus(a: A<Int>): A<Int> {
10+
private operator fun Int.plus(a: A<Int>): A<Int> {
1111
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
1212
}

idea/testData/quickfix/createFromUsage/createFunction/binaryOperations/plusOnUserType.kt.after

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// "Create member function 'A.plus'" "true"
22

33
class A<T>(val n: T) {
4-
infix operator fun plus(t: T): A<T> {
4+
operator fun plus(t: T): A<T> {
55
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
66
}
77
}

idea/testData/quickfix/createFromUsage/createFunction/binaryOperations/plusOnUserTypeWithTypeParams.kt.after

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// "Create member function 'A.plus'" "true"
22

33
class A<T>(val n: T) {
4-
infix operator fun plus(i: Int): A<T> {
4+
operator fun plus(i: Int): A<T> {
55
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
66
}
77
}

idea/testData/quickfix/createFromUsage/createFunction/binaryOperations/typeMismatch.kt.after

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ fun test() {
77
A() * "1"
88
}
99

10-
private infix operator fun A.times(s: String) {
10+
private operator fun A.times(s: String) {
1111
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
1212
}

idea/testData/quickfix/createFromUsage/createFunction/binaryOperations/whenInOnUserType.kt.after

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// "Create member function 'A.contains'" "true"
22

33
class A<T>(val n: T) {
4-
infix operator fun contains(t: T): Boolean {
4+
operator fun contains(t: T): Boolean {
55
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
66
}
77
}

idea/testData/quickfix/createFromUsage/createFunction/binaryOperations/whenNotInOnUserType.kt.after

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// "Create member function 'A.contains'" "true"
22

33
class A<T>(val n: T) {
4-
infix operator fun contains(t: T): Boolean {
4+
operator fun contains(t: T): Boolean {
55
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
66
}
77
}

0 commit comments

Comments
 (0)