Skip to content

Commit

Permalink
Backport "Adjust the API name entry for nested classes" to LTS (#21106)
Browse files Browse the repository at this point in the history
Backports #20279 to the LTS branch.

PR submitted by the release tooling.
  • Loading branch information
WojciechMazur authored Jul 6, 2024
2 parents 96e68a1 + 6a39b40 commit 0d787e2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ private class ExtractAPICollector(using Context) extends ThunkHolder {

val selfType = apiType(sym.givenSelfType)

val name = sym.fullName.stripModuleClassSuffix.toString
val name = ExtractDependencies.classNameAsString(sym)
// We strip module class suffix. Zinc relies on a class and its companion having the same name

val tparams = sym.typeParams.map(apiTypeParameter).toArray
Expand Down
18 changes: 17 additions & 1 deletion compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,24 @@ object ExtractDependencies {
val name: String = "sbt-deps"
val description: String = "sends information on classes' dependencies to sbt"

/** Construct String name for the given sym.
* See https://github.com/sbt/zinc/blob/v1.9.6/internal/zinc-apiinfo/src/main/scala/sbt/internal/inc/ClassToAPI.scala#L86-L99
*
* For a Java nested class M of a class C returns C's canonical name + "." + M's simple name.
*/
def classNameAsString(sym: Symbol)(using Context): String =
sym.fullName.stripModuleClassSuffix.toString
def isJava(sym: Symbol)(using Context): Boolean =
Option(sym.source) match
case Some(src) => src.toString.endsWith(".java")
case None => false
def classNameAsString0(sym: Symbol)(using Context): String =
sym.fullName.stripModuleClassSuffix.toString
def javaClassNameAsString(sym: Symbol)(using Context): String =
if sym.owner.isClass && !sym.owner.isRoot then
javaClassNameAsString(sym.owner) + "." + sym.name.stripModuleClassSuffix.toString
else classNameAsString0(sym)
if isJava(sym) then javaClassNameAsString(sym)
else classNameAsString0(sym)

/** Report an internal error in incremental compilation. */
def internalError(msg: => String, pos: SrcPos = NoSourcePosition)(using Context): Unit =
Expand Down

0 comments on commit 0d787e2

Please sign in to comment.