Skip to content

Commit

Permalink
Merge pull request #338 from sjrd/deprecate-enclosingdecl
Browse files Browse the repository at this point in the history
Deprecate Symbol.enclosingDecl.
  • Loading branch information
sjrd authored Aug 12, 2023
2 parents 1b871f7 + 56802f7 commit d814dd5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
8 changes: 1 addition & 7 deletions tasty-query/shared/src/main/scala/tastyquery/Symbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,13 @@ object Symbols {
if isFlagsInitialized then myFlags
else throw IllegalStateException(s"flags of $this have not been initialized")

@deprecated("pattern-match on owner instead", since = "0.10.0")
final def enclosingDecl: DeclaringSymbol = owner match {
case owner: DeclaringSymbol => owner
case _: Symbol | null =>
assert(false, s"cannot access owner, ${this.name} is local or not declared within any scope")
}

/** The closest enclosing package of this symbol.
* Returns this if this is a package.
*/
private[tastyquery] final def closestPackage: PackageSymbol = this match
case pkg: PackageSymbol => pkg
case sym: TermOrTypeSymbol => sym.owner.closestPackage

private[Symbols] final def addDeclIfDeclaringSym(decl: TermOrTypeSymbol): decl.type =
this match
case declaring: DeclaringSymbol => declaring.addDecl(decl)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,16 @@ private[reader] object ClassfileParser {
)(using Context, Resolver): List[InnerClassDecl] = {
import structure.{reader, given}

val pkg = classOwner.closestPackage

val allRegisteredSymbols = mutable.ListBuffer.empty[Symbol]

val cls = ClassSymbol.create(name.toTypeName, classOwner)
allRegisteredSymbols += cls

def privateWithin(access: AccessFlags): Option[PackageSymbol] =
if access.isPackagePrivate then Some(pkg) else None
def enclosingPackage(sym: Symbol): PackageSymbol = sym match
case sym: PackageSymbol => sym
case sym: TermOrTypeSymbol => enclosingPackage(sym.owner)
if access.isPackagePrivate then Some(enclosingPackage(classOwner)) else None

val clsFlags = structure.access.toFlags | JavaDefined
val clsPrivateWithin = privateWithin(structure.access)
Expand Down

0 comments on commit d814dd5

Please sign in to comment.