forked from sbt/sbt
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clarify source and binary class name handling.
Introduce ClassName trait that centralizes logic for creating both source and binary names for a class symbol. In addition to using it in Analyzer, Dependency, ExtractDeclaredClasses we also use it in ExtractAPI. We want every component of the incremental compiler to use consitent naming scheme. Add ClassNameSpecification that documents expected behavior of ClassName.
- Loading branch information
1 parent
ba92ff4
commit 87fd296
Showing
8 changed files
with
106 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package xsbt | ||
|
||
/** | ||
* Utility methods for creating (source|binary) class names for a Symbol. | ||
*/ | ||
trait ClassName extends Compat { | ||
val global: CallbackGlobal | ||
import global._ | ||
|
||
/** | ||
* Creates a flat (binary) name for a class symbol `s`. | ||
*/ | ||
protected def flatname(s: Symbol, separator: Char): String = | ||
atPhase(currentRun.flattenPhase.next) { s fullName separator } | ||
|
||
/** | ||
* Create a (source) name for a class symbol `s`. | ||
*/ | ||
protected def className(s: Symbol): String = pickledName(s) | ||
|
||
private def pickledName(s: Symbol): String = | ||
atPhase(currentRun.picklerPhase) { s.fullName } | ||
|
||
protected def isTopLevelModule(sym: Symbol): Boolean = | ||
atPhase(currentRun.picklerPhase.next) { | ||
sym.isModuleClass && !sym.isImplClass && !sym.isNestedClass | ||
} | ||
|
||
protected def flatclassName(s: Symbol, sep: Char, dollarRequired: Boolean): String = | ||
flatname(s, sep) + (if (dollarRequired) "$" else "") | ||
} |
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
63 changes: 63 additions & 0 deletions
63
compile/interface/src/test/scala/xsbt/ClassNameSpecification.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,63 @@ | ||
package xsbt | ||
|
||
import org.junit.runner.RunWith | ||
import xsbti.TestCallback.ExtractedClassDependencies | ||
import xsbti.api.ClassLike | ||
import xsbti.api.Def | ||
import xsbt.api.SameAPI | ||
import org.specs2.mutable.Specification | ||
import org.specs2.runner.JUnitRunner | ||
|
||
@RunWith(classOf[JUnitRunner]) | ||
class ClassNameSpecification extends Specification { | ||
|
||
"Binary names for top level object" in { | ||
val src = "object A" | ||
|
||
val compilerForTesting = new ScalaCompilerForUnitTesting(nameHashing = true) | ||
val binaryClassNames = compilerForTesting.extractBinaryClassNamesFromSrc(src) | ||
|
||
binaryClassNames === Set("A" -> "A", "A" -> "A$") | ||
} | ||
|
||
"Binary names for top level companion object" in { | ||
val src = "class A; object A" | ||
|
||
val compilerForTesting = new ScalaCompilerForUnitTesting(nameHashing = true) | ||
val binaryClassNames = compilerForTesting.extractBinaryClassNamesFromSrc(src) | ||
|
||
binaryClassNames === Set("A" -> "A", "A" -> "A$") | ||
} | ||
|
||
"Binary names for nested object" in { | ||
val src = | ||
"""|object A { | ||
| object C { | ||
| object D | ||
| } | ||
|} | ||
|class B { | ||
| object E | ||
|} | ||
""".stripMargin | ||
|
||
val compilerForTesting = new ScalaCompilerForUnitTesting(nameHashing = true) | ||
val binaryClassNames = compilerForTesting.extractBinaryClassNamesFromSrc(src) | ||
|
||
binaryClassNames === Set("A" -> "A$", "A" -> "A", "A.C" -> "A$C$", "A.C.D" -> "A$C$D$", | ||
"B" -> "B", "B.E" -> "B$E$") | ||
} | ||
|
||
"Binary names for trait" in { | ||
val src = | ||
"""|trait A | ||
""".stripMargin | ||
|
||
val compilerForTesting = new ScalaCompilerForUnitTesting(nameHashing = true) | ||
val binaryClassNames = compilerForTesting.extractBinaryClassNamesFromSrc(src) | ||
|
||
// we do not track $impl classes because nobody can depend on them directly | ||
binaryClassNames === Set("A" -> "A") | ||
} | ||
|
||
} |
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