add 'operator' modifier when creating next() and hasNext() from usage

This commit is contained in:
Dmitry Jemerov
2015-09-24 20:22:42 +02:00
parent 1e2d4c0471
commit e0f8d68a5f
7 changed files with 9 additions and 7 deletions
@@ -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)
}
}
@@ -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)
}
}
@@ -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.
}
}
@@ -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.
}
}
@@ -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.
}
}
@@ -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.
}
}
@@ -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.
}
}