-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #562 from scalacenter/anonClass
Anon class
- Loading branch information
Showing
10 changed files
with
288 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...unpickler/src/main/scala/ch/epfl/scala/debugadapter/internal/stacktrace/Definitions.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package ch.epfl.scala.debugadapter.internal.stacktrace | ||
|
||
import tastyquery.Contexts.Context | ||
import tastyquery.Names.* | ||
|
||
class Definitions(using ctx: Context): | ||
val scalaPackage = ctx.defn.scalaPackage | ||
val scalaRuntimePackage = scalaPackage.getPackageDecl(SimpleName("runtime")).get | ||
val javaPackage = ctx.defn.RootPackage.getPackageDecl(SimpleName("java")).get | ||
val javaIOPackage = javaPackage.getPackageDecl(SimpleName("io")).get | ||
val partialFunction = scalaPackage.getDecl(typeName("PartialFunction")).get.asClass | ||
val abstractPartialFunction = scalaRuntimePackage.getDecl(typeName("AbstractPartialFunction")).get.asClass | ||
val serializable = javaIOPackage.getDecl(typeName("Serializable")).get.asClass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
.../unpickler/src/main/scala/ch/epfl/scala/debugadapter/internal/stacktrace/extensions.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package ch.epfl.scala.debugadapter.internal.stacktrace | ||
|
||
import tastyquery.Symbols.* | ||
import tastyquery.Modifiers.TermSymbolKind | ||
|
||
extension (symbol: Symbol) | ||
def isTrait = symbol.isClass && symbol.asClass.isTrait | ||
def isAnonFun = symbol.nameStr == "$anonfun" | ||
def isAnonClass = symbol.nameStr == "$anon" | ||
def matchName(name: String) = | ||
symbol.nameStr == name | ||
def isLocal = symbol.owner.isTerm | ||
def isModuleClass = symbol.isClass && symbol.asClass.isModuleClass | ||
def nameStr = symbol.name.toString | ||
|
||
extension (symbol: TermSymbol) | ||
private def isGetterOrSetter = !symbol.isMethod || symbol.isSetter | ||
private def isLazyValInTrait: Boolean = symbol.owner.isTrait && symbol.isLazyVal | ||
private def isLazyVal: Boolean = symbol.kind == TermSymbolKind.LazyVal | ||
|
||
extension [T <: Symbol](symbols: Seq[T]) | ||
def singleOrThrow(binaryName: String): T = | ||
singleOptOrThrow(binaryName) | ||
.getOrElse(throw new NotFoundException(s"Cannot find Scala symbol of $binaryName")) | ||
|
||
def singleOptOrThrow(binaryName: String): Option[T] = | ||
if symbols.size > 1 then throw new AmbiguousException(s"Found ${symbols.size} matching symbols for $binaryName") | ||
else symbols.headOption |
Oops, something went wrong.