Refactoring: ClassDescriptor.isFinal, no more Modality.isOverridable
This commit is contained in:
@@ -154,7 +154,7 @@ public class MutableClassDescriptor extends ClassDescriptorBase implements Class
|
|||||||
this.typeConstructor = TypeConstructorImpl.createForClass(
|
this.typeConstructor = TypeConstructorImpl.createForClass(
|
||||||
this,
|
this,
|
||||||
Annotations.Companion.getEMPTY(),
|
Annotations.Companion.getEMPTY(),
|
||||||
!getModality().isOverridable(),
|
ModalityKt.isFinal(this),
|
||||||
getName().asString(),
|
getName().asString(),
|
||||||
typeParameters,
|
typeParameters,
|
||||||
supertypes
|
supertypes
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ private fun KotlinType.canHaveSubtypesIgnoringNullability(): Boolean {
|
|||||||
|
|
||||||
when (descriptor) {
|
when (descriptor) {
|
||||||
is TypeParameterDescriptor -> return true
|
is TypeParameterDescriptor -> return true
|
||||||
is ClassDescriptor -> if (descriptor.modality.isOverridable) return true
|
is ClassDescriptor -> if (!descriptor.isFinal) return true
|
||||||
}
|
}
|
||||||
|
|
||||||
for ((parameter, argument) in constructor.parameters.zip(arguments)) {
|
for ((parameter, argument) in constructor.parameters.zip(arguments)) {
|
||||||
|
|||||||
+1
-1
@@ -447,7 +447,7 @@ public class DataFlowValueFactory {
|
|||||||
DeclarationDescriptor containingDeclaration = propertyDescriptor.getContainingDeclaration();
|
DeclarationDescriptor containingDeclaration = propertyDescriptor.getContainingDeclaration();
|
||||||
if (containingDeclaration instanceof ClassDescriptor) {
|
if (containingDeclaration instanceof ClassDescriptor) {
|
||||||
ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration;
|
ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration;
|
||||||
if (classDescriptor.getModality().isOverridable() && ModalityKt.isOverridable(propertyDescriptor)) return false;
|
if (!ModalityKt.isFinal(classDescriptor) && ModalityKt.isOverridable(propertyDescriptor)) return false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (ModalityKt.isOverridable(propertyDescriptor)) {
|
if (ModalityKt.isOverridable(propertyDescriptor)) {
|
||||||
|
|||||||
+1
-1
@@ -676,7 +676,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isFinal() {
|
public boolean isFinal() {
|
||||||
return !getModality().isOverridable();
|
return getModality() == Modality.FINAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+1
-1
@@ -206,7 +206,7 @@ class LazyJavaClassDescriptor(
|
|||||||
|
|
||||||
override fun getAnnotations() = Annotations.EMPTY
|
override fun getAnnotations() = Annotations.EMPTY
|
||||||
|
|
||||||
override fun isFinal() = !getModality().isOverridable
|
override fun isFinal(): Boolean = isFinal
|
||||||
|
|
||||||
override fun isDenotable() = true
|
override fun isDenotable() = true
|
||||||
|
|
||||||
|
|||||||
@@ -17,13 +17,13 @@
|
|||||||
package org.jetbrains.kotlin.descriptors
|
package org.jetbrains.kotlin.descriptors
|
||||||
|
|
||||||
// For sealed classes, isOverridable is false but isOverridableByMembers is true
|
// For sealed classes, isOverridable is false but isOverridableByMembers is true
|
||||||
enum class Modality private constructor(val isOverridable: Boolean) {
|
enum class Modality {
|
||||||
// THE ORDER OF ENTRIES MATTERS HERE
|
// THE ORDER OF ENTRIES MATTERS HERE
|
||||||
FINAL(false),
|
FINAL,
|
||||||
// NB: class can be sealed but not function or property
|
// NB: class can be sealed but not function or property
|
||||||
SEALED(true),
|
SEALED,
|
||||||
OPEN(true),
|
OPEN,
|
||||||
ABSTRACT(true);
|
ABSTRACT;
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
@@ -39,3 +39,5 @@ enum class Modality private constructor(val isOverridable: Boolean) {
|
|||||||
val CallableMemberDescriptor.isOverridable: Boolean
|
val CallableMemberDescriptor.isOverridable: Boolean
|
||||||
get() = modality != Modality.FINAL
|
get() = modality != Modality.FINAL
|
||||||
|
|
||||||
|
val ClassDescriptor.isFinal: Boolean
|
||||||
|
get() = modality == Modality.FINAL
|
||||||
|
|||||||
+1
-1
@@ -181,7 +181,7 @@ public class DeserializedClassDescriptor(
|
|||||||
|
|
||||||
override fun getSupertypes() = supertypes()
|
override fun getSupertypes() = supertypes()
|
||||||
|
|
||||||
override fun isFinal() = !getModality().isOverridable
|
override fun isFinal(): Boolean = isFinal
|
||||||
|
|
||||||
override fun isDenotable() = true
|
override fun isDenotable() = true
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -27,6 +27,7 @@ import com.intellij.psi.PsiNamedElement
|
|||||||
import com.intellij.psi.util.PsiTreeUtil
|
import com.intellij.psi.util.PsiTreeUtil
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||||
|
import org.jetbrains.kotlin.descriptors.isFinal
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||||
import org.jetbrains.kotlin.idea.util.getResolutionScope
|
import org.jetbrains.kotlin.idea.util.getResolutionScope
|
||||||
@@ -73,7 +74,7 @@ class AnonymousSuperMacro : Macro() {
|
|||||||
|
|
||||||
return resolutionScope
|
return resolutionScope
|
||||||
.collectDescriptorsFiltered(DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS)
|
.collectDescriptorsFiltered(DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS)
|
||||||
.filter { it is ClassDescriptor && it.modality.isOverridable && (it.kind == ClassKind.CLASS || it.kind == ClassKind.INTERFACE) }
|
.filter { it is ClassDescriptor && !it.isFinal && (it.kind == ClassKind.CLASS || it.kind == ClassKind.INTERFACE) }
|
||||||
.mapNotNull { DescriptorToSourceUtils.descriptorToDeclaration(it) as PsiNamedElement? }
|
.mapNotNull { DescriptorToSourceUtils.descriptorToDeclaration(it) as PsiNamedElement? }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ public class ManglingUtils {
|
|||||||
ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration;
|
ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration;
|
||||||
|
|
||||||
// Use stable mangling when it's inside an overridable declaration to avoid clashing names on inheritance.
|
// Use stable mangling when it's inside an overridable declaration to avoid clashing names on inheritance.
|
||||||
if (classDescriptor.getModality().isOverridable()) {
|
if (!ModalityKt.isFinal(classDescriptor)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user