From f6f825e0dc2c94ca2a48fd156accd8bb6052c68f Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 24 Jun 2016 20:08:38 +0300 Subject: [PATCH] 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 --- .../resolve/DelegatedPropertyResolver.java | 2 +- .../kotlin/resolve/calls/CallCompleter.kt | 2 +- .../validation/DeprecatedSymbolValidator.kt | 20 +++++++++++-------- .../validation/SymbolUsageValidator.kt | 5 ++++- .../BasicExpressionTypingVisitor.java | 4 ++-- .../DestructuringDeclarationResolver.kt | 5 ++--- .../ForLoopConventionsChecker.java | 4 ++-- 7 files changed, 24 insertions(+), 18 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.java index 8bbf7cc5bed..1823a718957 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.java @@ -265,7 +265,7 @@ public class DelegatedPropertyResolver { } for (SymbolUsageValidator validator : symbolUsageValidators) { - validator.validateCall(resultingCall, resultingCall.getResultingDescriptor(), trace, byKeyword); + validator.validateCall(resultingCall, trace, byKeyword); } } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallCompleter.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallCompleter.kt index ea83d351a0d..f69b460155d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallCompleter.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallCompleter.kt @@ -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) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/validation/DeprecatedSymbolValidator.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/validation/DeprecatedSymbolValidator.kt index 98761245915..1327f0f2661 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/validation/DeprecatedSymbolValidator.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/validation/DeprecatedSymbolValidator.kt @@ -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) } } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/validation/SymbolUsageValidator.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/validation/SymbolUsageValidator.kt index 7612b6a4e06..c9b047fd1de 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/validation/SymbolUsageValidator.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/validation/SymbolUsageValidator.kt @@ -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) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java index 3f74c54b254..4dd3b07b7b2 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java @@ -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); } } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DestructuringDeclarationResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DestructuringDeclarationResolver.kt index 57546e59cb0..d80fd7da77b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DestructuringDeclarationResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DestructuringDeclarationResolver.kt @@ -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)) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ForLoopConventionsChecker.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ForLoopConventionsChecker.java index 4819adabf77..4bd9335df1a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ForLoopConventionsChecker.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ForLoopConventionsChecker.java @@ -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);