ExpectActualUtils: rename checkTypeInSequence to incorrectTypesInSequence & change return type
This commit is contained in:
@@ -435,29 +435,39 @@ class KotlinTypeInaccessibleException(val type: KotlinType) : Exception() {
|
|||||||
get() = "Type ${type.getJetTypeFqName(true)} is not accessible from common code"
|
get() = "Type ${type.getJetTypeFqName(true)} is not accessible from common code"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun KtNamedDeclaration.checkTypeAccessibilityInModule(module: Module, existingClasses: Set<String> = emptySet()): Boolean {
|
||||||
|
return !hasPrivateModifier() && descriptor?.checkTypeAccessibilityInModule(project, module, existingClasses) == true
|
||||||
|
}
|
||||||
|
|
||||||
fun DeclarationDescriptor.checkTypeAccessibilityInModule(
|
fun DeclarationDescriptor.checkTypeAccessibilityInModule(
|
||||||
project: Project,
|
project: Project,
|
||||||
module: Module,
|
module: Module,
|
||||||
existingClasses: Set<String> = emptySet()
|
existingClasses: Set<String> = emptySet()
|
||||||
): Boolean = checkTypeInSequence(collectAllTypes(), project, module, additionalClasses(existingClasses))
|
): Boolean = incorrectTypesInSequence(collectAllTypes(), project, module, additionalClasses(existingClasses)).isEmpty()
|
||||||
|
|
||||||
fun KotlinType.checkTypeAccessibilityInModule(
|
fun KotlinType.checkTypeAccessibilityInModule(
|
||||||
project: Project,
|
project: Project,
|
||||||
module: Module,
|
module: Module,
|
||||||
existingClasses: Set<String> = emptySet()
|
existingClasses: Set<String> = emptySet()
|
||||||
): Boolean = checkTypeInSequence(collectAllTypes(), project, module, existingClasses)
|
): Boolean = incorrectTypesInSequence(collectAllTypes(), project, module, existingClasses).isEmpty()
|
||||||
|
|
||||||
private fun checkTypeInSequence(sequence: Sequence<FqName?>, project: Project, module: Module, existingClasses: Set<String>): Boolean {
|
private fun incorrectTypesInSequence(
|
||||||
|
sequence: Sequence<FqName?>,
|
||||||
|
project: Project,
|
||||||
|
module: Module,
|
||||||
|
existingClasses: Set<String>,
|
||||||
|
lazy: Boolean = true
|
||||||
|
): List<FqName?> {
|
||||||
val builtInsModule = module.toDescriptor()
|
val builtInsModule = module.toDescriptor()
|
||||||
val scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, module.isTestModule)
|
val scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, module.isTestModule)
|
||||||
return sequence.all { fqName ->
|
fun predicate(fqName: FqName?): Boolean = fqName != null
|
||||||
if (fqName == null) return false
|
&& (builtInsModule?.resolveClassByFqName(fqName, NoLookupLocation.FROM_BUILTINS) != null
|
||||||
builtInsModule?.resolveClassByFqName(fqName, NoLookupLocation.FROM_BUILTINS) != null || fqName.canFindClassInModule(
|
|| fqName.canFindClassInModule(project, scope, existingClasses))
|
||||||
project,
|
|
||||||
scope,
|
return if (lazy) {
|
||||||
existingClasses
|
for (fqName in sequence) if (!predicate(fqName)) return listOf(fqName)
|
||||||
)
|
emptyList()
|
||||||
}
|
} else sequence.filterNot(::predicate).toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
private tailrec fun DeclarationDescriptor.additionalClasses(existingClasses: Set<String> = emptySet()): Set<String> = when (this) {
|
private tailrec fun DeclarationDescriptor.additionalClasses(existingClasses: Set<String> = emptySet()): Set<String> = when (this) {
|
||||||
@@ -499,10 +509,6 @@ private fun KotlinType.collectAllTypes(): Sequence<FqName?> = sequenceOf(fqName)
|
|||||||
fun KtNamedDeclaration.isAlwaysActual(): Boolean = safeAs<KtParameter>()?.parent?.parent?.safeAs<KtPrimaryConstructor>()
|
fun KtNamedDeclaration.isAlwaysActual(): Boolean = safeAs<KtParameter>()?.parent?.parent?.safeAs<KtPrimaryConstructor>()
|
||||||
?.mustHaveValOrVar() ?: false
|
?.mustHaveValOrVar() ?: false
|
||||||
|
|
||||||
fun KtNamedDeclaration.checkTypeAccessibilityInModule(module: Module, existingClasses: Set<String> = emptySet()): Boolean {
|
|
||||||
return !hasPrivateModifier() && descriptor?.checkTypeAccessibilityInModule(project, module, existingClasses) == true
|
|
||||||
}
|
|
||||||
|
|
||||||
val KotlinType.fqName: FqName? get() = constructor.declarationDescriptor?.fqNameOrNull()
|
val KotlinType.fqName: FqName? get() = constructor.declarationDescriptor?.fqNameOrNull()
|
||||||
|
|
||||||
private fun FqName.canFindClassInModule(project: Project, scope: GlobalSearchScope, existedClasses: Set<String>): Boolean {
|
private fun FqName.canFindClassInModule(project: Project, scope: GlobalSearchScope, existedClasses: Set<String>): Boolean {
|
||||||
|
|||||||
Reference in New Issue
Block a user