add 'operator' modifier when creating next() and hasNext() from usage
This commit is contained in:
+2
-1
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.Functi
|
||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.TypeInfo
|
||||
import org.jetbrains.kotlin.psi.JetForExpression
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
|
||||
object CreateHasNextFunctionActionFactory : CreateCallableMemberFromUsageFactory<JetForExpression>() {
|
||||
override fun getElementOfInterest(diagnostic: Diagnostic): JetForExpression? {
|
||||
@@ -37,6 +38,6 @@ object CreateHasNextFunctionActionFactory : CreateCallableMemberFromUsageFactory
|
||||
DiagnosticFactory.cast(diagnostic, Errors.HAS_NEXT_MISSING, Errors.HAS_NEXT_FUNCTION_NONE_APPLICABLE)
|
||||
val ownerType = TypeInfo(diagnosticWithParameters.a, Variance.IN_VARIANCE)
|
||||
val returnType = TypeInfo(KotlinBuiltIns.getInstance().booleanType, Variance.OUT_VARIANCE)
|
||||
return FunctionInfo("hasNext", ownerType, returnType)
|
||||
return FunctionInfo(OperatorConventions.HAS_NEXT.asString(), ownerType, returnType, isOperator = true)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.TypeIn
|
||||
import org.jetbrains.kotlin.psi.JetExpression
|
||||
import org.jetbrains.kotlin.psi.JetForExpression
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
|
||||
object CreateNextFunctionActionFactory : CreateCallableMemberFromUsageFactory<JetForExpression>() {
|
||||
override fun getElementOfInterest(diagnostic: Diagnostic): JetForExpression? {
|
||||
@@ -38,6 +39,6 @@ object CreateNextFunctionActionFactory : CreateCallableMemberFromUsageFactory<Je
|
||||
|
||||
val variableExpr = element.loopParameter ?: element.multiParameter ?: return null
|
||||
val returnType = TypeInfo(variableExpr as JetExpression, Variance.OUT_VARIANCE)
|
||||
return FunctionInfo("next", ownerType, returnType)
|
||||
return FunctionInfo(OperatorConventions.NEXT.asString(), ownerType, returnType, isOperator = true)
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -4,7 +4,7 @@ class FooIterator<T> {
|
||||
throw Exception("not implemented")
|
||||
}
|
||||
|
||||
fun hasNext(): Boolean {
|
||||
operator fun hasNext(): Boolean {
|
||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -4,7 +4,7 @@ class FooIterator<T> {
|
||||
throw Exception("not implemented")
|
||||
}
|
||||
|
||||
fun hasNext(): Boolean {
|
||||
operator fun hasNext(): Boolean {
|
||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -2,7 +2,7 @@
|
||||
class FooIterator<T> {
|
||||
fun hasNext(): Boolean { return false }
|
||||
|
||||
fun next(): Any {
|
||||
operator fun next(): Any {
|
||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
class FooIterator<T> {
|
||||
fun hasNext(): Boolean { return false }
|
||||
|
||||
fun next(): Int {
|
||||
operator fun next(): Int {
|
||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
class FooIterator<T> {
|
||||
fun hasNext(): Boolean { return false }
|
||||
|
||||
fun next(): T {
|
||||
operator fun next(): T {
|
||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user