Fix Quickfix for missing operator adds infix modifier to created function (#1012)

Fixes #KT-14907
This commit is contained in:
Kirill Rakhman
2017-01-09 12:03:22 +01:00
committed by Dmitry Jemerov
parent af1ed78e17
commit 406bac684c
15 changed files with 19 additions and 18 deletions
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2015 JetBrains s.r.o. * Copyright 2010-2017 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.types.expressions.OperatorConventions import org.jetbrains.kotlin.types.expressions.OperatorConventions
import java.util.* import java.util.*
object CreateBinaryOperationActionFactory: CreateCallableMemberFromUsageFactory<KtBinaryExpression>() { object CreateBinaryOperationActionFactory : CreateCallableMemberFromUsageFactory<KtBinaryExpression>() {
override fun getElementOfInterest(diagnostic: Diagnostic): KtBinaryExpression? { override fun getElementOfInterest(diagnostic: Diagnostic): KtBinaryExpression? {
return diagnostic.psiElement.parent as? KtBinaryExpression return diagnostic.psiElement.parent as? KtBinaryExpression
} }
@@ -54,8 +54,9 @@ object CreateBinaryOperationActionFactory: CreateCallableMemberFromUsageFactory<
else -> TypeInfo(element, Variance.OUT_VARIANCE) else -> TypeInfo(element, Variance.OUT_VARIANCE)
} }
val parameters = Collections.singletonList(ParameterInfo(TypeInfo(argumentExpr, Variance.IN_VARIANCE))) val parameters = Collections.singletonList(ParameterInfo(TypeInfo(argumentExpr, Variance.IN_VARIANCE)))
val isOperator = token != KtTokens.IDENTIFIER
return FunctionInfo(operationName, receiverType, returnType, parameterInfos = parameters, return FunctionInfo(operationName, receiverType, returnType, parameterInfos = parameters,
isOperator = token != KtTokens.IDENTIFIER, isOperator = isOperator,
isInfix = true) isInfix = !isOperator)
} }
} }
@@ -1,7 +1,7 @@
// "Create member function 'A.compareTo'" "true" // "Create member function 'A.compareTo'" "true"
class A<T>(val n: T) { class A<T>(val n: T) {
infix operator fun compareTo(t: T): Int { operator fun compareTo(t: T): Int {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
} }
} }
@@ -1,7 +1,7 @@
// "Create member function 'A.contains'" "true" // "Create member function 'A.contains'" "true"
class A<T>(val n: T) { class A<T>(val n: T) {
infix operator fun contains(t: T): Boolean { operator fun contains(t: T): Boolean {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
} }
} }
@@ -1,7 +1,7 @@
// "Create member function 'A.compareTo'" "true" // "Create member function 'A.compareTo'" "true"
class A<T>(val n: T) { class A<T>(val n: T) {
infix operator fun compareTo(t: T): Int { operator fun compareTo(t: T): Int {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
} }
} }
@@ -1,7 +1,7 @@
// "Create member function 'A.contains'" "true" // "Create member function 'A.contains'" "true"
class A<T>(val n: T) { class A<T>(val n: T) {
infix operator fun contains(t: T): Boolean { operator fun contains(t: T): Boolean {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
} }
} }
@@ -1,7 +1,7 @@
// "Create member function 'A.plusAssign'" "true" // "Create member function 'A.plusAssign'" "true"
class A<T>(val n: T) { class A<T>(val n: T) {
infix operator fun plusAssign(t: T) { operator fun plusAssign(t: T) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
} }
} }
@@ -2,7 +2,7 @@
class A<T>(val n: T) { class A<T>(val n: T) {
operator fun unaryPlus(): A<T> = throw Exception() operator fun unaryPlus(): A<T> = throw Exception()
infix operator fun plus(t: T): A<T> { operator fun plus(t: T): A<T> {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
} }
} }
@@ -1,7 +1,7 @@
// "Create member function 'A.plus'" "true" // "Create member function 'A.plus'" "true"
class A<T>(val n: T) { class A<T>(val n: T) {
infix operator fun plus(t: T): A<T> { operator fun plus(t: T): A<T> {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
} }
} }
@@ -2,7 +2,7 @@
class A<T>(val n: T) { class A<T>(val n: T) {
fun plus(i: Int, s: String): A<T> = throw Exception() fun plus(i: Int, s: String): A<T> = throw Exception()
infix operator fun plus(t: T): A<T> { operator fun plus(t: T): A<T> {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
} }
} }
@@ -7,6 +7,6 @@ fun test() {
val a: A<Int> = 2 + A(1) val a: A<Int> = 2 + A(1)
} }
private infix operator fun Int.plus(a: A<Int>): A<Int> { private operator fun Int.plus(a: A<Int>): A<Int> {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
} }
@@ -1,7 +1,7 @@
// "Create member function 'A.plus'" "true" // "Create member function 'A.plus'" "true"
class A<T>(val n: T) { class A<T>(val n: T) {
infix operator fun plus(t: T): A<T> { operator fun plus(t: T): A<T> {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
} }
} }
@@ -1,7 +1,7 @@
// "Create member function 'A.plus'" "true" // "Create member function 'A.plus'" "true"
class A<T>(val n: T) { class A<T>(val n: T) {
infix operator fun plus(i: Int): A<T> { operator fun plus(i: Int): A<T> {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
} }
} }
@@ -7,6 +7,6 @@ fun test() {
A() * "1" A() * "1"
} }
private infix operator fun A.times(s: String) { private operator fun A.times(s: String) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
} }
@@ -1,7 +1,7 @@
// "Create member function 'A.contains'" "true" // "Create member function 'A.contains'" "true"
class A<T>(val n: T) { class A<T>(val n: T) {
infix operator fun contains(t: T): Boolean { operator fun contains(t: T): Boolean {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
} }
} }
@@ -1,7 +1,7 @@
// "Create member function 'A.contains'" "true" // "Create member function 'A.contains'" "true"
class A<T>(val n: T) { class A<T>(val n: T) {
infix operator fun contains(t: T): Boolean { operator fun contains(t: T): Boolean {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
} }
} }