Add LanguageFeatureSettings parameter to single method in checkers interfaces
This parameter will be used further for target-dependent checks Also introduce SimpleDeclarationChecker/SimpleCallChecker sub-interfaces (more weak ones) Implementing them instead of base checkers is more convenient in most cases
This commit is contained in:
+2
-2
@@ -25,13 +25,13 @@ import org.jetbrains.kotlin.psi.KtAnnotationEntry
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.SimpleCallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
||||
|
||||
class JavaAnnotationCallChecker : CallChecker {
|
||||
class JavaAnnotationCallChecker : SimpleCallChecker {
|
||||
override fun check(resolvedCall: ResolvedCall<*>, context: BasicCallResolutionContext) {
|
||||
val resultingDescriptor = resolvedCall.resultingDescriptor.original
|
||||
if (resultingDescriptor !is JavaConstructorDescriptor ||
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtDeclarationWithBody
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DeclarationChecker
|
||||
import org.jetbrains.kotlin.resolve.SimpleDeclarationChecker
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.inline.InlineUtil
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
||||
@@ -30,7 +30,7 @@ fun DeclarationDescriptor.hasNativeAnnotation(): Boolean {
|
||||
return this is FunctionDescriptor && this.isExternal
|
||||
}
|
||||
|
||||
class NativeFunChecker : DeclarationChecker {
|
||||
class NativeFunChecker : SimpleDeclarationChecker {
|
||||
override fun check(
|
||||
declaration: KtDeclaration,
|
||||
descriptor: DeclarationDescriptor,
|
||||
|
||||
+2
-2
@@ -20,14 +20,14 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.SimpleCallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
||||
import org.jetbrains.kotlin.types.KotlinTypeFactory
|
||||
import org.jetbrains.kotlin.types.TypeProjectionImpl
|
||||
|
||||
class JavaClassOnCompanionChecker : CallChecker {
|
||||
class JavaClassOnCompanionChecker : SimpleCallChecker {
|
||||
override fun check(resolvedCall: ResolvedCall<*>, context: BasicCallResolutionContext) {
|
||||
val descriptor = resolvedCall.resultingDescriptor
|
||||
if (descriptor !is PropertyDescriptor || descriptor.name.asString() != "javaClass") return
|
||||
|
||||
+3
-3
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.fileClasses.isInsideJvmMultifileClassFile
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtProperty
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DeclarationChecker
|
||||
import org.jetbrains.kotlin.resolve.SimpleDeclarationChecker
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.jvm.annotations.findJvmFieldAnnotation
|
||||
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.resolve.jvm.checkers.JvmFieldApplicabilityChecker.Pr
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
||||
|
||||
|
||||
class JvmFieldApplicabilityChecker : DeclarationChecker {
|
||||
class JvmFieldApplicabilityChecker : SimpleDeclarationChecker {
|
||||
|
||||
internal enum class Problem(val errorMessage: String) {
|
||||
NOT_FINAL("JvmField can only be applied to final property"),
|
||||
@@ -87,4 +87,4 @@ class JvmFieldApplicabilityChecker : DeclarationChecker {
|
||||
val outerClassForObject = containingClass.containingDeclaration as? ClassDescriptor ?: return false
|
||||
return DescriptorUtils.isInterface(outerClassForObject)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -22,12 +22,12 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtProperty
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DeclarationChecker
|
||||
import org.jetbrains.kotlin.resolve.SimpleDeclarationChecker
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.kotlin.resolve.annotations.findJvmSyntheticAnnotation
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
||||
|
||||
class JvmSyntheticApplicabilityChecker : DeclarationChecker {
|
||||
class JvmSyntheticApplicabilityChecker : SimpleDeclarationChecker {
|
||||
|
||||
override fun check(
|
||||
declaration: KtDeclaration,
|
||||
@@ -41,4 +41,4 @@ class JvmSyntheticApplicabilityChecker : DeclarationChecker {
|
||||
diagnosticHolder.report(ErrorsJvm.JVM_SYNTHETIC_ON_DELEGATE.on(annotationEntry))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.resolve.jvm.checkers
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.SimpleCallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.isComputingDeferredType
|
||||
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.serialization.deserialization.NotFoundClasses
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.utils.newLinkedHashSetWithExpectedSize
|
||||
|
||||
class MissingDependencyClassChecker : CallChecker {
|
||||
class MissingDependencyClassChecker : SimpleCallChecker {
|
||||
override fun check(resolvedCall: ResolvedCall<*>, context: BasicCallResolutionContext) {
|
||||
for (classId in collectNotFoundClasses(resolvedCall.resultingDescriptor)) {
|
||||
context.trace.report(ErrorsJvm.MISSING_DEPENDENCY_CLASS.on(resolvedCall.call.callElement, classId.asSingleFqName()))
|
||||
|
||||
+2
-2
@@ -20,13 +20,13 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.annotations.hasJvmStaticAnnotation
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.SimpleCallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.parentsWithSelf
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
||||
|
||||
class ProtectedInSuperClassCompanionCallChecker : CallChecker {
|
||||
class ProtectedInSuperClassCompanionCallChecker : SimpleCallChecker {
|
||||
override fun check(resolvedCall: ResolvedCall<*>, context: BasicCallResolutionContext) {
|
||||
val targetDescriptor = resolvedCall.resultingDescriptor.original
|
||||
// Protected non-JVM static
|
||||
|
||||
+2
-2
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.resolve.jvm.checkers
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.SimpleCallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
|
||||
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.synthetic.SamAdapterExtensionFunctionDescriptor
|
||||
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
|
||||
|
||||
object ProtectedSyntheticExtensionCallChecker : CallChecker {
|
||||
object ProtectedSyntheticExtensionCallChecker : SimpleCallChecker {
|
||||
override fun check(resolvedCall: ResolvedCall<*>, context: BasicCallResolutionContext) {
|
||||
val descriptor = resolvedCall.resultingDescriptor
|
||||
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.SimpleCallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm.NO_REFLECTION_IN_CLASS_PATH
|
||||
@@ -34,7 +34,7 @@ import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
* If there's no Kotlin reflection implementation found in the classpath, checks that there are no usages
|
||||
* of reflection API which will fail at runtime.
|
||||
*/
|
||||
class ReflectionAPICallChecker(private val module: ModuleDescriptor, storageManager: StorageManager) : CallChecker {
|
||||
class ReflectionAPICallChecker(private val module: ModuleDescriptor, storageManager: StorageManager) : SimpleCallChecker {
|
||||
private val isReflectionAvailable by storageManager.createLazyValue {
|
||||
module.findClassAcrossModuleDependencies(JvmAbi.REFLECTION_FACTORY_IMPL) != null
|
||||
}
|
||||
|
||||
+2
-2
@@ -22,12 +22,12 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DeclarationChecker
|
||||
import org.jetbrains.kotlin.resolve.SimpleDeclarationChecker
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.kotlin.resolve.annotations.findStrictfpAnnotation
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
||||
|
||||
class StrictfpApplicabilityChecker : DeclarationChecker {
|
||||
class StrictfpApplicabilityChecker : SimpleDeclarationChecker {
|
||||
override fun check(
|
||||
declaration: KtDeclaration,
|
||||
descriptor: DeclarationDescriptor,
|
||||
|
||||
+2
-2
@@ -18,12 +18,12 @@ package org.jetbrains.kotlin.resolve.jvm.checkers
|
||||
|
||||
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.getSuperCallExpression
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.usesDefaultArguments
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.SimpleCallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
||||
|
||||
class SuperCallWithDefaultArgumentsChecker : CallChecker {
|
||||
class SuperCallWithDefaultArgumentsChecker : SimpleCallChecker {
|
||||
override fun check(resolvedCall: ResolvedCall<*>, context: BasicCallResolutionContext) {
|
||||
val superCallExpression = getSuperCallExpression(resolvedCall.call)
|
||||
if (superCallExpression == null || !resolvedCall.usesDefaultArguments()) return
|
||||
|
||||
+2
-2
@@ -22,12 +22,12 @@ import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.getSuperCallExpression
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.SimpleCallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
||||
|
||||
class TraitDefaultMethodCallChecker : CallChecker {
|
||||
class TraitDefaultMethodCallChecker : SimpleCallChecker {
|
||||
|
||||
override fun check(resolvedCall: ResolvedCall<*>, context: BasicCallResolutionContext) {
|
||||
if (getSuperCallExpression(resolvedCall.call) == null) return
|
||||
|
||||
+2
-2
@@ -19,12 +19,12 @@ package org.jetbrains.kotlin.resolve.jvm.checkers
|
||||
import org.jetbrains.kotlin.diagnostics.Errors.UNSUPPORTED
|
||||
import org.jetbrains.kotlin.psi.KtCallableReferenceExpression
|
||||
import org.jetbrains.kotlin.psi.KtNameReferenceExpression
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.SimpleCallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
|
||||
|
||||
class UnsupportedSyntheticCallableReferenceChecker : CallChecker {
|
||||
class UnsupportedSyntheticCallableReferenceChecker : SimpleCallChecker {
|
||||
override fun check(resolvedCall: ResolvedCall<*>, context: BasicCallResolutionContext) {
|
||||
val expression = context.call.callElement
|
||||
if (expression !is KtNameReferenceExpression || expression.parent !is KtCallableReferenceExpression) return
|
||||
|
||||
+10
-10
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DeclarationChecker
|
||||
import org.jetbrains.kotlin.resolve.SimpleDeclarationChecker
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.annotations.hasJvmStaticAnnotation
|
||||
@@ -34,7 +34,7 @@ import org.jetbrains.kotlin.resolve.jvm.annotations.hasJvmFieldAnnotation
|
||||
import org.jetbrains.kotlin.resolve.jvm.annotations.hasJvmOverloadsAnnotation
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
||||
|
||||
class LocalFunInlineChecker : DeclarationChecker {
|
||||
class LocalFunInlineChecker : SimpleDeclarationChecker {
|
||||
|
||||
override fun check(
|
||||
declaration: KtDeclaration,
|
||||
@@ -50,7 +50,7 @@ class LocalFunInlineChecker : DeclarationChecker {
|
||||
}
|
||||
}
|
||||
|
||||
class PlatformStaticAnnotationChecker : DeclarationChecker {
|
||||
class PlatformStaticAnnotationChecker : SimpleDeclarationChecker {
|
||||
|
||||
override fun check(
|
||||
declaration: KtDeclaration,
|
||||
@@ -98,7 +98,7 @@ class PlatformStaticAnnotationChecker : DeclarationChecker {
|
||||
}
|
||||
}
|
||||
|
||||
class JvmNameAnnotationChecker : DeclarationChecker {
|
||||
class JvmNameAnnotationChecker : SimpleDeclarationChecker {
|
||||
override fun check(
|
||||
declaration: KtDeclaration,
|
||||
descriptor: DeclarationDescriptor,
|
||||
@@ -140,7 +140,7 @@ class JvmNameAnnotationChecker : DeclarationChecker {
|
||||
}
|
||||
}
|
||||
|
||||
class VolatileAnnotationChecker : DeclarationChecker {
|
||||
class VolatileAnnotationChecker : SimpleDeclarationChecker {
|
||||
|
||||
override fun check(declaration: KtDeclaration,
|
||||
descriptor: DeclarationDescriptor,
|
||||
@@ -161,7 +161,7 @@ class VolatileAnnotationChecker : DeclarationChecker {
|
||||
}
|
||||
}
|
||||
|
||||
class SynchronizedAnnotationChecker : DeclarationChecker {
|
||||
class SynchronizedAnnotationChecker : SimpleDeclarationChecker {
|
||||
|
||||
override fun check(declaration: KtDeclaration,
|
||||
descriptor: DeclarationDescriptor,
|
||||
@@ -176,7 +176,7 @@ class SynchronizedAnnotationChecker : DeclarationChecker {
|
||||
}
|
||||
}
|
||||
|
||||
class OverloadsAnnotationChecker: DeclarationChecker {
|
||||
class OverloadsAnnotationChecker: SimpleDeclarationChecker {
|
||||
override fun check(
|
||||
declaration: KtDeclaration,
|
||||
descriptor: DeclarationDescriptor,
|
||||
@@ -205,7 +205,7 @@ class OverloadsAnnotationChecker: DeclarationChecker {
|
||||
}
|
||||
}
|
||||
|
||||
class TypeParameterBoundIsNotArrayChecker : DeclarationChecker {
|
||||
class TypeParameterBoundIsNotArrayChecker : SimpleDeclarationChecker {
|
||||
override fun check(
|
||||
declaration: KtDeclaration,
|
||||
descriptor: DeclarationDescriptor,
|
||||
@@ -225,7 +225,7 @@ class TypeParameterBoundIsNotArrayChecker : DeclarationChecker {
|
||||
}
|
||||
}
|
||||
|
||||
class ReifiedTypeParameterAnnotationChecker : DeclarationChecker {
|
||||
class ReifiedTypeParameterAnnotationChecker : SimpleDeclarationChecker {
|
||||
|
||||
override fun check(
|
||||
declaration: KtDeclaration,
|
||||
@@ -258,4 +258,4 @@ class ReifiedTypeParameterAnnotationChecker : DeclarationChecker {
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtProperty
|
||||
|
||||
object ConstModifierChecker : DeclarationChecker {
|
||||
object ConstModifierChecker : SimpleDeclarationChecker {
|
||||
override fun check(
|
||||
declaration: KtDeclaration,
|
||||
descriptor: DeclarationDescriptor,
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.psi.KtInstanceExpressionWithLabel
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.SimpleCallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.Receiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.parentsWithSelf
|
||||
|
||||
object ConstructorHeaderCallChecker : CallChecker {
|
||||
object ConstructorHeaderCallChecker : SimpleCallChecker {
|
||||
override fun check(resolvedCall: ResolvedCall<*>, context: BasicCallResolutionContext) {
|
||||
val dispatchReceiverClass = resolvedCall.dispatchReceiver.classDescriptorForImplicitReceiver
|
||||
val extensionReceiverClass = resolvedCall.extensionReceiver.classDescriptorForImplicitReceiver
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
|
||||
|
||||
class DataClassDeclarationChecker : DeclarationChecker {
|
||||
class DataClassDeclarationChecker : SimpleDeclarationChecker {
|
||||
override fun check(
|
||||
declaration: KtDeclaration,
|
||||
descriptor: DeclarationDescriptor,
|
||||
|
||||
@@ -16,16 +16,34 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve
|
||||
|
||||
import org.jetbrains.kotlin.config.LanguageFeatureSettings
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
|
||||
interface DeclarationChecker {
|
||||
// TODO: Think about encapsulating these parameters into specific class like CheckerParameters when you're about to add another one
|
||||
fun check(
|
||||
declaration: KtDeclaration,
|
||||
descriptor: DeclarationDescriptor,
|
||||
diagnosticHolder: DiagnosticSink,
|
||||
bindingContext: BindingContext,
|
||||
languageFeatureSettings: LanguageFeatureSettings
|
||||
)
|
||||
}
|
||||
|
||||
interface SimpleDeclarationChecker : DeclarationChecker {
|
||||
override fun check(
|
||||
declaration: KtDeclaration,
|
||||
descriptor: DeclarationDescriptor,
|
||||
diagnosticHolder: DiagnosticSink,
|
||||
bindingContext: BindingContext, languageFeatureSettings: LanguageFeatureSettings
|
||||
) = check(declaration, descriptor, diagnosticHolder, bindingContext)
|
||||
|
||||
fun check(
|
||||
declaration: KtDeclaration,
|
||||
descriptor: DeclarationDescriptor,
|
||||
diagnosticHolder: DiagnosticSink,
|
||||
bindingContext: BindingContext)
|
||||
|
||||
bindingContext: BindingContext
|
||||
)
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.hasDefaultValue
|
||||
|
||||
class InfixModifierChecker : DeclarationChecker {
|
||||
class InfixModifierChecker : SimpleDeclarationChecker {
|
||||
|
||||
override fun check(
|
||||
declaration: KtDeclaration,
|
||||
@@ -49,4 +49,4 @@ class InfixModifierChecker : DeclarationChecker {
|
||||
return !singleParameter.hasDefaultValue() && singleParameter.varargElementType == null
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtFunction
|
||||
import org.jetbrains.kotlin.psi.KtParameter
|
||||
|
||||
object InlineParameterChecker : DeclarationChecker {
|
||||
object InlineParameterChecker : SimpleDeclarationChecker {
|
||||
override fun check(
|
||||
declaration: KtDeclaration, descriptor: DeclarationDescriptor, diagnosticHolder: DiagnosticSink, bindingContext: BindingContext
|
||||
) {
|
||||
|
||||
@@ -237,7 +237,7 @@ public class ModifiersChecker {
|
||||
@NotNull DeclarationDescriptor descriptor
|
||||
) {
|
||||
for (DeclarationChecker checker : declarationCheckers) {
|
||||
checker.check(declaration, descriptor, trace, trace.getBindingContext());
|
||||
checker.check(declaration, descriptor, trace, trace.getBindingContext(), languageFeatureSettings);
|
||||
}
|
||||
OperatorModifierChecker.INSTANCE.check(declaration, descriptor, trace, languageFeatureSettings);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.jetbrains.kotlin.types.typeUtil.isUnit
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
import org.jetbrains.kotlin.utils.sure
|
||||
|
||||
object SuspendModifierChecker : DeclarationChecker {
|
||||
object SuspendModifierChecker : SimpleDeclarationChecker {
|
||||
override fun check(
|
||||
declaration: KtDeclaration,
|
||||
descriptor: DeclarationDescriptor,
|
||||
@@ -61,7 +61,7 @@ object SuspendModifierChecker : DeclarationChecker {
|
||||
}
|
||||
}
|
||||
|
||||
object CoroutineModifierChecker : DeclarationChecker {
|
||||
object CoroutineModifierChecker : SimpleDeclarationChecker {
|
||||
override fun check(
|
||||
declaration: KtDeclaration,
|
||||
descriptor: DeclarationDescriptor,
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
|
||||
object UnderscoreChecker : DeclarationChecker {
|
||||
object UnderscoreChecker : SimpleDeclarationChecker {
|
||||
|
||||
fun checkIdentifier(identifier: PsiElement?, diagnosticHolder: DiagnosticSink) {
|
||||
if (identifier == null || identifier.text.isEmpty()) return
|
||||
|
||||
@@ -85,7 +85,7 @@ class CallCompleter(
|
||||
|
||||
if (resolvedCall != null) {
|
||||
for (callChecker in callCheckers) {
|
||||
callChecker.check(resolvedCall, context)
|
||||
callChecker.check(resolvedCall, context, languageFeatureSettings)
|
||||
}
|
||||
|
||||
val element = if (resolvedCall is VariableAsFunctionResolvedCall)
|
||||
|
||||
@@ -16,12 +16,29 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve.calls.checkers
|
||||
|
||||
import org.jetbrains.kotlin.config.LanguageFeatureSettings
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.types.DeferredType
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
interface CallChecker {
|
||||
// TODO: Think about encapsulating these parameters into specific class like CheckerParameters when you're about to add another one
|
||||
fun check(
|
||||
resolvedCall: ResolvedCall<*>,
|
||||
context: BasicCallResolutionContext,
|
||||
languageFeatureSettings: LanguageFeatureSettings
|
||||
)
|
||||
}
|
||||
|
||||
interface SimpleCallChecker : CallChecker {
|
||||
override fun check(
|
||||
resolvedCall: ResolvedCall<*>,
|
||||
context: BasicCallResolutionContext,
|
||||
languageFeatureSettings: LanguageFeatureSettings
|
||||
) = check(resolvedCall, context)
|
||||
|
||||
fun check(resolvedCall: ResolvedCall<*>, context: BasicCallResolutionContext)
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.typeUtil.isArrayOfNothing
|
||||
|
||||
class CallReturnsArrayOfNothingChecker : CallChecker {
|
||||
class CallReturnsArrayOfNothingChecker : SimpleCallChecker {
|
||||
override fun check(resolvedCall: ResolvedCall<*>, context: BasicCallResolutionContext) {
|
||||
val returnType = resolvedCall.resultingDescriptor.returnType
|
||||
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.resolve.inline.InlineUtil
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
import org.jetbrains.kotlin.types.expressions.CaptureKind
|
||||
|
||||
class CapturingInClosureChecker : CallChecker {
|
||||
class CapturingInClosureChecker : SimpleCallChecker {
|
||||
override fun check(resolvedCall: ResolvedCall<*>, context: BasicCallResolutionContext) {
|
||||
val variableResolvedCall = if (resolvedCall is VariableAsFunctionResolvedCall) resolvedCall.variableCall else resolvedCall
|
||||
val variableDescriptor = variableResolvedCall.resultingDescriptor as? VariableDescriptor
|
||||
|
||||
+11
-1
@@ -20,6 +20,7 @@ import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.builtins.FunctionTypesKt;
|
||||
import org.jetbrains.kotlin.config.LanguageFeatureSettings;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.diagnostics.Errors;
|
||||
import org.jetbrains.kotlin.lexer.KtToken;
|
||||
@@ -48,7 +49,7 @@ import static org.jetbrains.kotlin.diagnostics.Errors.USAGE_IS_NOT_INLINABLE;
|
||||
import static org.jetbrains.kotlin.resolve.inline.InlineUtil.allowsNonLocalReturns;
|
||||
import static org.jetbrains.kotlin.resolve.inline.InlineUtil.checkNonLocalReturnUsage;
|
||||
|
||||
class InlineChecker implements CallChecker {
|
||||
class InlineChecker implements SimpleCallChecker {
|
||||
private final SimpleFunctionDescriptor descriptor;
|
||||
private final Set<CallableDescriptor> inlinableParameters = new LinkedHashSet<CallableDescriptor>();
|
||||
private final boolean isEffectivelyPublicApiFunction;
|
||||
@@ -66,6 +67,15 @@ class InlineChecker implements CallChecker {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void check(
|
||||
@NotNull ResolvedCall<?> resolvedCall,
|
||||
@NotNull BasicCallResolutionContext context,
|
||||
@NotNull LanguageFeatureSettings languageFeatureSettings
|
||||
) {
|
||||
SimpleCallChecker.DefaultImpls.check(this, resolvedCall, context, languageFeatureSettings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void check(@NotNull ResolvedCall<?> resolvedCall, @NotNull BasicCallResolutionContext context) {
|
||||
KtExpression expression = context.call.getCalleeExpression();
|
||||
|
||||
+3
-3
@@ -23,8 +23,8 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.inline.InlineUtil
|
||||
import java.lang.ref.WeakReference
|
||||
|
||||
class InlineCheckerWrapper : CallChecker {
|
||||
private var checkersCache: WeakReference<MutableMap<DeclarationDescriptor, CallChecker>>? = null
|
||||
class InlineCheckerWrapper : SimpleCallChecker {
|
||||
private var checkersCache: WeakReference<MutableMap<DeclarationDescriptor, SimpleCallChecker>>? = null
|
||||
|
||||
override fun check(resolvedCall: ResolvedCall<*>, context: BasicCallResolutionContext) {
|
||||
if (context.isAnnotationContext) return
|
||||
@@ -41,7 +41,7 @@ class InlineCheckerWrapper : CallChecker {
|
||||
}
|
||||
}
|
||||
|
||||
private fun getChecker(descriptor: SimpleFunctionDescriptor): CallChecker {
|
||||
private fun getChecker(descriptor: SimpleFunctionDescriptor): SimpleCallChecker {
|
||||
val map = checkersCache?.get() ?: hashMapOf()
|
||||
checkersCache = checkersCache ?: WeakReference(map)
|
||||
return map.getOrPut(descriptor) { InlineChecker(descriptor) }
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCallImpl
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||
|
||||
class InvokeConventionChecker : CallChecker {
|
||||
class InvokeConventionChecker : SimpleCallChecker {
|
||||
override fun check(resolvedCall: ResolvedCall<*>, context: BasicCallResolutionContext) {
|
||||
if (resolvedCall is VariableAsFunctionResolvedCallImpl) {
|
||||
val functionCall = resolvedCall.functionCall
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.parentsWithSelf
|
||||
|
||||
object ProtectedConstructorCallChecker : CallChecker {
|
||||
object ProtectedConstructorCallChecker : SimpleCallChecker {
|
||||
override fun check(resolvedCall: ResolvedCall<*>, context: BasicCallResolutionContext) {
|
||||
val descriptor = resolvedCall.resultingDescriptor as? ConstructorDescriptor ?: return
|
||||
val constructorOwner = descriptor.containingDeclaration.original
|
||||
|
||||
+11
-1
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.resolve.calls.checkers;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.config.LanguageFeatureSettings;
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
@@ -33,7 +34,16 @@ import org.jetbrains.kotlin.types.typeUtil.TypeUtilsKt;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ReifiedTypeParameterSubstitutionChecker implements CallChecker {
|
||||
public class ReifiedTypeParameterSubstitutionChecker implements SimpleCallChecker {
|
||||
@Override
|
||||
public void check(
|
||||
@NotNull ResolvedCall<?> resolvedCall,
|
||||
@NotNull BasicCallResolutionContext context,
|
||||
@NotNull LanguageFeatureSettings languageFeatureSettings
|
||||
) {
|
||||
SimpleCallChecker.DefaultImpls.check(this, resolvedCall, context, languageFeatureSettings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void check(@NotNull ResolvedCall<?> resolvedCall, @NotNull BasicCallResolutionContext context) {
|
||||
Map<TypeParameterDescriptor, KotlinType> typeArguments = resolvedCall.getTypeArguments();
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
||||
|
||||
class SafeCallChecker : CallChecker {
|
||||
class SafeCallChecker : SimpleCallChecker {
|
||||
override fun check(resolvedCall: ResolvedCall<*>, context: BasicCallResolutionContext) {
|
||||
val operationNode = resolvedCall.call.callOperationNode ?: return
|
||||
|
||||
|
||||
+1
-2
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.coroutine.CoroutineReceiverValue
|
||||
import org.jetbrains.kotlin.resolve.inline.InlineUtil
|
||||
|
||||
object CoroutineSuspendCallChecker : CallChecker {
|
||||
object CoroutineSuspendCallChecker : SimpleCallChecker {
|
||||
override fun check(resolvedCall: ResolvedCall<*>, context: BasicCallResolutionContext) {
|
||||
val descriptor = resolvedCall.candidateDescriptor as? FunctionDescriptor ?: return
|
||||
if (!descriptor.isSuspend || descriptor.initialSignatureDescriptor == null) return
|
||||
@@ -54,4 +54,3 @@ fun checkCoroutineBuilderCall(
|
||||
resolvedCall.call.calleeExpression ?: resolvedCall.call.callElement, LanguageFeature.Coroutines))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -587,7 +587,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
BasicCallResolutionContext resolutionContext =
|
||||
BasicCallResolutionContext.create(context, call, CheckArgumentTypesMode.CHECK_CALLABLE_TYPE);
|
||||
for (CallChecker checker : components.callCheckers) {
|
||||
checker.check(resolvedCall, resolutionContext);
|
||||
checker.check(resolvedCall, resolutionContext, components.languageFeatureSettings);
|
||||
}
|
||||
|
||||
components.symbolUsageValidator.validateCall(resolvedCall, descriptor, trace, expression);
|
||||
|
||||
@@ -36,7 +36,7 @@ import org.jetbrains.kotlin.psi.KtLiteralStringTemplateEntry
|
||||
import org.jetbrains.kotlin.psi.KtStringTemplateExpression
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||
import org.jetbrains.kotlin.resolve.TemporaryBindingTrace
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.SimpleCallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant
|
||||
@@ -47,7 +47,7 @@ import org.jetbrains.kotlin.types.TypeUtils
|
||||
|
||||
class JsCallChecker(
|
||||
private val constantExpressionEvaluator: ConstantExpressionEvaluator
|
||||
) : CallChecker {
|
||||
) : SimpleCallChecker {
|
||||
|
||||
companion object {
|
||||
private val JS_PATTERN: DescriptorPredicate = PatternBuilder.pattern("kotlin.js.js(String)")
|
||||
|
||||
+2
-2
@@ -22,10 +22,10 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
||||
import org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DeclarationChecker
|
||||
import org.jetbrains.kotlin.resolve.SimpleDeclarationChecker
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
|
||||
class NativeInnerClassChecker : DeclarationChecker {
|
||||
class NativeInnerClassChecker : SimpleDeclarationChecker {
|
||||
override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, diagnosticHolder: DiagnosticSink,
|
||||
bindingContext: BindingContext) {
|
||||
if (descriptor !is ClassDescriptor || !AnnotationsUtils.isNativeObject(descriptor)) return
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.kotlin.js.resolve
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
@@ -28,13 +27,13 @@ import org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtNamedFunction
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DeclarationChecker
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.SimpleDeclarationChecker
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf
|
||||
|
||||
internal abstract class AbstractNativeAnnotationsChecker(private val requiredAnnotation: PredefinedAnnotation) : DeclarationChecker {
|
||||
internal abstract class AbstractNativeAnnotationsChecker(private val requiredAnnotation: PredefinedAnnotation) : SimpleDeclarationChecker {
|
||||
|
||||
open fun additionalCheck(declaration: KtNamedFunction, descriptor: FunctionDescriptor, diagnosticHolder: DiagnosticSink) {}
|
||||
|
||||
|
||||
+2
-2
@@ -22,11 +22,11 @@ import org.jetbrains.kotlin.android.synthetic.res.AndroidSyntheticProperty
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.SimpleCallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
|
||||
class AndroidExtensionPropertiesCallChecker : CallChecker {
|
||||
class AndroidExtensionPropertiesCallChecker : SimpleCallChecker {
|
||||
override fun check(resolvedCall: ResolvedCall<*>, context: BasicCallResolutionContext) {
|
||||
val expression = context.call.calleeExpression ?: return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user