Add warnings at declaration and call sites of operator 'mod'
This commit is contained in:
@@ -629,6 +629,9 @@ public interface Errors {
|
||||
|
||||
// Conventions
|
||||
|
||||
DiagnosticFactory2<PsiElement, FunctionDescriptor, String> DEPRECATED_BINARY_MOD = DiagnosticFactory2.create(WARNING);
|
||||
DiagnosticFactory2<PsiElement, FunctionDescriptor, String> DEPRECATED_BINARY_MOD_AS_REM = DiagnosticFactory2.create(WARNING);
|
||||
|
||||
DiagnosticFactory0<KtArrayAccessExpression> NO_GET_METHOD = DiagnosticFactory0.create(ERROR, ARRAY_ACCESS);
|
||||
DiagnosticFactory0<KtArrayAccessExpression> NO_SET_METHOD = DiagnosticFactory0.create(ERROR, ARRAY_ACCESS);
|
||||
|
||||
|
||||
+3
@@ -354,6 +354,9 @@ public class DefaultErrorMessages {
|
||||
MAP.put(LOCAL_VARIABLE_WITH_SETTER, "Local variables are not allowed to have setters");
|
||||
MAP.put(VAL_WITH_SETTER, "A 'val'-property cannot have a setter");
|
||||
|
||||
MAP.put(DEPRECATED_BINARY_MOD, "Deprecated convention for ''{0}''. Use ''{1}''", NAME, STRING);
|
||||
MAP.put(DEPRECATED_BINARY_MOD_AS_REM, "''%'' is resolved to deprecated ''{0}'' operator. Replace with ''.{0}'' or add operator ''{1}''", NAME, STRING);
|
||||
|
||||
MAP.put(NO_GET_METHOD, "No get method providing array access");
|
||||
MAP.put(NO_SET_METHOD, "No set method providing array access");
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ object OperatorModifierChecker {
|
||||
|
||||
val checkResult = OperatorChecks.check(functionDescriptor)
|
||||
if (checkResult.isSuccess) {
|
||||
val shouldUseOperatorRem = languageVersionSettings.supportsFeature(LanguageFeature.OperatorRem)
|
||||
when (functionDescriptor.name) {
|
||||
in COROUTINE_OPERATOR_NAMES -> {
|
||||
if (!languageVersionSettings.supportsFeature(LanguageFeature.Coroutines)) {
|
||||
@@ -50,12 +51,17 @@ object OperatorModifierChecker {
|
||||
}
|
||||
|
||||
in REM_TO_MOD_OPERATION_NAMES.keys -> {
|
||||
if (!languageVersionSettings.supportsFeature(LanguageFeature.OperatorRem)) {
|
||||
if (!shouldUseOperatorRem) {
|
||||
diagnosticHolder.report(Errors.UNSUPPORTED_FEATURE.on(modifier, LanguageFeature.OperatorRem))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (functionDescriptor.name in REM_TO_MOD_OPERATION_NAMES.values && shouldUseOperatorRem) {
|
||||
val newNameConvention = REM_TO_MOD_OPERATION_NAMES.inverse()[functionDescriptor.name]
|
||||
diagnosticHolder.report(Errors.DEPRECATED_BINARY_MOD.on(modifier, functionDescriptor, newNameConvention!!.asString()))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
+11
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.resolve.calls.checkers
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
@@ -31,6 +32,7 @@ import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.isDynamic
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||
import org.jetbrains.kotlin.types.ErrorUtils
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
|
||||
class OperatorCallChecker : CallChecker {
|
||||
override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) {
|
||||
@@ -58,6 +60,15 @@ class OperatorCallChecker : CallChecker {
|
||||
}
|
||||
|
||||
val isConventionOperator = element is KtOperationReferenceExpression && element.isConventionOperator()
|
||||
|
||||
if (isConventionOperator) {
|
||||
val shouldUseOperatorRem = context.languageVersionSettings.supportsFeature(LanguageFeature.OperatorRem)
|
||||
if (functionDescriptor.name in OperatorConventions.REM_TO_MOD_OPERATION_NAMES.values && shouldUseOperatorRem) {
|
||||
val newNameConvention = OperatorConventions.REM_TO_MOD_OPERATION_NAMES.inverse()[functionDescriptor.name]
|
||||
context.trace.report(Errors.DEPRECATED_BINARY_MOD_AS_REM.on(reportOn, functionDescriptor, newNameConvention!!.asString()))
|
||||
}
|
||||
}
|
||||
|
||||
if (isConventionOperator || element is KtArrayAccessExpression) {
|
||||
if (!functionDescriptor.isOperator) {
|
||||
report(reportOn, functionDescriptor, context.trace)
|
||||
|
||||
Reference in New Issue
Block a user