Create from Usage: Add infix modifier to functions generated from binary expressions

#KT-10184 Fixed
This commit is contained in:
Alexey Sedunov
2015-11-26 13:37:43 +03:00
parent 5b90c09ab1
commit e37eea2b2d
18 changed files with 21 additions and 18 deletions
@@ -463,7 +463,8 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
}
if (callableInfo is FunctionInfo) {
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 {
psiFactory.createSecondaryConstructor("${modifiers}constructor$paramList $body")
@@ -146,7 +146,8 @@ class FunctionInfo(name: String,
possibleContainers: List<KtElement> = Collections.emptyList(),
override val parameterInfos: List<ParameterInfo> = 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) {
override val kind: CallableKind get() = CallableKind.FUNCTION
}
@@ -55,6 +55,7 @@ public object CreateBinaryOperationActionFactory: CreateCallableMemberFromUsageF
}
val parameters = Collections.singletonList(ParameterInfo(TypeInfo(argumentExpr, Variance.IN_VARIANCE)))
return FunctionInfo(operationName, receiverType, returnType, parameterInfos = parameters,
isOperator = token != KtTokens.IDENTIFIER)
isOperator = token != KtTokens.IDENTIFIER,
isInfix = true)
}
}
@@ -1,7 +1,7 @@
// "Create member function 'foo'" "true"
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.
}
}
@@ -1,7 +1,7 @@
// "Create member function 'compareTo'" "true"
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.
}
}
@@ -1,7 +1,7 @@
// "Create member function 'contains'" "true"
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.
}
}
@@ -1,7 +1,7 @@
// "Create member function 'compareTo'" "true"
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.
}
}
@@ -1,7 +1,7 @@
// "Create member function 'contains'" "true"
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.
}
}
@@ -1,7 +1,7 @@
// "Create member function 'plusAssign'" "true"
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.
}
}
@@ -3,7 +3,7 @@
class A<T>(val n: T) {
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.
}
}
@@ -1,7 +1,7 @@
// "Create member function 'plus'" "true"
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.
}
}
@@ -3,7 +3,7 @@
class A<T>(val n: T) {
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.
}
}
@@ -6,6 +6,6 @@ fun test() {
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.
}
@@ -1,7 +1,7 @@
// "Create member function 'plus'" "true"
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.
}
}
@@ -1,7 +1,7 @@
// "Create member function 'plus'" "true"
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.
}
}
@@ -3,6 +3,6 @@ fun test() {
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.
}
@@ -1,7 +1,7 @@
// "Create member function 'contains'" "true"
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.
}
}
@@ -1,7 +1,7 @@
// "Create member function 'contains'" "true"
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.
}
}