Minor, extract validatePropertyCall out of SymbolUsageValidator#validateCall

BasicExpressionTypingVisitor#checkLValue is the only place where it's used.
There's no ResolvedCall instance for the setter call (only for the property
itself), that's why this special method is needed
This commit is contained in:
Alexander Udalov
2016-06-24 20:08:38 +03:00
parent d7d2780666
commit f6f825e0dc
7 changed files with 24 additions and 18 deletions
@@ -265,7 +265,7 @@ public class DelegatedPropertyResolver {
}
for (SymbolUsageValidator validator : symbolUsageValidators) {
validator.validateCall(resultingCall, resultingCall.getResultingDescriptor(), trace, byKeyword);
validator.validateCall(resultingCall, trace, byKeyword);
}
}
}
@@ -93,7 +93,7 @@ class CallCompleter(
resolvedCall.call.calleeExpression
for (validator in symbolUsageValidators) {
validator.validateCall(resolvedCall, resolvedCall.resultingDescriptor, context.trace, element!!)
validator.validateCall(resolvedCall, context.trace, element!!)
}
resolveHandleResultCallForCoroutineLambdaExpressions(context, resolvedCall)
@@ -19,10 +19,7 @@ package org.jetbrains.kotlin.resolve.validation
import com.intellij.psi.PsiElement
import com.intellij.psi.tree.TokenSet
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.PropertySetterDescriptor
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.lexer.KtTokens
@@ -35,7 +32,15 @@ import org.jetbrains.kotlin.resolve.getDeprecation
class DeprecatedSymbolValidator : SymbolUsageValidator {
override fun validateCall(resolvedCall: ResolvedCall<*>?, targetDescriptor: CallableDescriptor, trace: BindingTrace, element: PsiElement) {
override fun validateCall(resolvedCall: ResolvedCall<*>, trace: BindingTrace, element: PsiElement) {
validate(resolvedCall.resultingDescriptor, trace, element)
}
override fun validatePropertyCall(targetDescriptor: PropertyAccessorDescriptor, trace: BindingTrace, element: PsiElement) {
validate(targetDescriptor, trace, element)
}
private fun validate(targetDescriptor: CallableDescriptor, trace: BindingTrace, element: PsiElement) {
val deprecation = targetDescriptor.getDeprecation()
// avoid duplicating diagnostic when deprecation for property effectively deprecates setter
@@ -45,7 +50,7 @@ class DeprecatedSymbolValidator : SymbolUsageValidator {
trace.report(createDeprecationDiagnostic(element, deprecation))
}
else if (targetDescriptor is PropertyDescriptor) {
propertyGetterWorkaround(resolvedCall, targetDescriptor, trace, element)
propertyGetterWorkaround(targetDescriptor, trace, element)
}
}
@@ -77,7 +82,6 @@ class DeprecatedSymbolValidator : SymbolUsageValidator {
KtTokens.DIVEQ, KtTokens.PERCEQ, KtTokens.PLUSPLUS, KtTokens.MINUSMINUS)
fun propertyGetterWorkaround(
resolvedCall: ResolvedCall<*>?,
propertyDescriptor: PropertyDescriptor,
trace: BindingTrace,
expression: PsiElement
@@ -105,6 +109,6 @@ class DeprecatedSymbolValidator : SymbolUsageValidator {
// skip Type::property
if (callableExpression != null && callableExpression.callableReference == expression) return
propertyDescriptor.getter?.let { validateCall(resolvedCall, it, trace, expression) }
propertyDescriptor.getter?.let { validatePropertyCall(it, trace, expression) }
}
}
@@ -19,11 +19,14 @@ package org.jetbrains.kotlin.resolve.validation
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor
import org.jetbrains.kotlin.resolve.BindingTrace
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
interface SymbolUsageValidator {
fun validateTypeUsage(targetDescriptor: ClassifierDescriptor, trace: BindingTrace, element: PsiElement)
fun validateCall(resolvedCall: ResolvedCall<*>?, targetDescriptor: CallableDescriptor, trace: BindingTrace, element: PsiElement)
fun validateCall(resolvedCall: ResolvedCall<*>, trace: BindingTrace, element: PsiElement)
fun validatePropertyCall(targetDescriptor: PropertyAccessorDescriptor, trace: BindingTrace, element: PsiElement)
}
@@ -592,7 +592,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
checker.check(resolvedCall, resolutionContext, components.languageFeatureSettings);
}
for (SymbolUsageValidator validator : components.symbolUsageValidators) {
validator.validateCall(resolvedCall, descriptor, trace, expression);
validator.validateCall(resolvedCall, trace, expression);
}
}
@@ -925,7 +925,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
}
else if (setter != null) {
for (SymbolUsageValidator validator : components.symbolUsageValidators) {
validator.validateCall(null, setter, trace, reportOn);
validator.validatePropertyCall(setter, trace, reportOn);
}
}
}
@@ -81,12 +81,11 @@ class DestructuringDeclarationResolver(
context.trace.record(BindingContext.COMPONENT_RESOLVED_CALL, entry, results.resultingCall)
val functionDescriptor = results.resultingDescriptor
for (validator in symbolUsageValidators) {
validator.validateCall(null, functionDescriptor, context.trace, entry)
validator.validateCall(results.resultingCall, context.trace, entry)
}
val functionReturnType = functionDescriptor.returnType
val functionReturnType = results.resultingDescriptor.returnType
if (functionReturnType != null && !TypeUtils.noExpectedType(expectedType)
&& !KotlinTypeChecker.DEFAULT.isSubtypeOf(functionReturnType, expectedType) ) {
context.trace.report(Errors.COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH.on(initializer, componentName, functionReturnType, expectedType))
@@ -77,7 +77,7 @@ public class ForLoopConventionsChecker {
checkIfOperatorModifierPresent(loopRangeExpression, iteratorFunction, context.trace);
for (SymbolUsageValidator validator : symbolUsageValidators) {
validator.validateCall(iteratorResolvedCall, iteratorFunction, context.trace, loopRangeExpression);
validator.validateCall(iteratorResolvedCall, context.trace, loopRangeExpression);
}
KotlinType iteratorType = iteratorFunction.getReturnType();
@@ -132,7 +132,7 @@ public class ForLoopConventionsChecker {
context.trace.record(resolvedCallKey, loopRangeExpression, resolvedCall);
FunctionDescriptor functionDescriptor = resolvedCall.getResultingDescriptor();
for (SymbolUsageValidator validator : symbolUsageValidators) {
validator.validateCall(resolvedCall, functionDescriptor, context.trace, loopRangeExpression);
validator.validateCall(resolvedCall, context.trace, loopRangeExpression);
}
checkIfOperatorModifierPresent(loopRangeExpression, functionDescriptor, context.trace);