Minor. Rename jvm default utility methods
This commit is contained in:
+3
-5
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.resolve.jvm.annotations
|
||||
import org.jetbrains.kotlin.config.JvmDefaultMode
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotated
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
@@ -17,7 +16,6 @@ import org.jetbrains.kotlin.load.java.JvmAbi.JVM_FIELD_ANNOTATION_FQ_NAME
|
||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmProtoBufUtil
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils.isInterface
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor
|
||||
|
||||
val JVM_DEFAULT_FQ_NAME = FqName("kotlin.jvm.JvmDefault")
|
||||
@@ -45,10 +43,10 @@ fun DeclarationDescriptor.findJvmFieldAnnotation(): AnnotationDescriptor? =
|
||||
fun DeclarationDescriptor.hasJvmFieldAnnotation(): Boolean =
|
||||
findJvmFieldAnnotation() != null
|
||||
|
||||
fun DeclarationDescriptor.isCallableMemberCompiledToJvmDefaultIfNoAbstract(jvmDefault: JvmDefaultMode): Boolean =
|
||||
this is CallableMemberDescriptor && isCompiledToJvmDefaultIfNoAbstract(jvmDefault)
|
||||
fun DeclarationDescriptor.isCallableMemberCompiledToJvmDefault(jvmDefault: JvmDefaultMode): Boolean =
|
||||
this is CallableMemberDescriptor && isCompiledToJvmDefault(jvmDefault)
|
||||
|
||||
fun CallableMemberDescriptor.isCompiledToJvmDefaultIfNoAbstract(jvmDefault: JvmDefaultMode): Boolean {
|
||||
fun CallableMemberDescriptor.isCompiledToJvmDefault(jvmDefault: JvmDefaultMode): Boolean {
|
||||
val directMember = DescriptorUtils.getDirectMember(this)
|
||||
|
||||
val clazz = directMember.containingDeclaration
|
||||
|
||||
+3
-3
@@ -36,7 +36,7 @@ import org.jetbrains.kotlin.resolve.calls.callResolverUtil.getSuperCallExpressio
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallCheckerContext
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.jvm.annotations.isCompiledToJvmDefaultIfNoAbstract
|
||||
import org.jetbrains.kotlin.resolve.jvm.annotations.isCompiledToJvmDefault
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm.*
|
||||
|
||||
class InterfaceDefaultMethodCallChecker(val jvmTarget: JvmTarget) : CallChecker {
|
||||
@@ -63,13 +63,13 @@ class InterfaceDefaultMethodCallChecker(val jvmTarget: JvmTarget) : CallChecker
|
||||
val realDescriptorOwner = realDescriptor.containingDeclaration as? ClassDescriptor ?: return
|
||||
|
||||
val jvmDefaultMode = context.languageVersionSettings.getFlag(JvmAnalysisFlags.jvmDefaultMode)
|
||||
if (isInterface(realDescriptorOwner) && (realDescriptor is JavaCallableMemberDescriptor || realDescriptor.isCompiledToJvmDefaultIfNoAbstract(jvmDefaultMode))) {
|
||||
if (isInterface(realDescriptorOwner) && (realDescriptor is JavaCallableMemberDescriptor || realDescriptor.isCompiledToJvmDefault(jvmDefaultMode))) {
|
||||
val bindingContext = context.trace.bindingContext
|
||||
val thisForSuperCall = getSuperCallLabelTarget(bindingContext, superCallExpression)
|
||||
|
||||
if (thisForSuperCall != null && DescriptorUtils.isInterface(thisForSuperCall)) {
|
||||
val declarationWithCall = findInterfaceMember(thisForSuperCall, superCallExpression, bindingContext)
|
||||
if (declarationWithCall?.isCompiledToJvmDefaultIfNoAbstract(jvmDefaultMode) == false) {
|
||||
if (declarationWithCall?.isCompiledToJvmDefault(jvmDefaultMode) == false) {
|
||||
context.trace.report(INTERFACE_CANT_CALL_DEFAULT_METHOD_VIA_SUPER.on(reportOn))
|
||||
return
|
||||
}
|
||||
|
||||
+3
-3
@@ -18,7 +18,7 @@ import org.jetbrains.kotlin.resolve.OverridingUtil
|
||||
import org.jetbrains.kotlin.resolve.checkers.DeclarationChecker
|
||||
import org.jetbrains.kotlin.resolve.checkers.DeclarationCheckerContext
|
||||
import org.jetbrains.kotlin.resolve.jvm.annotations.JVM_DEFAULT_FQ_NAME
|
||||
import org.jetbrains.kotlin.resolve.jvm.annotations.isCompiledToJvmDefaultIfNoAbstract
|
||||
import org.jetbrains.kotlin.resolve.jvm.annotations.isCompiledToJvmDefault
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
||||
|
||||
class JvmDefaultChecker(val jvmTarget: JvmTarget) : DeclarationChecker {
|
||||
@@ -41,7 +41,7 @@ class JvmDefaultChecker(val jvmTarget: JvmTarget) : DeclarationChecker {
|
||||
if (descriptor is ClassDescriptor) {
|
||||
val hasDeclaredJvmDefaults =
|
||||
descriptor.unsubstitutedMemberScope.getContributedDescriptors().filterIsInstance<CallableMemberDescriptor>().any {
|
||||
it.kind.isReal && it.isCompiledToJvmDefaultIfNoAbstract(jvmDefaultMode)
|
||||
it.kind.isReal && it.isCompiledToJvmDefault(jvmDefaultMode)
|
||||
}
|
||||
if (!hasDeclaredJvmDefaults && !checkJvmDefaultsInHierarchy(descriptor, jvmDefaultMode)) {
|
||||
context.trace.report(ErrorsJvm.JVM_DEFAULT_THROUGH_INHERITANCE.on(declaration))
|
||||
@@ -74,7 +74,7 @@ class JvmDefaultChecker(val jvmTarget: JvmTarget) : DeclarationChecker {
|
||||
return descriptor.unsubstitutedMemberScope.getContributedDescriptors().filterIsInstance<CallableMemberDescriptor>()
|
||||
.all { memberDescriptor ->
|
||||
memberDescriptor.kind.isReal || OverridingUtil.filterOutOverridden(memberDescriptor.overriddenDescriptors.toSet()).all {
|
||||
!isInterface(it.containingDeclaration) || !it.isCompiledToJvmDefaultIfNoAbstract(jvmDefaultMode) || it.modality == Modality.ABSTRACT
|
||||
!isInterface(it.containingDeclaration) || !it.isCompiledToJvmDefault(jvmDefaultMode) || it.modality == Modality.ABSTRACT
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.resolve.calls.callResolverUtil.getSuperCallExpressio
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallCheckerContext
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.jvm.annotations.isCompiledToJvmDefaultIfNoAbstract
|
||||
import org.jetbrains.kotlin.resolve.jvm.annotations.isCompiledToJvmDefault
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
||||
|
||||
class JvmDefaultSuperCallChecker : CallChecker {
|
||||
@@ -23,7 +23,7 @@ class JvmDefaultSuperCallChecker : CallChecker {
|
||||
if (getSuperCallExpression(resolvedCall.call) == null) return
|
||||
|
||||
val resultingDescriptor = resolvedCall.resultingDescriptor as? CallableMemberDescriptor ?: return
|
||||
if (!resultingDescriptor.isCompiledToJvmDefaultIfNoAbstract(jvmDefaultMode)) return
|
||||
if (!resultingDescriptor.isCompiledToJvmDefault(jvmDefaultMode)) return
|
||||
|
||||
if (DescriptorUtils.isInterface(resultingDescriptor.containingDeclaration)) {
|
||||
context.trace.report(ErrorsJvm.USAGE_OF_JVM_DEFAULT_THROUGH_SUPER_CALL.on(reportOn))
|
||||
|
||||
Reference in New Issue
Block a user