aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/Symbols.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-04-07 21:50:00 +0200
committerMartin Odersky <odersky@gmail.com>2016-04-07 21:53:59 +0200
commitcc7acead9472643a2bdf73ac49d8d28f444d5fce (patch)
tree88da0bba6f6e7e28ebd404112cc54d6fb836dbc8 /src/dotty/tools/dotc/core/Symbols.scala
parent8ddfa83177c5962e06a0a2ee2365e2e62ea6dfa0 (diff)
downloaddotty-cc7acead9472643a2bdf73ac49d8d28f444d5fce.tar.gz
dotty-cc7acead9472643a2bdf73ac49d8d28f444d5fce.tar.bz2
dotty-cc7acead9472643a2bdf73ac49d8d28f444d5fce.zip
Take SourceFile annotations into account when computing sourceFile
If a file was loaded from TASTY, it can not still have a non-null source file, since the source file is unpickled into the annotation of a top-level class. Also, fix typo in previous commit.
Diffstat (limited to 'src/dotty/tools/dotc/core/Symbols.scala')
-rw-r--r--src/dotty/tools/dotc/core/Symbols.scala28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/dotty/tools/dotc/core/Symbols.scala b/src/dotty/tools/dotc/core/Symbols.scala
index 2a76f18d8..d40acdfa7 100644
--- a/src/dotty/tools/dotc/core/Symbols.scala
+++ b/src/dotty/tools/dotc/core/Symbols.scala
@@ -21,6 +21,7 @@ import StdNames._
import NameOps._
import ast.tpd.Tree
import ast.TreeTypeMap
+import Constants.Constant
import Denotations.{ Denotation, SingleDenotation, MultiDenotation }
import collection.mutable
import io.AbstractFile
@@ -463,20 +464,23 @@ object Symbols {
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)
+ final def binaryFile(implicit ctx: Context): AbstractFile = {
+ val file = associatedFile
+ if (file != null && file.path.endsWith("class")) file else null
+ }
/** 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
+ final def sourceFile(implicit ctx: Context): AbstractFile = {
+ val file = associatedFile
+ if (file != null && !file.path.endsWith("class")) file
+ else denot.topLevelClass.getAnnotation(defn.SourceFileAnnot) match {
+ case Some(sourceAnnot) => sourceAnnot.argumentConstant(0) match {
+ case Some(Constant(path: String)) => AbstractFile.getFile(path)
+ case none => null
+ }
+ case none => null
+ }
+ }
/** The position of this symbol, or NoPosition is symbol was not loaded
* from source.