More precise diagnostic messages about "operator modifier is not applicable"

This commit is contained in:
Yan Zhulanow
2015-12-25 18:37:36 +03:00
parent 3fa506fd45
commit 0304bd1dc1
9 changed files with 163 additions and 90 deletions
@@ -28,7 +28,7 @@ class AddOperatorModifierIntention : SelfTargetingRangeIntention<KtNamedFunction
override fun applicabilityRange(element: KtNamedFunction): TextRange? {
val nameIdentifier = element.nameIdentifier ?: return null
val functionDescriptor = element.resolveToDescriptor() as? FunctionDescriptor ?: return null
if (functionDescriptor.isOperator || !OperatorChecks.canBeOperator(functionDescriptor)) return null
if (functionDescriptor.isOperator || !OperatorChecks.checkOperator(functionDescriptor).isSuccess) return null
return nameIdentifier.textRange
}
@@ -37,8 +37,8 @@ import org.jetbrains.kotlin.psi.KtPostfixExpression
import org.jetbrains.kotlin.psi.KtPsiFactory
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.util.OperatorChecks
import org.jetbrains.kotlin.util.OperatorNameConventions
import org.jetbrains.kotlin.util.isValidOperator
abstract class ExclExclCallFix : IntentionAction {
override fun getFamilyName(): String = text
@@ -126,7 +126,7 @@ object MissingIteratorExclExclFixFactory : KotlinSingleIntentionActionFactory()
val memberScope = descriptor.unsubstitutedMemberScope
val functions = memberScope.getContributedFunctions(OperatorNameConventions.ITERATOR, NoLookupLocation.FROM_IDE)
return functions.any { it.isOperator && OperatorChecks.canBeOperator(it) }
return functions.any { it.isValidOperator() }
}
when (descriptor) {
@@ -1,5 +1,5 @@
// IS_APPLICABLE: false
// ERROR: operator modifier is inapplicable on this function: last parameter must not have a default value or be a vararg
// ERROR: operator modifier is inapplicable on this function: last parameter should not have a default value or be a vararg
class C {
operator fun set(s: String, vararg value: Int): Boolean = true
@@ -1,3 +1,4 @@
// IS_APPLICABLE: false
// ERROR: 'infix' modifier is inapplicable on this function
infix fun id(s: String) = s
val x = <caret>id("0").get(0)