aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/Symbols.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-02-23 13:36:05 +0100
committerMartin Odersky <odersky@gmail.com>2013-02-23 13:36:05 +0100
commit7cde8b6d78022aadb00d3f82fb9019da39a62b49 (patch)
tree389ce0d44ecec47a7fa6caec79d252fe129d5116 /src/dotty/tools/dotc/core/Symbols.scala
parentd54fee4fcc75d5e9b58353da9daea0aa1b760aeb (diff)
downloaddotty-7cde8b6d78022aadb00d3f82fb9019da39a62b49.tar.gz
dotty-7cde8b6d78022aadb00d3f82fb9019da39a62b49.tar.bz2
dotty-7cde8b6d78022aadb00d3f82fb9019da39a62b49.zip
Moving associatedFile from SymDenotation to Symbol
Motivation: This is something that stays invariant over all periods. but _can_ change between compilation runs. Therefore it matches the lifetime of a Symbol.
Diffstat (limited to 'src/dotty/tools/dotc/core/Symbols.scala')
-rw-r--r--src/dotty/tools/dotc/core/Symbols.scala31
1 files changed, 28 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/core/Symbols.scala b/src/dotty/tools/dotc/core/Symbols.scala
index edd610bca..2aec15894 100644
--- a/src/dotty/tools/dotc/core/Symbols.scala
+++ b/src/dotty/tools/dotc/core/Symbols.scala
@@ -27,7 +27,7 @@ trait Symbols { this: Context =>
}
def newLazyClassSymbol(owner: Symbol, name: TypeName, initFlags: FlagSet, completer: ClassCompleter, assocFile: AbstractFile = null, coord: Coord = NoCoord) =
- new ClassSymbol(coord, new LazyClassDenotation(_, owner, name, initFlags, completer, assocFile)(this))
+ new ClassSymbol(coord, new LazyClassDenotation(_, owner, name, initFlags, completer)(this), assocFile)
def newLazyModuleSymbols(owner: Symbol,
name: TermName,
@@ -64,7 +64,7 @@ trait Symbols { this: Context =>
coord: Coord = NoCoord)
=
new ClassSymbol(coord, new CompleteClassDenotation(
- _, owner, name, flags, parents, privateWithin, optSelfType, decls, assocFile)(this))
+ _, owner, name, flags, parents, privateWithin, optSelfType, decls)(this), assocFile)
def newModuleSymbols(
owner: Symbol,
@@ -257,6 +257,26 @@ object Symbols {
/** The current name of this symbol */
final def name(implicit ctx: Context): ThisName = denot.name.asInstanceOf[ThisName]
+ /** The source or class file from which this class was generated, null if not applicable. */
+ def associatedFile(implicit ctx: Context): AbstractFile =
+ this.denot.topLevelClass.symbol.associatedFile
+
+ /** The class file from which this class was generated, null if not applicable. */
+ final def binaryFile(implicit ctx: Context): AbstractFile =
+ pickFile(associatedFile, classFile = true)
+
+ /** The source file from which this class was generated, null if not applicable. */
+ final def sourceFile(implicit ctx: Context): AbstractFile =
+ pickFile(associatedFile, classFile = false)
+
+ /** Desire to re-use the field in ClassSymbol which stores the source
+ * file to also store the classfile, but without changing the behavior
+ * of sourceFile (which is expected at least in the IDE only to
+ * return actual source code.) So sourceFile has classfiles filtered out.
+ */
+ private def pickFile(file: AbstractFile, classFile: Boolean): AbstractFile =
+ if ((file eq null) || classFile != (file.path endsWith ".class")) null else file
+
def show(implicit ctx: Context): String = ctx.show(this)
def showLocated(implicit ctx: Context): String = ctx.showLocated(this)
def showDcl(implicit ctx: Context): String = ctx.showDcl(this)
@@ -269,10 +289,15 @@ object Symbols {
type TermSymbol = Symbol { type ThisName = TermName }
type TypeSymbol = Symbol { type ThisName = TypeName }
- class ClassSymbol(coord: Coord, denotf: ClassSymbol => ClassDenotation) extends Symbol(coord, s => denotf(s.asClass)) {
+ class ClassSymbol(coord: Coord, denotf: ClassSymbol => ClassDenotation, assocFile: AbstractFile) extends Symbol(coord, s => denotf(s.asClass)) {
type ThisName = TypeName
+ /** The source or class file from which this class was generated, null if not applicable. */
+ override def associatedFile(implicit ctx: Context): AbstractFile =
+ if (this.owner.isPackageClass) assocFile
+ else super.associatedFile
+
final def classDenot(implicit ctx: Context): ClassDenotation =
denot.asInstanceOf[ClassDenotation]