Report warning on unary plus()/minus()
This commit is contained in:
@@ -29,6 +29,11 @@ import org.jetbrains.kotlin.resolve.calls.tasks.isDynamic
|
||||
import org.jetbrains.kotlin.types.ErrorUtils
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions.PLUS
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions.MINUS
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions.UNARY_PLUS
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions.UNARY_MINUS
|
||||
|
||||
public class OperatorValidator : SymbolUsageValidator {
|
||||
|
||||
@@ -61,10 +66,24 @@ public class OperatorValidator : SymbolUsageValidator {
|
||||
return
|
||||
}
|
||||
|
||||
if (isConventionOperator() || isArrayAccessExpression()) {
|
||||
val isConventionOperator = isConventionOperator()
|
||||
if (isConventionOperator || isArrayAccessExpression()) {
|
||||
if (!functionDescriptor.isOperator) {
|
||||
report(jetElement, functionDescriptor, trace)
|
||||
}
|
||||
if (isConventionOperator && call != null) {
|
||||
checkDeprecatedUnaryConventions(call, functionDescriptor, trace)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkDeprecatedUnaryConventions(call: Call, functionDescriptor: FunctionDescriptor, sink: DiagnosticSink) {
|
||||
(call.callElement as? JetPrefixExpression)?.let { expr ->
|
||||
val functionName = functionDescriptor.name
|
||||
if (functionName == PLUS || functionName == MINUS) {
|
||||
val newName = if (functionName == PLUS) UNARY_PLUS else UNARY_MINUS
|
||||
sink.report(Errors.DEPRECATED_UNARY_PLUS_MINUS.on(expr, functionDescriptor, newName.asString()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user