Create from Usage: Add infix modifier to functions generated from binary expressions
#KT-10184 Fixed
This commit is contained in:
+2
-1
@@ -463,7 +463,8 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
|
|||||||
}
|
}
|
||||||
if (callableInfo is FunctionInfo) {
|
if (callableInfo is FunctionInfo) {
|
||||||
val operatorModifier = if (callableInfo.isOperator) "operator " else ""
|
val operatorModifier = if (callableInfo.isOperator) "operator " else ""
|
||||||
psiFactory.createFunction("${modifiers}${operatorModifier}fun<> $header $body")
|
val infixModifier = if (callableInfo.isInfix) "infix " else ""
|
||||||
|
psiFactory.createFunction("$modifiers$infixModifier${operatorModifier}fun<> $header $body")
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
psiFactory.createSecondaryConstructor("${modifiers}constructor$paramList $body")
|
psiFactory.createSecondaryConstructor("${modifiers}constructor$paramList $body")
|
||||||
|
|||||||
+2
-1
@@ -146,7 +146,8 @@ class FunctionInfo(name: String,
|
|||||||
possibleContainers: List<KtElement> = Collections.emptyList(),
|
possibleContainers: List<KtElement> = Collections.emptyList(),
|
||||||
override val parameterInfos: List<ParameterInfo> = Collections.emptyList(),
|
override val parameterInfos: List<ParameterInfo> = Collections.emptyList(),
|
||||||
typeParameterInfos: List<TypeInfo> = Collections.emptyList(),
|
typeParameterInfos: List<TypeInfo> = Collections.emptyList(),
|
||||||
val isOperator: Boolean = false
|
val isOperator: Boolean = false,
|
||||||
|
val isInfix: Boolean = false
|
||||||
) : CallableInfo(name, receiverTypeInfo, returnTypeInfo, possibleContainers, typeParameterInfos) {
|
) : CallableInfo(name, receiverTypeInfo, returnTypeInfo, possibleContainers, typeParameterInfos) {
|
||||||
override val kind: CallableKind get() = CallableKind.FUNCTION
|
override val kind: CallableKind get() = CallableKind.FUNCTION
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -55,6 +55,7 @@ public object CreateBinaryOperationActionFactory: CreateCallableMemberFromUsageF
|
|||||||
}
|
}
|
||||||
val parameters = Collections.singletonList(ParameterInfo(TypeInfo(argumentExpr, Variance.IN_VARIANCE)))
|
val parameters = Collections.singletonList(ParameterInfo(TypeInfo(argumentExpr, Variance.IN_VARIANCE)))
|
||||||
return FunctionInfo(operationName, receiverType, returnType, parameterInfos = parameters,
|
return FunctionInfo(operationName, receiverType, returnType, parameterInfos = parameters,
|
||||||
isOperator = token != KtTokens.IDENTIFIER)
|
isOperator = token != KtTokens.IDENTIFIER,
|
||||||
|
isInfix = true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
// "Create member function 'foo'" "true"
|
// "Create member function 'foo'" "true"
|
||||||
|
|
||||||
class A<T>(val n: T) {
|
class A<T>(val n: T) {
|
||||||
fun foo(t: T): A<T> {
|
infix fun foo(t: T): A<T> {
|
||||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
// "Create member function 'compareTo'" "true"
|
// "Create member function 'compareTo'" "true"
|
||||||
|
|
||||||
class A<T>(val n: T) {
|
class A<T>(val n: T) {
|
||||||
operator fun compareTo(t: T): Int {
|
infix operator fun compareTo(t: T): Int {
|
||||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
// "Create member function 'contains'" "true"
|
// "Create member function 'contains'" "true"
|
||||||
|
|
||||||
class A<T>(val n: T) {
|
class A<T>(val n: T) {
|
||||||
operator fun contains(t: T): Boolean {
|
infix operator fun contains(t: T): Boolean {
|
||||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
// "Create member function 'compareTo'" "true"
|
// "Create member function 'compareTo'" "true"
|
||||||
|
|
||||||
class A<T>(val n: T) {
|
class A<T>(val n: T) {
|
||||||
operator fun compareTo(t: T): Int {
|
infix operator fun compareTo(t: T): Int {
|
||||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
// "Create member function 'contains'" "true"
|
// "Create member function 'contains'" "true"
|
||||||
|
|
||||||
class A<T>(val n: T) {
|
class A<T>(val n: T) {
|
||||||
operator fun contains(t: T): Boolean {
|
infix operator fun contains(t: T): Boolean {
|
||||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
idea/testData/quickfix/createFromUsage/createFunction/binaryOperations/plusAssignOnUserType.kt.after
Vendored
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
// "Create member function 'plusAssign'" "true"
|
// "Create member function 'plusAssign'" "true"
|
||||||
|
|
||||||
class A<T>(val n: T) {
|
class A<T>(val n: T) {
|
||||||
operator fun plusAssign(t: T) {
|
infix operator fun plusAssign(t: T) {
|
||||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+1
-1
@@ -3,7 +3,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()
|
||||||
|
|
||||||
operator fun plus(t: T): A<T> {
|
infix operator fun plus(t: T): A<T> {
|
||||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
// "Create member function 'plus'" "true"
|
// "Create member function 'plus'" "true"
|
||||||
|
|
||||||
class A<T>(val n: T) {
|
class A<T>(val n: T) {
|
||||||
operator fun plus(t: T): A<T> {
|
infix operator fun plus(t: T): A<T> {
|
||||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+1
-1
@@ -3,7 +3,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()
|
||||||
|
|
||||||
operator fun plus(t: T): A<T> {
|
infix operator fun plus(t: T): A<T> {
|
||||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+1
-1
@@ -6,6 +6,6 @@ fun test() {
|
|||||||
val a: A<Int> = 2 + A(1)
|
val a: A<Int> = 2 + A(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
operator fun Int.plus(a: A<Int>): A<Int> {
|
infix operator fun Int.plus(a: A<Int>): A<Int> {
|
||||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
// "Create member function 'plus'" "true"
|
// "Create member function 'plus'" "true"
|
||||||
|
|
||||||
class A<T>(val n: T) {
|
class A<T>(val n: T) {
|
||||||
operator fun plus(t: T): A<T> {
|
infix operator fun plus(t: T): A<T> {
|
||||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
// "Create member function 'plus'" "true"
|
// "Create member function 'plus'" "true"
|
||||||
|
|
||||||
class A<T>(val n: T) {
|
class A<T>(val n: T) {
|
||||||
operator fun plus(i: Int): A<T> {
|
infix operator fun plus(i: Int): A<T> {
|
||||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -3,6 +3,6 @@ fun test() {
|
|||||||
val t: Int = 1 `!u00A0` 2
|
val t: Int = 1 `!u00A0` 2
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Int.`!u00A0`(i: Int): Int {
|
infix fun Int.`!u00A0`(i: Int): Int {
|
||||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
// "Create member function 'contains'" "true"
|
// "Create member function 'contains'" "true"
|
||||||
|
|
||||||
class A<T>(val n: T) {
|
class A<T>(val n: T) {
|
||||||
operator fun contains(t: T): Boolean {
|
infix operator fun contains(t: T): Boolean {
|
||||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
// "Create member function 'contains'" "true"
|
// "Create member function 'contains'" "true"
|
||||||
|
|
||||||
class A<T>(val n: T) {
|
class A<T>(val n: T) {
|
||||||
operator fun contains(t: T): Boolean {
|
infix operator fun contains(t: T): Boolean {
|
||||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user