@@ -11,7 +11,7 @@ import scala.collection.mutable.ListBuffer
1111import util .{ Statistics , shortClassOfInstance }
1212import Flags ._
1313import scala .annotation .tailrec
14- import scala .reflect .io .AbstractFile
14+ import scala .reflect .io .{ AbstractFile , NoAbstractFile }
1515
1616trait Symbols extends api.Symbols { self : SymbolTable =>
1717 import definitions ._
@@ -1916,8 +1916,8 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
19161916 (this .rawInfo ne NoType )
19171917 && (this .effectiveOwner == that.effectiveOwner)
19181918 && ( ! this .effectiveOwner.isPackageClass
1919- || (this .associatedFile eq null )
1920- || (that.associatedFile eq null )
1919+ || (this .associatedFile eq NoAbstractFile )
1920+ || (that.associatedFile eq NoAbstractFile )
19211921 || (this .associatedFile.path == that.associatedFile.path) // Cheap possibly wrong check, then expensive normalization
19221922 || (this .associatedFile.canonicalPath == that.associatedFile.canonicalPath)
19231923 )
@@ -2176,17 +2176,16 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
21762176 case _ => NoSymbol
21772177 }
21782178
2179- /** Desire to re-use the field in ClassSymbol which stores the source
2180- * file to also store the classfile, but without changing the behavior
2181- * of sourceFile (which is expected at least in the IDE only to
2182- * return actual source code.) So sourceFile has classfiles filtered out.
2183- */
2184- private def sourceFileOnly (file : AbstractFile ): AbstractFile =
2185- if ((file eq null ) || (file.path endsWith " .class" )) null else file
2186-
2187- final def sourceFile : AbstractFile = sourceFileOnly(associatedFile)
2179+ // Desire to re-use the field in ClassSymbol which stores the source
2180+ // file to also store the classfile, but without changing the behavior
2181+ // of sourceFile (which is expected at least in the IDE only to
2182+ // return actual source code.) So sourceFile has classfiles filtered out.
2183+ final def sourceFile : AbstractFile =
2184+ if ((associatedFile eq NoAbstractFile ) || (associatedFile.path endsWith " .class" )) null else associatedFile
21882185
2189- /** Overridden in ModuleSymbols to delegate to the module class. */
2186+ /** Overridden in ModuleSymbols to delegate to the module class.
2187+ * Never null; if there is no associated file, returns NoAbstractFile.
2188+ */
21902189 def associatedFile : AbstractFile = enclosingTopLevelClass.associatedFile
21912190 def associatedFile_= (f : AbstractFile ) { abort(" associatedFile_= inapplicable for " + this ) }
21922191
@@ -2932,7 +2931,11 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
29322931 if (c.isOverloaded) c.alternatives.head else c
29332932 }
29342933
2935- override def associatedFile = if (owner.isPackageClass) _associatedFile else super .associatedFile
2934+ override def associatedFile = (
2935+ if (! owner.isPackageClass) super .associatedFile
2936+ else if (_associatedFile eq null ) NoAbstractFile // guarantee not null, but save cost of initializing the var
2937+ else _associatedFile
2938+ )
29362939 override def associatedFile_= (f : AbstractFile ) { _associatedFile = f }
29372940
29382941 override def reset (completer : Type ): this .type = {
@@ -2981,9 +2984,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
29812984 clone.typeOfThis = typeOfThis
29822985 clone.thisSym setName thisSym.name
29832986 }
2984- if (_associatedFile ne null )
2985- clone.associatedFile = _associatedFile
2986-
2987+ clone.associatedFile = _associatedFile
29872988 clone
29882989 }
29892990
@@ -3169,7 +3170,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
31693170 override def enclosingTopLevelClass : Symbol = this
31703171 override def enclosingPackageClass : Symbol = this
31713172 override def enclMethod : Symbol = this
3172- override def associatedFile = null
3173+ override def associatedFile = NoAbstractFile
31733174 override def ownerChain : List [Symbol ] = List ()
31743175 override def ownersIterator : Iterator [Symbol ] = Iterator .empty
31753176 override def alternatives : List [Symbol ] = List ()
0 commit comments