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 {
|
||||
val project: Project
|
||||
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(descriptor: DeclarationDescriptor): Collection<FqName?>
|
||||
|
||||
+6
-6
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
class TypeAccessibilityCheckerImpl(
|
||||
override val project: Project,
|
||||
override val targetModule: Module,
|
||||
override var existingFqNames: Collection<String> = emptyList()
|
||||
override var existingTypeNames: Collection<String> = emptyList()
|
||||
) : TypeAccessibilityChecker {
|
||||
private val scope by lazy { GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(targetModule, targetModule.isTestModule) }
|
||||
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 <R> runInContext(fqNames: Collection<String>, block: TypeAccessibilityChecker.() -> R): R {
|
||||
val oldValue = existingFqNames
|
||||
existingFqNames = fqNames
|
||||
return block().also { existingFqNames = oldValue }
|
||||
val oldValue = existingTypeNames
|
||||
existingTypeNames = fqNames
|
||||
return block().also { existingTypeNames = oldValue }
|
||||
}
|
||||
|
||||
private fun incorrectTypesInSequence(
|
||||
@@ -70,13 +70,13 @@ class TypeAccessibilityCheckerImpl(
|
||||
}
|
||||
|
||||
private fun incorrectTypesInDescriptor(descriptor: DeclarationDescriptor, lazy: Boolean) =
|
||||
runInContext(descriptor.additionalClasses(existingFqNames)) {
|
||||
runInContext(descriptor.additionalClasses(existingTypeNames)) {
|
||||
incorrectTypesInSequence(descriptor.collectAllTypes(), lazy)
|
||||
}
|
||||
|
||||
private fun FqName?.canFindClassInModule(): Boolean {
|
||||
val name = this?.asString() ?: return false
|
||||
return name in existingFqNames
|
||||
return name in existingTypeNames
|
||||
|| KotlinFullClassNameIndex.getInstance()[name, project, scope].isNotEmpty()
|
||||
|| builtInsModule?.resolveClassByFqName(this, NoLookupLocation.FROM_BUILTINS) != null
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ private fun TypeAccessibilityChecker.findAndApplyExistingClasses(elements: Colle
|
||||
var classes = elements.filterIsInstance<KtClassOrObject>()
|
||||
while (true) {
|
||||
val existingNames = classes.mapNotNull { it.fqName?.asString() }.toHashSet()
|
||||
existingFqNames = existingNames
|
||||
existingTypeNames = existingNames
|
||||
|
||||
val newExistingClasses = classes.filter { isCorrectAndHaveNonPrivate(it) }
|
||||
if (classes.size == newExistingClasses.size) return existingNames
|
||||
@@ -305,7 +305,7 @@ class CreateExpectedCallableMemberFix(
|
||||
return@block null
|
||||
}
|
||||
val descriptor = element.toDescriptor() as? CallableMemberDescriptor
|
||||
checker.existingFqNames = targetExpectedClass?.getSuperNames()?.toSet().orEmpty()
|
||||
checker.existingTypeNames = targetExpectedClass?.getSuperNames()?.toSet().orEmpty()
|
||||
descriptor?.let {
|
||||
generateCallable(
|
||||
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) {
|
||||
val descriptor = originalDeclaration.toDescriptor() ?: continue
|
||||
if (generateExpectClass && !originalDeclaration.isEffectivelyActual(false)) continue
|
||||
@@ -292,7 +292,7 @@ private fun KtCallableDeclaration.repairOverride(descriptor: CallableDescriptor,
|
||||
if (!hasModifier(KtTokens.OVERRIDE_KEYWORD)) return
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user