Rename unary plus() and minus() to unaryPlus() and unaryMinus()
This commit is contained in:
@@ -60,7 +60,7 @@ public fun Name.getOperationSymbolsToSearch(): Set<JetToken> {
|
||||
|
||||
if (isComponentLike(this)) return setOf(JetTokens.LPAR)
|
||||
|
||||
val unaryOp = UNARY_OPERATION_NAMES.inverse()[this]
|
||||
val unaryOp = UNARY_OPERATION_NAMES_WITH_DEPRECATED_INVERTED[this]
|
||||
if (unaryOp != null) return setOf(unaryOp)
|
||||
|
||||
val binaryOp = BINARY_OPERATION_NAMES.inverse()[this]
|
||||
|
||||
+6
-1
@@ -143,7 +143,12 @@ private fun getCallNameFromPsi(element: JetElement): Name? {
|
||||
if (element == operationReference) {
|
||||
val node = operationReference.getReferencedNameElementType()
|
||||
return if (node is JetToken) {
|
||||
OperatorConventions.getNameForOperationSymbol(node) ?: Name.identifierNoValidate(element.getText())
|
||||
val conventionName = if (elementParent is JetPrefixExpression)
|
||||
OperatorConventions.getNameForOperationSymbol(node, true, false)
|
||||
else
|
||||
OperatorConventions.getNameForOperationSymbol(node)
|
||||
|
||||
conventionName ?: Name.identifierNoValidate(element.getText())
|
||||
}
|
||||
else {
|
||||
Name.identifierNoValidate(element.getText())
|
||||
|
||||
@@ -69,6 +69,7 @@ public class OperatorModifierInspection : AbstractKotlinInspection() {
|
||||
val arity = valueParameters.size()
|
||||
if (arity == 0 &&
|
||||
(name in OperatorConventions.UNARY_OPERATION_NAMES.values() ||
|
||||
name == OperatorNameConventions.PLUS || name == OperatorNameConventions.MINUS || // temporary
|
||||
name == OperatorNameConventions.ITERATOR ||
|
||||
isComponentLike(name) ||
|
||||
name == OperatorNameConventions.NEXT ||
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ public object CreateBinaryOperationActionFactory: CreateCallableMemberFromUsageF
|
||||
val token = element.operationToken as JetToken
|
||||
val operationName = when (token) {
|
||||
JetTokens.IDENTIFIER -> element.operationReference.getReferencedName()
|
||||
else -> OperatorConventions.getNameForOperationSymbol(token)?.asString()
|
||||
else -> OperatorConventions.getNameForOperationSymbol(token, false, true)?.asString()
|
||||
} ?: return null
|
||||
val inOperation = token in OperatorConventions.IN_OPERATIONS
|
||||
val comparisonOperation = token in OperatorConventions.COMPARISON_OPERATIONS
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ public object CreateUnaryOperationActionFactory: CreateCallableMemberFromUsageFa
|
||||
|
||||
override fun createCallableInfo(element: JetUnaryExpression, diagnostic: Diagnostic): CallableInfo? {
|
||||
val token = element.operationToken as JetToken
|
||||
val operationName = OperatorConventions.getNameForOperationSymbol(token) ?: return null
|
||||
val operationName = OperatorConventions.getNameForOperationSymbol(token, true, false) ?: return null
|
||||
val incDec = token in OperatorConventions.INCREMENT_OPERATIONS
|
||||
|
||||
val receiverExpr = element.baseExpression ?: return null
|
||||
|
||||
@@ -22,11 +22,11 @@ class A {
|
||||
return 1
|
||||
}
|
||||
|
||||
fun plus() {
|
||||
fun unaryPlus() {
|
||||
<lineMarker descr="Recursive call">+</lineMarker>this
|
||||
}
|
||||
|
||||
fun minus() {
|
||||
fun unaryMinus() {
|
||||
<lineMarker descr="Recursive call">-</lineMarker>this
|
||||
}
|
||||
|
||||
|
||||
Vendored
+2
-2
@@ -1,7 +1,7 @@
|
||||
fun test() {
|
||||
class Test {
|
||||
fun plus(vararg a: Int): Test = Test()
|
||||
fun unaryPlus(vararg a: Int): Test = Test()
|
||||
}
|
||||
val test = Test()
|
||||
test.pl<caret>us()
|
||||
test.unaryPl<caret>us()
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -1,6 +1,6 @@
|
||||
fun test() {
|
||||
class Test {
|
||||
fun plus(vararg a: Int): Test = Test()
|
||||
fun unaryPlus(vararg a: Int): Test = Test()
|
||||
}
|
||||
val test = Test()
|
||||
+test
|
||||
|
||||
+3
-3
@@ -2,10 +2,10 @@ fun doSomething<T>(a: T) {}
|
||||
|
||||
fun test() {
|
||||
class Test {
|
||||
fun plus(): Test = Test()
|
||||
fun unaryPlus(): Test = Test()
|
||||
fun plus(a: Test): Test = Test()
|
||||
fun minus(): Test = Test()
|
||||
fun unaryMinus(): Test = Test()
|
||||
}
|
||||
val test = Test()
|
||||
doSomething((-((test + test).pl<caret>us())).toString())
|
||||
doSomething((-((test + test).unaryPl<caret>us())).toString())
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -2,9 +2,9 @@ fun doSomething<T>(a: T) {}
|
||||
|
||||
fun test() {
|
||||
class Test {
|
||||
fun plus(): Test = Test()
|
||||
fun unaryPlus(): Test = Test()
|
||||
fun plus(a: Test): Test = Test()
|
||||
fun minus(): Test = Test()
|
||||
fun unaryMinus(): Test = Test()
|
||||
}
|
||||
val test = Test()
|
||||
doSomething((-(+(test + test))).toString())
|
||||
|
||||
Vendored
+2
-2
@@ -1,7 +1,7 @@
|
||||
fun test() {
|
||||
class Test {
|
||||
fun plus(a: Int=1): Test = Test()
|
||||
fun unaryPlus(a: Int=1): Test = Test()
|
||||
}
|
||||
val test = Test()
|
||||
test.pl<caret>us()
|
||||
test.unaryPl<caret>us()
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -1,6 +1,6 @@
|
||||
fun test() {
|
||||
class Test {
|
||||
fun plus(a: Int=1): Test = Test()
|
||||
fun unaryPlus(a: Int=1): Test = Test()
|
||||
}
|
||||
val test = Test()
|
||||
+test
|
||||
|
||||
Vendored
+2
-2
@@ -1,8 +1,8 @@
|
||||
fun test() {
|
||||
class Test()
|
||||
|
||||
fun Test.plus(): Test = Test()
|
||||
fun Test.unaryPlus(): Test = Test()
|
||||
|
||||
val test = Test()
|
||||
test.pl<caret>us()
|
||||
test.unaryPl<caret>us()
|
||||
}
|
||||
|
||||
idea/testData/intentions/conventionNameCalls/replaceCallWithUnaryOperator/extensionFunction.kt.after
Vendored
+1
-1
@@ -1,7 +1,7 @@
|
||||
fun test() {
|
||||
class Test()
|
||||
|
||||
fun Test.plus(): Test = Test()
|
||||
fun Test.unaryPlus(): Test = Test()
|
||||
|
||||
val test = Test()
|
||||
+test
|
||||
|
||||
idea/testData/intentions/conventionNameCalls/replaceCallWithUnaryOperator/functionLiteralArgument.kt
Vendored
+2
-2
@@ -1,8 +1,8 @@
|
||||
// IS_APPLICABLE: false
|
||||
fun test() {
|
||||
class Test {
|
||||
fun plus(fn: () -> Unit): Test = Test()
|
||||
fun unaryPlus(fn: () -> Unit): Test = Test()
|
||||
}
|
||||
val test = Test()
|
||||
test.pl<caret>us {}
|
||||
test.unaryPl<caret>us {}
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -1,8 +1,8 @@
|
||||
// INTENTION_TEXT: Replace with '-' operator
|
||||
fun test() {
|
||||
class Test {
|
||||
fun minus(): Test = Test()
|
||||
fun unaryMinus(): Test = Test()
|
||||
}
|
||||
val test = Test()
|
||||
test.min<caret>us()
|
||||
test.unaryMin<caret>us()
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -1,7 +1,7 @@
|
||||
// INTENTION_TEXT: Replace with '-' operator
|
||||
fun test() {
|
||||
class Test {
|
||||
fun minus(): Test = Test()
|
||||
fun unaryMinus(): Test = Test()
|
||||
}
|
||||
val test = Test()
|
||||
-test
|
||||
|
||||
Vendored
+2
-2
@@ -1,8 +1,8 @@
|
||||
// IS_APPLICABLE: false
|
||||
fun test() {
|
||||
class Test {
|
||||
fun plus(a: Int): Test = Test()
|
||||
fun unaryPlus(a: Int): Test = Test()
|
||||
}
|
||||
val test = Test()
|
||||
test.pl<caret>us(a=1)
|
||||
test.unaryPl<caret>us(a=1)
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
fun test() {
|
||||
class Test {
|
||||
fun plus(): Test = Test()
|
||||
fun unaryPlus(): Test = Test()
|
||||
}
|
||||
val test = Test()
|
||||
+test.p<caret>lus()
|
||||
+test.unaryP<caret>lus()
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -1,6 +1,6 @@
|
||||
fun test() {
|
||||
class Test {
|
||||
fun plus(): Test = Test()
|
||||
fun unaryPlus(): Test = Test()
|
||||
}
|
||||
val test = Test()
|
||||
+(+test)
|
||||
|
||||
Vendored
+2
-2
@@ -1,8 +1,8 @@
|
||||
// INTENTION_TEXT: Replace with '+' operator
|
||||
fun test() {
|
||||
class Test {
|
||||
fun plus(): Test = Test()
|
||||
fun unaryPlus(): Test = Test()
|
||||
}
|
||||
val test = Test()
|
||||
test.pl<caret>us()
|
||||
test.unaryPl<caret>us()
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -1,7 +1,7 @@
|
||||
// INTENTION_TEXT: Replace with '+' operator
|
||||
fun test() {
|
||||
class Test {
|
||||
fun plus(): Test = Test()
|
||||
fun unaryPlus(): Test = Test()
|
||||
}
|
||||
val test = Test()
|
||||
+test
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
class C {
|
||||
companion object {
|
||||
fun minus(): C = C()
|
||||
fun unaryMinus(): C = C()
|
||||
}
|
||||
}
|
||||
|
||||
fun foo() {
|
||||
C.<caret>minus()
|
||||
C.<caret>unaryMinus()
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -1,6 +1,6 @@
|
||||
class C {
|
||||
companion object {
|
||||
fun minus(): C = C()
|
||||
fun unaryMinus(): C = C()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -1,11 +1,11 @@
|
||||
// IS_APPLICABLE: false
|
||||
|
||||
open class Base {
|
||||
open fun minus() = this
|
||||
open fun unaryMinus() = this
|
||||
}
|
||||
|
||||
class C : Base() {
|
||||
override fun minus(): Base {
|
||||
return super.<caret>minus()
|
||||
override fun unaryMinus(): Base {
|
||||
return super.<caret>unaryMinus()
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
// IS_APPLICABLE: false
|
||||
fun test() {
|
||||
class Test {
|
||||
fun plus<T>(): T? = this as? T
|
||||
fun unaryPlus<T>(): T? = this as? T
|
||||
}
|
||||
val test = Test()
|
||||
test.p<caret>lus<Int>()
|
||||
test.unaryP<caret>lus<Int>()
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -1,8 +1,8 @@
|
||||
// IS_APPLICABLE: false
|
||||
fun test() {
|
||||
class Test {
|
||||
fun plus(vararg a: Int): Test = Test()
|
||||
fun unaryPlus(vararg a: Int): Test = Test()
|
||||
}
|
||||
val test = Test()
|
||||
test.pl<caret>us(0)
|
||||
test.unaryPl<caret>us(0)
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
// IS_APPLICABLE: false
|
||||
fun test() {
|
||||
class Test {
|
||||
fun plus(a: Int): Test = Test()
|
||||
fun unaryPlus(a: Int): Test = Test()
|
||||
}
|
||||
val test = Test()
|
||||
test.pl<caret>us(1)
|
||||
test.unaryPl<caret>us(1)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
// IS_APPLICABLE: false
|
||||
class A(val n: Int) {
|
||||
fun <caret>minus(): A = A(-n)
|
||||
fun <caret>unaryMinus(): A = A(-n)
|
||||
}
|
||||
|
||||
fun test() {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
package h
|
||||
|
||||
import util.minus
|
||||
import util.unaryMinus
|
||||
|
||||
interface H
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
package util
|
||||
|
||||
operator fun h.H?.minus() = ""
|
||||
operator fun h.H?.unaryMinus() = ""
|
||||
@@ -1,9 +1,9 @@
|
||||
// "Import" "true"
|
||||
// ERROR: <html>Unresolved reference. <br/> None of the following candidates is applicable because of receiver type mismatch: <ul><li><b>public</b> operator <b>fun</b> h.A.plus(): kotlin.Int <i>defined in</i> h</li><li><b>public</b> operator <b>fun</b> kotlin.String?.plus(other: kotlin.Any?): kotlin.String <i>defined in</i> kotlin</li></ul></html>
|
||||
// ERROR: <html>Unresolved reference. <br/> None of the following candidates is applicable because of receiver type mismatch: <ul><li><b>public</b> operator <b>fun</b> h.A.unaryPlus(): kotlin.Int <i>defined in</i> h</li></ul></html>
|
||||
|
||||
package h
|
||||
|
||||
import util.plus
|
||||
import util.unaryPlus
|
||||
|
||||
interface H
|
||||
|
||||
@@ -13,4 +13,4 @@ fun f(h: H?) {
|
||||
|
||||
class A()
|
||||
|
||||
operator fun A.plus(): Int = 3
|
||||
operator fun A.unaryPlus(): Int = 3
|
||||
@@ -1,3 +1,3 @@
|
||||
package util
|
||||
|
||||
operator fun h.H.plus() = ""
|
||||
operator fun h.H.unaryPlus() = ""
|
||||
@@ -1,5 +1,5 @@
|
||||
// "Import" "true"
|
||||
// ERROR: <html>Unresolved reference. <br/> None of the following candidates is applicable because of receiver type mismatch: <ul><li><b>public</b> operator <b>fun</b> h.A.plus(): kotlin.Int <i>defined in</i> h</li><li><b>public</b> operator <b>fun</b> kotlin.String?.plus(other: kotlin.Any?): kotlin.String <i>defined in</i> kotlin</li></ul></html>
|
||||
// ERROR: <html>Unresolved reference. <br/> None of the following candidates is applicable because of receiver type mismatch: <ul><li><b>public</b> operator <b>fun</b> h.A.unaryPlus(): kotlin.Int <i>defined in</i> h</li></ul></html>
|
||||
|
||||
package h
|
||||
|
||||
@@ -11,4 +11,4 @@ fun f(h: H?) {
|
||||
|
||||
class A()
|
||||
|
||||
operator fun A.plus(): Int = 3
|
||||
operator fun A.unaryPlus(): Int = 3
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
// "Create member function 'plus'" "true"
|
||||
|
||||
class A<T>(val n: T) {
|
||||
fun plus(): A<T> = throw Exception()
|
||||
operator fun unaryPlus(): A<T> = throw Exception()
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val a: A<Int> = A(1) + <caret>2
|
||||
val a: A<Int> = A(1) +<caret> 2
|
||||
}
|
||||
Vendored
+1
-1
@@ -1,7 +1,7 @@
|
||||
// "Create member function 'plus'" "true"
|
||||
|
||||
class A<T>(val n: T) {
|
||||
fun plus(): A<T> = throw Exception()
|
||||
operator fun unaryPlus(): A<T> = throw Exception()
|
||||
|
||||
operator fun plus(t: T): A<T> {
|
||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Create member function 'getValue', function 'set'" "true"
|
||||
// "Create member function 'getValue', function 'setValue'" "true"
|
||||
class F {
|
||||
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -1,8 +1,8 @@
|
||||
// "Create member function 'setValue'" "true"
|
||||
class F {
|
||||
fun get(x: X, propertyMetadata: PropertyMetadata): Int = 1
|
||||
fun getValue(x: X, propertyMetadata: PropertyMetadata): Int = 1
|
||||
|
||||
fun set(x: X, propertyMetadata: PropertyMetadata, i: Int) {
|
||||
fun setValue(x: X, propertyMetadata: PropertyMetadata, i: Int) {
|
||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
// "Create member function 'minus'" "true"
|
||||
// "Create member function 'unaryMinus'" "true"
|
||||
|
||||
class A<T>(val n: T) {
|
||||
fun minus(n: Int): A<T> = throw Exception()
|
||||
operator fun minus(n: Int): A<T> = throw Exception()
|
||||
}
|
||||
|
||||
fun test() {
|
||||
|
||||
Vendored
+3
-3
@@ -1,9 +1,9 @@
|
||||
// "Create member function 'minus'" "true"
|
||||
// "Create member function 'unaryMinus'" "true"
|
||||
|
||||
class A<T>(val n: T) {
|
||||
fun minus(n: Int): A<T> = throw Exception()
|
||||
operator fun minus(n: Int): A<T> = throw Exception()
|
||||
|
||||
operator fun minus(): A<T> {
|
||||
operator fun unaryMinus(): A<T> {
|
||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Create extension function 'minus'" "true"
|
||||
// "Create extension function 'unaryMinus'" "true"
|
||||
|
||||
fun test() {
|
||||
val a = <caret>-false
|
||||
|
||||
Vendored
+2
-2
@@ -1,9 +1,9 @@
|
||||
// "Create extension function 'minus'" "true"
|
||||
// "Create extension function 'unaryMinus'" "true"
|
||||
|
||||
fun test() {
|
||||
val a = -false
|
||||
}
|
||||
|
||||
operator fun Boolean.minus(): Any {
|
||||
operator fun Boolean.unaryMinus(): Any {
|
||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Create member function 'minus'" "true"
|
||||
// "Create member function 'unaryMinus'" "true"
|
||||
|
||||
class A<T>(val n: T)
|
||||
|
||||
|
||||
Vendored
+2
-2
@@ -1,7 +1,7 @@
|
||||
// "Create member function 'minus'" "true"
|
||||
// "Create member function 'unaryMinus'" "true"
|
||||
|
||||
class A<T>(val n: T) {
|
||||
operator fun minus(): Any {
|
||||
operator fun unaryMinus(): Any {
|
||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Create member function 'minus'" "true"
|
||||
// "Create member function 'unaryMinus'" "true"
|
||||
|
||||
class A<T>(val n: T)
|
||||
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
// "Create member function 'minus'" "true"
|
||||
// "Create member function 'unaryMinus'" "true"
|
||||
|
||||
class A<T>(val n: T) {
|
||||
operator fun minus(): A<T> {
|
||||
operator fun unaryMinus(): A<T> {
|
||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user