TypeAccessibilityChecker: rename existingFqNames to existingTypeNames and add comments
This commit is contained in:
+8
-1
@@ -16,7 +16,14 @@ import org.jetbrains.kotlin.types.KotlinType
|
|||||||
interface TypeAccessibilityChecker {
|
interface TypeAccessibilityChecker {
|
||||||
val project: Project
|
val project: Project
|
||||||
val targetModule: Module
|
val targetModule: Module
|
||||||
var existingFqNames: Collection<String>
|
|
||||||
|
/***
|
||||||
|
* Contains additional [FqName] as [String], which aren't available in the module at the time of verification.
|
||||||
|
*
|
||||||
|
* For example, you want to move `open class A<T : A>` class to another module.
|
||||||
|
* In this case, you should add [FqName] of class `A` in [existingTypeNames].
|
||||||
|
*/
|
||||||
|
var existingTypeNames: Collection<String>
|
||||||
|
|
||||||
fun incorrectTypes(declaration: KtNamedDeclaration): Collection<FqName?>
|
fun incorrectTypes(declaration: KtNamedDeclaration): Collection<FqName?>
|
||||||
fun incorrectTypes(descriptor: DeclarationDescriptor): Collection<FqName?>
|
fun incorrectTypes(descriptor: DeclarationDescriptor): Collection<FqName?>
|
||||||
|
|||||||
+6
-6
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
|||||||
class TypeAccessibilityCheckerImpl(
|
class TypeAccessibilityCheckerImpl(
|
||||||
override val project: Project,
|
override val project: Project,
|
||||||
override val targetModule: Module,
|
override val targetModule: Module,
|
||||||
override var existingFqNames: Collection<String> = emptyList()
|
override var existingTypeNames: Collection<String> = emptyList()
|
||||||
) : TypeAccessibilityChecker {
|
) : TypeAccessibilityChecker {
|
||||||
private val scope by lazy { GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(targetModule, targetModule.isTestModule) }
|
private val scope by lazy { GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(targetModule, targetModule.isTestModule) }
|
||||||
private var builtInsModule: ModuleDescriptor? = targetModule.toDescriptor()
|
private var builtInsModule: ModuleDescriptor? = targetModule.toDescriptor()
|
||||||
@@ -54,9 +54,9 @@ class TypeAccessibilityCheckerImpl(
|
|||||||
override fun checkAccessibility(type: KotlinType): Boolean = incorrectTypesInSequence(type.collectAllTypes(), true).isEmpty()
|
override fun checkAccessibility(type: KotlinType): Boolean = incorrectTypesInSequence(type.collectAllTypes(), true).isEmpty()
|
||||||
|
|
||||||
override fun <R> runInContext(fqNames: Collection<String>, block: TypeAccessibilityChecker.() -> R): R {
|
override fun <R> runInContext(fqNames: Collection<String>, block: TypeAccessibilityChecker.() -> R): R {
|
||||||
val oldValue = existingFqNames
|
val oldValue = existingTypeNames
|
||||||
existingFqNames = fqNames
|
existingTypeNames = fqNames
|
||||||
return block().also { existingFqNames = oldValue }
|
return block().also { existingTypeNames = oldValue }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun incorrectTypesInSequence(
|
private fun incorrectTypesInSequence(
|
||||||
@@ -70,13 +70,13 @@ class TypeAccessibilityCheckerImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun incorrectTypesInDescriptor(descriptor: DeclarationDescriptor, lazy: Boolean) =
|
private fun incorrectTypesInDescriptor(descriptor: DeclarationDescriptor, lazy: Boolean) =
|
||||||
runInContext(descriptor.additionalClasses(existingFqNames)) {
|
runInContext(descriptor.additionalClasses(existingTypeNames)) {
|
||||||
incorrectTypesInSequence(descriptor.collectAllTypes(), lazy)
|
incorrectTypesInSequence(descriptor.collectAllTypes(), lazy)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun FqName?.canFindClassInModule(): Boolean {
|
private fun FqName?.canFindClassInModule(): Boolean {
|
||||||
val name = this?.asString() ?: return false
|
val name = this?.asString() ?: return false
|
||||||
return name in existingFqNames
|
return name in existingTypeNames
|
||||||
|| KotlinFullClassNameIndex.getInstance()[name, project, scope].isNotEmpty()
|
|| KotlinFullClassNameIndex.getInstance()[name, project, scope].isNotEmpty()
|
||||||
|| builtInsModule?.resolveClassByFqName(this, NoLookupLocation.FROM_BUILTINS) != null
|
|| builtInsModule?.resolveClassByFqName(this, NoLookupLocation.FROM_BUILTINS) != null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ private fun TypeAccessibilityChecker.findAndApplyExistingClasses(elements: Colle
|
|||||||
var classes = elements.filterIsInstance<KtClassOrObject>()
|
var classes = elements.filterIsInstance<KtClassOrObject>()
|
||||||
while (true) {
|
while (true) {
|
||||||
val existingNames = classes.mapNotNull { it.fqName?.asString() }.toHashSet()
|
val existingNames = classes.mapNotNull { it.fqName?.asString() }.toHashSet()
|
||||||
existingFqNames = existingNames
|
existingTypeNames = existingNames
|
||||||
|
|
||||||
val newExistingClasses = classes.filter { isCorrectAndHaveNonPrivate(it) }
|
val newExistingClasses = classes.filter { isCorrectAndHaveNonPrivate(it) }
|
||||||
if (classes.size == newExistingClasses.size) return existingNames
|
if (classes.size == newExistingClasses.size) return existingNames
|
||||||
@@ -305,7 +305,7 @@ class CreateExpectedCallableMemberFix(
|
|||||||
return@block null
|
return@block null
|
||||||
}
|
}
|
||||||
val descriptor = element.toDescriptor() as? CallableMemberDescriptor
|
val descriptor = element.toDescriptor() as? CallableMemberDescriptor
|
||||||
checker.existingFqNames = targetExpectedClass?.getSuperNames()?.toSet().orEmpty()
|
checker.existingTypeNames = targetExpectedClass?.getSuperNames()?.toSet().orEmpty()
|
||||||
descriptor?.let {
|
descriptor?.let {
|
||||||
generateCallable(
|
generateCallable(
|
||||||
project,
|
project,
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ internal fun KtPsiFactory.generateClassOrObject(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val existingFqNamesWithSuperTypes = (checker.existingFqNames + superNames).toSet()
|
val existingFqNamesWithSuperTypes = (checker.existingTypeNames + superNames).toSet()
|
||||||
declLoop@ for (originalDeclaration in originalClass.declarations) {
|
declLoop@ for (originalDeclaration in originalClass.declarations) {
|
||||||
val descriptor = originalDeclaration.toDescriptor() ?: continue
|
val descriptor = originalDeclaration.toDescriptor() ?: continue
|
||||||
if (generateExpectClass && !originalDeclaration.isEffectivelyActual(false)) continue
|
if (generateExpectClass && !originalDeclaration.isEffectivelyActual(false)) continue
|
||||||
@@ -292,7 +292,7 @@ private fun KtCallableDeclaration.repairOverride(descriptor: CallableDescriptor,
|
|||||||
if (!hasModifier(KtTokens.OVERRIDE_KEYWORD)) return
|
if (!hasModifier(KtTokens.OVERRIDE_KEYWORD)) return
|
||||||
|
|
||||||
val superDescriptor = descriptor.overriddenDescriptors.firstOrNull()?.containingDeclaration
|
val superDescriptor = descriptor.overriddenDescriptors.firstOrNull()?.containingDeclaration
|
||||||
if (superDescriptor?.fqNameOrNull()?.shortName()?.asString() !in checker.existingFqNames) {
|
if (superDescriptor?.fqNameOrNull()?.shortName()?.asString() !in checker.existingTypeNames) {
|
||||||
removeModifier(KtTokens.OVERRIDE_KEYWORD)
|
removeModifier(KtTokens.OVERRIDE_KEYWORD)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user