Drop SymbolUsageValidator#validateCall in favor of CallChecker#check

This commit is contained in:
Alexander Udalov
2016-06-27 19:10:12 +03:00
parent 260689eb8c
commit d599d87978
10 changed files with 109 additions and 113 deletions
@@ -42,7 +42,6 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.kotlin.resolve.scopes.LexicalScope; import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
import org.jetbrains.kotlin.resolve.scopes.ScopeUtils; import org.jetbrains.kotlin.resolve.scopes.ScopeUtils;
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver; import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver;
import org.jetbrains.kotlin.resolve.validation.SymbolUsageValidator;
import org.jetbrains.kotlin.types.*; import org.jetbrains.kotlin.types.*;
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker; import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
import org.jetbrains.kotlin.types.expressions.ExpressionTypingContext; import org.jetbrains.kotlin.types.expressions.ExpressionTypingContext;
@@ -70,22 +69,19 @@ public class DelegatedPropertyResolver {
private final ExpressionTypingServices expressionTypingServices; private final ExpressionTypingServices expressionTypingServices;
private final LanguageFeatureSettings languageFeatureSettings; private final LanguageFeatureSettings languageFeatureSettings;
private final Iterable<CallChecker> callCheckers; private final Iterable<CallChecker> callCheckers;
private final Iterable<SymbolUsageValidator> symbolUsageValidators;
public DelegatedPropertyResolver( public DelegatedPropertyResolver(
@NotNull KotlinBuiltIns builtIns, @NotNull KotlinBuiltIns builtIns,
@NotNull FakeCallResolver fakeCallResolver, @NotNull FakeCallResolver fakeCallResolver,
@NotNull ExpressionTypingServices expressionTypingServices, @NotNull ExpressionTypingServices expressionTypingServices,
@NotNull LanguageFeatureSettings languageFeatureSettings, @NotNull LanguageFeatureSettings languageFeatureSettings,
@NotNull Iterable<CallChecker> callCheckers, @NotNull Iterable<CallChecker> callCheckers
@NotNull Iterable<SymbolUsageValidator> symbolUsageValidators
) { ) {
this.builtIns = builtIns; this.builtIns = builtIns;
this.fakeCallResolver = fakeCallResolver; this.fakeCallResolver = fakeCallResolver;
this.expressionTypingServices = expressionTypingServices; this.expressionTypingServices = expressionTypingServices;
this.languageFeatureSettings = languageFeatureSettings; this.languageFeatureSettings = languageFeatureSettings;
this.callCheckers = callCheckers; this.callCheckers = callCheckers;
this.symbolUsageValidators = symbolUsageValidators;
} }
public void resolvePropertyDelegate( public void resolvePropertyDelegate(
@@ -288,9 +284,6 @@ public class DelegatedPropertyResolver {
for (CallChecker checker : callCheckers) { for (CallChecker checker : callCheckers) {
checker.check(resultingCall, byKeyword, callCheckerContext); checker.check(resultingCall, byKeyword, callCheckerContext);
} }
for (SymbolUsageValidator validator : symbolUsageValidators) {
validator.validateCall(resultingCall, trace, byKeyword);
}
} }
} }
trace.record(DELEGATED_PROPERTY_RESOLVED_CALL, accessor, resultingCall); trace.record(DELEGATED_PROPERTY_RESOLVED_CALL, accessor, resultingCall);
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.calls.checkers.* import org.jetbrains.kotlin.resolve.calls.checkers.*
import org.jetbrains.kotlin.resolve.calls.results.TypeSpecificityComparator import org.jetbrains.kotlin.resolve.calls.results.TypeSpecificityComparator
import org.jetbrains.kotlin.resolve.scopes.SyntheticScopes import org.jetbrains.kotlin.resolve.scopes.SyntheticScopes
import org.jetbrains.kotlin.resolve.calls.checkers.DeprecatedCallChecker
import org.jetbrains.kotlin.resolve.validation.DeprecatedSymbolValidator import org.jetbrains.kotlin.resolve.validation.DeprecatedSymbolValidator
import org.jetbrains.kotlin.resolve.validation.SymbolUsageValidator import org.jetbrains.kotlin.resolve.validation.SymbolUsageValidator
import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.storage.StorageManager
@@ -66,7 +67,7 @@ private val DEFAULT_DECLARATION_CHECKERS = listOf(
private val DEFAULT_CALL_CHECKERS = listOf( private val DEFAULT_CALL_CHECKERS = listOf(
CapturingInClosureChecker(), InlineCheckerWrapper(), ReifiedTypeParameterSubstitutionChecker(), SafeCallChecker(), CapturingInClosureChecker(), InlineCheckerWrapper(), ReifiedTypeParameterSubstitutionChecker(), SafeCallChecker(),
CallReturnsArrayOfNothingChecker(), InfixCallChecker(), OperatorCallChecker(), DeprecatedCallChecker, CallReturnsArrayOfNothingChecker(), InfixCallChecker(), OperatorCallChecker(),
ConstructorHeaderCallChecker, ProtectedConstructorCallChecker, ConstructorHeaderCallChecker, ProtectedConstructorCallChecker,
CoroutineSuspendCallChecker, BuilderFunctionsCallChecker CoroutineSuspendCallChecker, BuilderFunctionsCallChecker
) )
@@ -44,7 +44,6 @@ import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResultsImpl
import org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus import org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy
import org.jetbrains.kotlin.resolve.validation.SymbolUsageValidator
import org.jetbrains.kotlin.types.ErrorUtils import org.jetbrains.kotlin.types.ErrorUtils
import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.types.TypeUtils
@@ -58,7 +57,6 @@ class CallCompleter(
private val candidateResolver: CandidateResolver, private val candidateResolver: CandidateResolver,
private val dataFlowAnalyzer: DataFlowAnalyzer, private val dataFlowAnalyzer: DataFlowAnalyzer,
private val callCheckers: Iterable<CallChecker>, private val callCheckers: Iterable<CallChecker>,
private val symbolUsageValidators: Iterable<SymbolUsageValidator>,
private val builtIns: KotlinBuiltIns, private val builtIns: KotlinBuiltIns,
private val fakeCallResolver: FakeCallResolver, private val fakeCallResolver: FakeCallResolver,
private val languageFeatureSettings: LanguageFeatureSettings private val languageFeatureSettings: LanguageFeatureSettings
@@ -95,10 +93,6 @@ class CallCompleter(
callChecker.check(resolvedCall, reportOn, callCheckerContext) callChecker.check(resolvedCall, reportOn, callCheckerContext)
} }
for (validator in symbolUsageValidators) {
validator.validateCall(resolvedCall, context.trace, element!!)
}
resolveHandleResultCallForCoroutineLambdaExpressions(context, resolvedCall) resolveHandleResultCallForCoroutineLambdaExpressions(context, resolvedCall)
} }
@@ -0,0 +1,83 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.resolve.calls.checkers
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.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.PropertySetterDescriptor
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.KtBinaryExpression
import org.jetbrains.kotlin.psi.KtCallableReferenceExpression
import org.jetbrains.kotlin.psi.KtReferenceExpression
import org.jetbrains.kotlin.psi.KtUnaryExpression
import org.jetbrains.kotlin.resolve.BindingTrace
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.createDeprecationDiagnostic
import org.jetbrains.kotlin.resolve.getDeprecation
object DeprecatedCallChecker : CallChecker {
override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) {
check(resolvedCall.resultingDescriptor, context.trace, reportOn)
}
internal fun check(targetDescriptor: CallableDescriptor, trace: BindingTrace, element: PsiElement) {
val deprecation = targetDescriptor.getDeprecation()
// avoid duplicating diagnostic when deprecation for property effectively deprecates setter
if (targetDescriptor is PropertySetterDescriptor && targetDescriptor.correspondingProperty.getDeprecation() == deprecation) return
if (deprecation != null) {
trace.report(createDeprecationDiagnostic(element, deprecation))
}
else if (targetDescriptor is PropertyDescriptor) {
propertyGetterWorkaround(targetDescriptor, trace, element)
}
}
private val PROPERTY_SET_OPERATIONS = TokenSet.create(KtTokens.EQ, KtTokens.PLUSEQ, KtTokens.MINUSEQ, KtTokens.MULTEQ,
KtTokens.DIVEQ, KtTokens.PERCEQ, KtTokens.PLUSPLUS, KtTokens.MINUSMINUS)
private fun propertyGetterWorkaround(propertyDescriptor: PropertyDescriptor, trace: BindingTrace, expression: PsiElement) {
// property getters do not come as callable yet, so we analyse surroundings to check for deprecation annotation on getter
val binaryExpression = PsiTreeUtil.getParentOfType<KtBinaryExpression>(expression, KtBinaryExpression::class.java)
if (binaryExpression != null) {
val left = binaryExpression.left
if (left == expression && binaryExpression.operationToken in PROPERTY_SET_OPERATIONS) return
val referenceExpressions = PsiTreeUtil.getChildrenOfType<KtReferenceExpression>(left, KtReferenceExpression::class.java)
if (referenceExpressions != null) {
for (expr in referenceExpressions) {
// skip binary set operations
if (expr == expression && binaryExpression.operationToken in PROPERTY_SET_OPERATIONS) return
}
}
}
val unaryExpression = PsiTreeUtil.getParentOfType(expression, KtUnaryExpression::class.java)
// skip unary set operations
if (unaryExpression?.operationReference?.getReferencedNameElementType() in PROPERTY_SET_OPERATIONS) return
val callableExpression = PsiTreeUtil.getParentOfType(expression, KtCallableReferenceExpression::class.java)
// skip Type::property
if (callableExpression != null && callableExpression.callableReference == expression) return
propertyDescriptor.getter?.let { check(it, trace, expression) }
}
}
@@ -16,11 +16,14 @@
package org.jetbrains.kotlin.resolve package org.jetbrains.kotlin.resolve
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.resolve.annotations.argumentValue import org.jetbrains.kotlin.resolve.annotations.argumentValue
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
@@ -173,6 +176,15 @@ private fun DeclarationDescriptor.getDeclaredDeprecatedAnnotation(
return null return null
} }
internal fun createDeprecationDiagnostic(element: PsiElement, deprecation: Deprecation): Diagnostic {
val targetOriginal = deprecation.target.original
if (deprecation.deprecationLevel == DeprecationLevelValue.ERROR) {
return Errors.DEPRECATION_ERROR.on(element, targetOriginal, deprecation.message)
}
return Errors.DEPRECATION.on(element, targetOriginal, deprecation.message)
}
// values from kotlin.DeprecationLevel // values from kotlin.DeprecationLevel
enum class DeprecationLevelValue { enum class DeprecationLevelValue {
WARNING, ERROR, HIDDEN WARNING, ERROR, HIDDEN
@@ -17,41 +17,19 @@
package org.jetbrains.kotlin.resolve.validation package org.jetbrains.kotlin.resolve.validation
import com.intellij.psi.PsiElement import com.intellij.psi.PsiElement
import com.intellij.psi.tree.TokenSet import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
import com.intellij.psi.util.PsiTreeUtil import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.psi.KtAnnotationEntry
import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.psi.KtStubbedPsiUtil
import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.psi.KtSuperTypeCallEntry
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.BindingTrace import org.jetbrains.kotlin.resolve.BindingTrace
import org.jetbrains.kotlin.resolve.Deprecation import org.jetbrains.kotlin.resolve.calls.checkers.DeprecatedCallChecker
import org.jetbrains.kotlin.resolve.DeprecationLevelValue import org.jetbrains.kotlin.resolve.createDeprecationDiagnostic
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.getDeprecation import org.jetbrains.kotlin.resolve.getDeprecation
class DeprecatedSymbolValidator : SymbolUsageValidator { class DeprecatedSymbolValidator : SymbolUsageValidator {
override fun validateCall(resolvedCall: ResolvedCall<*>, trace: BindingTrace, element: PsiElement) {
validate(resolvedCall.resultingDescriptor, trace, element)
}
override fun validatePropertyCall(targetDescriptor: PropertyAccessorDescriptor, trace: BindingTrace, element: PsiElement) { override fun validatePropertyCall(targetDescriptor: PropertyAccessorDescriptor, trace: BindingTrace, element: PsiElement) {
validate(targetDescriptor, trace, element) DeprecatedCallChecker.check(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
if (targetDescriptor is PropertySetterDescriptor && targetDescriptor.correspondingProperty.getDeprecation() == deprecation) return
if (deprecation != null) {
trace.report(createDeprecationDiagnostic(element, deprecation))
}
else if (targetDescriptor is PropertyDescriptor) {
propertyGetterWorkaround(targetDescriptor, trace, element)
}
} }
override fun validateTypeUsage(targetDescriptor: ClassifierDescriptor, trace: BindingTrace, element: PsiElement) { override fun validateTypeUsage(targetDescriptor: ClassifierDescriptor, trace: BindingTrace, element: PsiElement) {
@@ -68,47 +46,4 @@ class DeprecatedSymbolValidator : SymbolUsageValidator {
trace.report(createDeprecationDiagnostic(element, deprecation)) trace.report(createDeprecationDiagnostic(element, deprecation))
} }
} }
private fun createDeprecationDiagnostic(element: PsiElement, deprecation: Deprecation): Diagnostic {
val targetOriginal = deprecation.target.original
if (deprecation.deprecationLevel == DeprecationLevelValue.ERROR) {
return Errors.DEPRECATION_ERROR.on(element, targetOriginal, deprecation.message)
}
return Errors.DEPRECATION.on(element, targetOriginal, deprecation.message)
}
private val PROPERTY_SET_OPERATIONS = TokenSet.create(KtTokens.EQ, KtTokens.PLUSEQ, KtTokens.MINUSEQ, KtTokens.MULTEQ,
KtTokens.DIVEQ, KtTokens.PERCEQ, KtTokens.PLUSPLUS, KtTokens.MINUSMINUS)
fun propertyGetterWorkaround(
propertyDescriptor: PropertyDescriptor,
trace: BindingTrace,
expression: PsiElement
) {
// property getters do not come as callable yet, so we analyse surroundings to check for deprecation annotation on getter
val binaryExpression = PsiTreeUtil.getParentOfType<KtBinaryExpression>(expression, KtBinaryExpression::class.java)
if (binaryExpression != null) {
val left = binaryExpression.left
if (left == expression && binaryExpression.operationToken in PROPERTY_SET_OPERATIONS) return
val referenceExpressions = PsiTreeUtil.getChildrenOfType<KtReferenceExpression>(left, KtReferenceExpression::class.java)
if (referenceExpressions != null) {
for (expr in referenceExpressions) {
// skip binary set operations
if (expr == expression && binaryExpression.operationToken in PROPERTY_SET_OPERATIONS) return
}
}
}
val unaryExpression = PsiTreeUtil.getParentOfType(expression, KtUnaryExpression::class.java)
// skip unary set operations
if (unaryExpression?.operationReference?.getReferencedNameElementType() in PROPERTY_SET_OPERATIONS) return
val callableExpression = PsiTreeUtil.getParentOfType(expression, KtCallableReferenceExpression::class.java)
// skip Type::property
if (callableExpression != null && callableExpression.callableReference == expression) return
propertyDescriptor.getter?.let { validatePropertyCall(it, trace, expression) }
}
} }
@@ -17,16 +17,12 @@
package org.jetbrains.kotlin.resolve.validation package org.jetbrains.kotlin.resolve.validation
import com.intellij.psi.PsiElement import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor
import org.jetbrains.kotlin.resolve.BindingTrace import org.jetbrains.kotlin.resolve.BindingTrace
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
interface SymbolUsageValidator { interface SymbolUsageValidator {
fun validateTypeUsage(targetDescriptor: ClassifierDescriptor, trace: BindingTrace, element: PsiElement) fun validateTypeUsage(targetDescriptor: ClassifierDescriptor, trace: BindingTrace, element: PsiElement)
fun validateCall(resolvedCall: ResolvedCall<*>, trace: BindingTrace, element: PsiElement)
fun validatePropertyCall(targetDescriptor: PropertyAccessorDescriptor, trace: BindingTrace, element: PsiElement) fun validatePropertyCall(targetDescriptor: PropertyAccessorDescriptor, trace: BindingTrace, element: PsiElement)
} }
@@ -589,9 +589,6 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
for (CallChecker checker : components.callCheckers) { for (CallChecker checker : components.callCheckers) {
checker.check(resolvedCall, expression, callCheckerContext); checker.check(resolvedCall, expression, callCheckerContext);
} }
for (SymbolUsageValidator validator : components.symbolUsageValidators) {
validator.validateCall(resolvedCall, trace, expression);
}
} }
private static boolean isDeclaredInClass(ReceiverParameterDescriptor receiver) { private static boolean isDeclaredInClass(ReceiverParameterDescriptor receiver) {
@@ -30,7 +30,6 @@ import org.jetbrains.kotlin.resolve.calls.checkers.CallCheckerContext
import org.jetbrains.kotlin.resolve.dataClassUtils.createComponentName import org.jetbrains.kotlin.resolve.dataClassUtils.createComponentName
import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.kotlin.resolve.validation.SymbolUsageValidator
import org.jetbrains.kotlin.types.ErrorUtils import org.jetbrains.kotlin.types.ErrorUtils
import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.types.TypeUtils
@@ -41,8 +40,7 @@ class DestructuringDeclarationResolver(
private val localVariableResolver: LocalVariableResolver, private val localVariableResolver: LocalVariableResolver,
private val typeResolver: TypeResolver, private val typeResolver: TypeResolver,
private val languageFeatureSettings: LanguageFeatureSettings, private val languageFeatureSettings: LanguageFeatureSettings,
private val callCheckers: Iterable<CallChecker>, private val callCheckers: Iterable<CallChecker>
private val symbolUsageValidators: Iterable<SymbolUsageValidator>
) { ) {
fun defineLocalVariablesFromMultiDeclaration( fun defineLocalVariablesFromMultiDeclaration(
writableScope: LexicalWritableScope, writableScope: LexicalWritableScope,
@@ -90,9 +88,6 @@ class DestructuringDeclarationResolver(
for (checker in callCheckers) { for (checker in callCheckers) {
checker.check(results.resultingCall, entry, callCheckerContext) checker.check(results.resultingCall, entry, callCheckerContext)
} }
for (validator in symbolUsageValidators) {
validator.validateCall(results.resultingCall, context.trace, entry)
}
val functionReturnType = results.resultingDescriptor.returnType val functionReturnType = results.resultingDescriptor.returnType
if (functionReturnType != null && !TypeUtils.noExpectedType(expectedType) if (functionReturnType != null && !TypeUtils.noExpectedType(expectedType)
@@ -35,7 +35,6 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults; import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults;
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver; import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver;
import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver; import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver;
import org.jetbrains.kotlin.resolve.validation.SymbolUsageValidator;
import org.jetbrains.kotlin.types.DynamicTypesKt; import org.jetbrains.kotlin.types.DynamicTypesKt;
import org.jetbrains.kotlin.types.ErrorUtils; import org.jetbrains.kotlin.types.ErrorUtils;
import org.jetbrains.kotlin.types.KotlinType; import org.jetbrains.kotlin.types.KotlinType;
@@ -52,20 +51,17 @@ public class ForLoopConventionsChecker {
private final FakeCallResolver fakeCallResolver; private final FakeCallResolver fakeCallResolver;
private final LanguageFeatureSettings languageFeatureSettings; private final LanguageFeatureSettings languageFeatureSettings;
private final Iterable<CallChecker> callCheckers; private final Iterable<CallChecker> callCheckers;
private final Iterable<SymbolUsageValidator> symbolUsageValidators;
public ForLoopConventionsChecker( public ForLoopConventionsChecker(
@NotNull KotlinBuiltIns builtIns, @NotNull KotlinBuiltIns builtIns,
@NotNull FakeCallResolver fakeCallResolver, @NotNull FakeCallResolver fakeCallResolver,
@NotNull LanguageFeatureSettings languageFeatureSettings, @NotNull LanguageFeatureSettings languageFeatureSettings,
@NotNull Iterable<CallChecker> callCheckers, @NotNull Iterable<CallChecker> callCheckers
@NotNull Iterable<SymbolUsageValidator> symbolUsageValidators
) { ) {
this.builtIns = builtIns; this.builtIns = builtIns;
this.fakeCallResolver = fakeCallResolver; this.fakeCallResolver = fakeCallResolver;
this.languageFeatureSettings = languageFeatureSettings; this.languageFeatureSettings = languageFeatureSettings;
this.callCheckers = callCheckers; this.callCheckers = callCheckers;
this.symbolUsageValidators = symbolUsageValidators;
} }
@Nullable @Nullable
@@ -90,9 +86,6 @@ public class ForLoopConventionsChecker {
for (CallChecker checker : callCheckers) { for (CallChecker checker : callCheckers) {
checker.check(iteratorResolvedCall, loopRangeExpression, callCheckerContext); checker.check(iteratorResolvedCall, loopRangeExpression, callCheckerContext);
} }
for (SymbolUsageValidator validator : symbolUsageValidators) {
validator.validateCall(iteratorResolvedCall, context.trace, loopRangeExpression);
}
KotlinType iteratorType = iteratorFunction.getReturnType(); KotlinType iteratorType = iteratorFunction.getReturnType();
//noinspection ConstantConditions //noinspection ConstantConditions
@@ -148,16 +141,13 @@ public class ForLoopConventionsChecker {
assert nextResolutionResults.isSuccess(); assert nextResolutionResults.isSuccess();
ResolvedCall<FunctionDescriptor> resolvedCall = nextResolutionResults.getResultingCall(); ResolvedCall<FunctionDescriptor> resolvedCall = nextResolutionResults.getResultingCall();
context.trace.record(resolvedCallKey, loopRangeExpression, resolvedCall); context.trace.record(resolvedCallKey, loopRangeExpression, resolvedCall);
FunctionDescriptor functionDescriptor = resolvedCall.getResultingDescriptor();
CallCheckerContext callCheckerContext = new CallCheckerContext(context, languageFeatureSettings); CallCheckerContext callCheckerContext = new CallCheckerContext(context, languageFeatureSettings);
for (CallChecker checker : callCheckers) { for (CallChecker checker : callCheckers) {
checker.check(resolvedCall, loopRangeExpression, callCheckerContext); checker.check(resolvedCall, loopRangeExpression, callCheckerContext);
} }
for (SymbolUsageValidator validator : symbolUsageValidators) {
validator.validateCall(resolvedCall, context.trace, loopRangeExpression);
}
FunctionDescriptor functionDescriptor = resolvedCall.getResultingDescriptor();
checkIfOperatorModifierPresent(loopRangeExpression, functionDescriptor, context.trace); checkIfOperatorModifierPresent(loopRangeExpression, functionDescriptor, context.trace);
return functionDescriptor.getReturnType(); return functionDescriptor.getReturnType();