Move SymbolUsageValidator#validatePropertyCall to CallChecker
This commit is contained in:
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.resolve.calls.checkers
|
|||||||
|
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.kotlin.config.LanguageFeatureSettings
|
import org.jetbrains.kotlin.config.LanguageFeatureSettings
|
||||||
|
import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor
|
||||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||||
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext
|
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||||
@@ -27,7 +28,20 @@ import org.jetbrains.kotlin.types.DeferredType
|
|||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
|
||||||
interface CallChecker {
|
interface CallChecker {
|
||||||
|
/**
|
||||||
|
* Note that [reportOn] should only be used as a target element for diagnostics reported by checkers.
|
||||||
|
* Logic of the checker should not depend on what element is the target of the diagnostic!
|
||||||
|
*/
|
||||||
fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext)
|
fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is needed because for the simple assignment expression like "a = b" there is no resolved call that points to a's setter
|
||||||
|
* (the only resolved call is the one pointing to the property 'a' itself). So [check] which takes [ResolvedCall] is not applicable here
|
||||||
|
*
|
||||||
|
* TODO: construct a special ResolvedCall instead and call [check]
|
||||||
|
*/
|
||||||
|
fun checkPropertyCall(descriptor: PropertyAccessorDescriptor, reportOn: PsiElement, context: CallCheckerContext) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class CallCheckerContext(
|
class CallCheckerContext(
|
||||||
|
|||||||
+5
@@ -20,6 +20,7 @@ import com.intellij.psi.PsiElement
|
|||||||
import com.intellij.psi.tree.TokenSet
|
import com.intellij.psi.tree.TokenSet
|
||||||
import com.intellij.psi.util.PsiTreeUtil
|
import com.intellij.psi.util.PsiTreeUtil
|
||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.PropertySetterDescriptor
|
import org.jetbrains.kotlin.descriptors.PropertySetterDescriptor
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
@@ -37,6 +38,10 @@ object DeprecatedCallChecker : CallChecker {
|
|||||||
check(resolvedCall.resultingDescriptor, context.trace, reportOn)
|
check(resolvedCall.resultingDescriptor, context.trace, reportOn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun checkPropertyCall(descriptor: PropertyAccessorDescriptor, reportOn: PsiElement, context: CallCheckerContext) {
|
||||||
|
check(descriptor, context.trace, reportOn)
|
||||||
|
}
|
||||||
|
|
||||||
internal fun check(targetDescriptor: CallableDescriptor, trace: BindingTrace, element: PsiElement) {
|
internal fun check(targetDescriptor: CallableDescriptor, trace: BindingTrace, element: PsiElement) {
|
||||||
val deprecation = targetDescriptor.getDeprecation()
|
val deprecation = targetDescriptor.getDeprecation()
|
||||||
|
|
||||||
|
|||||||
@@ -65,6 +65,13 @@ class InlineChecker implements CallChecker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void checkPropertyCall(
|
||||||
|
@NotNull PropertyAccessorDescriptor descriptor, @NotNull PsiElement reportOn, @NotNull CallCheckerContext context
|
||||||
|
) {
|
||||||
|
CallChecker.DefaultImpls.checkPropertyCall(this, descriptor, reportOn, context);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void check(@NotNull ResolvedCall<?> resolvedCall, @NotNull PsiElement reportOn, @NotNull CallCheckerContext context) {
|
public void check(@NotNull ResolvedCall<?> resolvedCall, @NotNull PsiElement reportOn, @NotNull CallCheckerContext context) {
|
||||||
KtExpression expression = resolvedCall.getCall().getCalleeExpression();
|
KtExpression expression = resolvedCall.getCall().getCalleeExpression();
|
||||||
|
|||||||
+8
-4
@@ -20,10 +20,7 @@ import com.intellij.psi.PsiElement;
|
|||||||
import kotlin.collections.CollectionsKt;
|
import kotlin.collections.CollectionsKt;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
import org.jetbrains.kotlin.descriptors.*;
|
||||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor;
|
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
|
||||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor;
|
|
||||||
import org.jetbrains.kotlin.diagnostics.Errors;
|
import org.jetbrains.kotlin.diagnostics.Errors;
|
||||||
import org.jetbrains.kotlin.psi.KtTypeProjection;
|
import org.jetbrains.kotlin.psi.KtTypeProjection;
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||||
@@ -33,6 +30,13 @@ import org.jetbrains.kotlin.types.typeUtil.TypeUtilsKt;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class ReifiedTypeParameterSubstitutionChecker implements CallChecker {
|
public class ReifiedTypeParameterSubstitutionChecker implements CallChecker {
|
||||||
|
@Override
|
||||||
|
public void checkPropertyCall(
|
||||||
|
@NotNull PropertyAccessorDescriptor descriptor, @NotNull PsiElement reportOn, @NotNull CallCheckerContext context
|
||||||
|
) {
|
||||||
|
CallChecker.DefaultImpls.checkPropertyCall(this, descriptor, reportOn, context);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void check(@NotNull ResolvedCall<?> resolvedCall, @NotNull PsiElement reportOn, @NotNull CallCheckerContext context) {
|
public void check(@NotNull ResolvedCall<?> resolvedCall, @NotNull PsiElement reportOn, @NotNull CallCheckerContext context) {
|
||||||
Map<TypeParameterDescriptor, KotlinType> typeArguments = resolvedCall.getTypeArguments();
|
Map<TypeParameterDescriptor, KotlinType> typeArguments = resolvedCall.getTypeArguments();
|
||||||
|
|||||||
-6
@@ -18,20 +18,14 @@ package org.jetbrains.kotlin.resolve.validation
|
|||||||
|
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor
|
|
||||||
import org.jetbrains.kotlin.psi.KtAnnotationEntry
|
import org.jetbrains.kotlin.psi.KtAnnotationEntry
|
||||||
import org.jetbrains.kotlin.psi.KtStubbedPsiUtil
|
import org.jetbrains.kotlin.psi.KtStubbedPsiUtil
|
||||||
import org.jetbrains.kotlin.psi.KtSuperTypeCallEntry
|
import org.jetbrains.kotlin.psi.KtSuperTypeCallEntry
|
||||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||||
import org.jetbrains.kotlin.resolve.calls.checkers.DeprecatedCallChecker
|
|
||||||
import org.jetbrains.kotlin.resolve.createDeprecationDiagnostic
|
import org.jetbrains.kotlin.resolve.createDeprecationDiagnostic
|
||||||
import org.jetbrains.kotlin.resolve.getDeprecation
|
import org.jetbrains.kotlin.resolve.getDeprecation
|
||||||
|
|
||||||
class DeprecatedSymbolValidator : SymbolUsageValidator {
|
class DeprecatedSymbolValidator : SymbolUsageValidator {
|
||||||
override fun validatePropertyCall(targetDescriptor: PropertyAccessorDescriptor, trace: BindingTrace, element: PsiElement) {
|
|
||||||
DeprecatedCallChecker.check(targetDescriptor, trace, element)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun validateTypeUsage(targetDescriptor: ClassifierDescriptor, trace: BindingTrace, element: PsiElement) {
|
override fun validateTypeUsage(targetDescriptor: ClassifierDescriptor, trace: BindingTrace, element: PsiElement) {
|
||||||
// Do not check types in annotation entries to prevent cycles in resolve, rely on call message
|
// Do not check types in annotation entries to prevent cycles in resolve, rely on call message
|
||||||
val annotationEntry = KtStubbedPsiUtil.getPsiOrStubParent(element, KtAnnotationEntry::class.java, true)
|
val annotationEntry = KtStubbedPsiUtil.getPsiOrStubParent(element, KtAnnotationEntry::class.java, true)
|
||||||
|
|||||||
@@ -18,11 +18,8 @@ package org.jetbrains.kotlin.resolve.validation
|
|||||||
|
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor
|
|
||||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||||
|
|
||||||
interface SymbolUsageValidator {
|
interface SymbolUsageValidator {
|
||||||
fun validateTypeUsage(targetDescriptor: ClassifierDescriptor, trace: BindingTrace, element: PsiElement)
|
fun validateTypeUsage(targetDescriptor: ClassifierDescriptor, trace: BindingTrace, element: PsiElement)
|
||||||
|
|
||||||
fun validatePropertyCall(targetDescriptor: PropertyAccessorDescriptor, trace: BindingTrace, element: PsiElement)
|
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-3
@@ -60,7 +60,6 @@ import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope;
|
|||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver;
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.utils.ScopeUtilsKt;
|
import org.jetbrains.kotlin.resolve.scopes.utils.ScopeUtilsKt;
|
||||||
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.ControlStructureTypingUtils.ResolveConstruct;
|
import org.jetbrains.kotlin.types.expressions.ControlStructureTypingUtils.ResolveConstruct;
|
||||||
@@ -919,8 +918,10 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
else if (setter != null) {
|
else if (setter != null) {
|
||||||
for (SymbolUsageValidator validator : components.symbolUsageValidators) {
|
CallCheckerContext callCheckerContext =
|
||||||
validator.validatePropertyCall(setter, trace, reportOn);
|
new CallCheckerContext(trace, context.scope, components.languageFeatureSettings, context.dataFlowInfo, false);
|
||||||
|
for (CallChecker checker : components.callCheckers) {
|
||||||
|
checker.checkPropertyCall(setter, reportOn, callCheckerContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-26
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.types.expressions;
|
|||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||||
import org.jetbrains.kotlin.builtins.ReflectionTypes;
|
|
||||||
import org.jetbrains.kotlin.config.LanguageFeatureSettings;
|
import org.jetbrains.kotlin.config.LanguageFeatureSettings;
|
||||||
import org.jetbrains.kotlin.context.GlobalContext;
|
import org.jetbrains.kotlin.context.GlobalContext;
|
||||||
import org.jetbrains.kotlin.incremental.components.LookupTracker;
|
import org.jetbrains.kotlin.incremental.components.LookupTracker;
|
||||||
@@ -28,8 +27,6 @@ import org.jetbrains.kotlin.resolve.calls.CallExpressionResolver;
|
|||||||
import org.jetbrains.kotlin.resolve.calls.CallResolver;
|
import org.jetbrains.kotlin.resolve.calls.CallResolver;
|
||||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker;
|
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker;
|
||||||
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator;
|
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator;
|
||||||
import org.jetbrains.kotlin.resolve.validation.SymbolUsageValidator;
|
|
||||||
import org.jetbrains.kotlin.types.DynamicTypesSettings;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
@@ -41,8 +38,6 @@ public class ExpressionTypingComponents {
|
|||||||
/*package*/ ControlStructureTypingUtils controlStructureTypingUtils;
|
/*package*/ ControlStructureTypingUtils controlStructureTypingUtils;
|
||||||
/*package*/ ForLoopConventionsChecker forLoopConventionsChecker;
|
/*package*/ ForLoopConventionsChecker forLoopConventionsChecker;
|
||||||
/*package*/ FakeCallResolver fakeCallResolver;
|
/*package*/ FakeCallResolver fakeCallResolver;
|
||||||
/*package*/ ReflectionTypes reflectionTypes;
|
|
||||||
/*package*/ DynamicTypesSettings dynamicTypesSettings;
|
|
||||||
/*package*/ KotlinBuiltIns builtIns;
|
/*package*/ KotlinBuiltIns builtIns;
|
||||||
/*package*/ LocalClassifierAnalyzer localClassifierAnalyzer;
|
/*package*/ LocalClassifierAnalyzer localClassifierAnalyzer;
|
||||||
/*package*/ FunctionDescriptorResolver functionDescriptorResolver;
|
/*package*/ FunctionDescriptorResolver functionDescriptorResolver;
|
||||||
@@ -57,7 +52,6 @@ public class ExpressionTypingComponents {
|
|||||||
/*package*/ ModifiersChecker modifiersChecker;
|
/*package*/ ModifiersChecker modifiersChecker;
|
||||||
/*package*/ DataFlowAnalyzer dataFlowAnalyzer;
|
/*package*/ DataFlowAnalyzer dataFlowAnalyzer;
|
||||||
/*package*/ Iterable<CallChecker> callCheckers;
|
/*package*/ Iterable<CallChecker> callCheckers;
|
||||||
/*package*/ Iterable<SymbolUsageValidator> symbolUsageValidators;
|
|
||||||
/*package*/ IdentifierChecker identifierChecker;
|
/*package*/ IdentifierChecker identifierChecker;
|
||||||
/*package*/ DeclarationsCheckerBuilder declarationsCheckerBuilder;
|
/*package*/ DeclarationsCheckerBuilder declarationsCheckerBuilder;
|
||||||
/*package*/ LocalVariableResolver localVariableResolver;
|
/*package*/ LocalVariableResolver localVariableResolver;
|
||||||
@@ -100,21 +94,6 @@ public class ExpressionTypingComponents {
|
|||||||
this.fakeCallResolver = fakeCallResolver;
|
this.fakeCallResolver = fakeCallResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
|
||||||
public void setReflectionTypes(@NotNull ReflectionTypes reflectionTypes) {
|
|
||||||
this.reflectionTypes = reflectionTypes;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public void setSymbolUsageValidators(@NotNull Iterable<SymbolUsageValidator> symbolUsageValidators) {
|
|
||||||
this.symbolUsageValidators = symbolUsageValidators;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public void setDynamicTypesSettings(@NotNull DynamicTypesSettings dynamicTypesSettings) {
|
|
||||||
this.dynamicTypesSettings = dynamicTypesSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public void setBuiltIns(@NotNull KotlinBuiltIns builtIns) {
|
public void setBuiltIns(@NotNull KotlinBuiltIns builtIns) {
|
||||||
this.builtIns = builtIns;
|
this.builtIns = builtIns;
|
||||||
@@ -165,11 +144,6 @@ public class ExpressionTypingComponents {
|
|||||||
this.destructuringDeclarationResolver = destructuringDeclarationResolver;
|
this.destructuringDeclarationResolver = destructuringDeclarationResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public ForLoopConventionsChecker getForLoopConventionsChecker() {
|
|
||||||
return forLoopConventionsChecker;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public void setConstantExpressionEvaluator(@NotNull ConstantExpressionEvaluator constantExpressionEvaluator) {
|
public void setConstantExpressionEvaluator(@NotNull ConstantExpressionEvaluator constantExpressionEvaluator) {
|
||||||
this.constantExpressionEvaluator = constantExpressionEvaluator;
|
this.constantExpressionEvaluator = constantExpressionEvaluator;
|
||||||
|
|||||||
Reference in New Issue
Block a user