Skip to content

Commit 0d787e2

Browse files
Backport "Adjust the API name entry for nested classes" to LTS (#21106)
Backports #20279 to the LTS branch. PR submitted by the release tooling.
2 parents 96e68a1 + 6a39b40 commit 0d787e2

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

Diff for: compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ private class ExtractAPICollector(using Context) extends ThunkHolder {
229229

230230
val selfType = apiType(sym.givenSelfType)
231231

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

235235
val tparams = sym.typeParams.map(apiTypeParameter).toArray

Diff for: compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala

+17-1
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,24 @@ object ExtractDependencies {
149149
val name: String = "sbt-deps"
150150
val description: String = "sends information on classes' dependencies to sbt"
151151

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

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

0 commit comments

Comments
 (0)