Skip to content

Commit

Permalink
Apply Grigorii's suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
jesyspa committed Jul 24, 2024
1 parent f391ca1 commit c446acb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ val NameScope.fullMangledName: String?
}

val NameScope.packageNameIfAny: FqName?
get() = allParentScopes.filterIsInstance<PackageScope>().firstOrNull()?.packageName
get() = allParentScopes.filterIsInstance<PackageScope>().lastOrNull()?.packageName

val NameScope.classNameIfAny: ClassKotlinName?
get() = allParentScopes.filterIsInstance<ClassScope>().firstOrNull()?.className
get() = allParentScopes.filterIsInstance<ClassScope>().lastOrNull()?.className

data class PackageScope(val packageName: FqName) : NameScope {
override val parent = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ class ScopedKotlinNameBuilder {
}

fun classScope(className: ClassKotlinName) {
require (scope != null) { "Public class scope cannot be top-level" }
require (scope != null) { "Class scope cannot be top-level" }
scope = ClassScope(scope!!, className)
}

fun publicScope() {
require(scope != null) { "Public class scope cannot be top-level" }
require(scope is ClassScope) { "Public scope must be in a class scope." }
scope = PublicScope(scope!!)
}

fun privateScope() {
require(scope != null) { "Private class scope cannot be top-level" }
require(scope is ClassScope) { "Private scope must be in a class scope." }
scope = PrivateScope(scope!!)
}

Expand All @@ -58,6 +58,4 @@ class ScopedKotlinNameBuilder {

// TODO: generalise this to work for all names.
fun buildName(init: ScopedKotlinNameBuilder.() -> KotlinName): ScopedKotlinName =
ScopedKotlinNameBuilder().let {
it.complete(it.init())
}
ScopedKotlinNameBuilder().run { complete(init()) }

0 comments on commit c446acb

Please sign in to comment.