@@ -395,34 +395,40 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
395
395
final def isAnonymousFunction = isSynthetic && (name containsName tpnme.ANON_FUN_NAME )
396
396
final def isAnonOrRefinementClass = isAnonymousClass || isRefinementClass
397
397
398
- final def isPackageObject = isModule && name == nme.PACKAGEkw && owner.isPackageClass
399
- final def isPackageObjectClass = isModuleClass && name.toTermName == nme.PACKAGEkw && owner.isPackageClass
400
- final def definedInPackage = owner.isPackageClass || owner.isPackageObjectClass
398
+ def isPackageObjectOrClass = (name.toTermName == nme.PACKAGEkw ) && owner.isPackageClass
399
+ final def isPackageObject = isModule && isPackageObjectOrClass
400
+ final def isPackageObjectClass = isModuleClass && isPackageObjectOrClass
401
+ final def isDefinedInPackage = effectiveOwner.isPackageClass
401
402
final def isJavaInterface = isJavaDefined && isTrait
402
403
final def needsFlatClasses : Boolean = phase.flatClasses && rawowner != NoSymbol && ! rawowner.isPackageClass
403
404
404
- // not printed as prefixes
405
- final def isPredefModule = this == PredefModule
406
- final def isScalaPackage = (this == ScalaPackage ) || (isPackageObject && owner == ScalaPackageClass )
407
- final def isScalaPackageClass = skipPackageObject == ScalaPackageClass
408
- def inDefaultNamespace = owner.isPredefModule || owner.isScalaPackageClass
405
+ // In java.lang, Predef, or scala package/package object
406
+ def isInDefaultNamespace = UnqualifiedOwners (effectiveOwner)
409
407
410
408
/** If this is a package object or package object class, its owner: otherwise this.
411
409
*/
412
410
final def skipPackageObject : Symbol = if (isPackageObjectClass) owner else this
413
411
412
+ /** The owner, skipping package objects.
413
+ */
414
+ def effectiveOwner = owner.skipPackageObject
415
+
414
416
/** If this is a constructor, its owner: otherwise this.
415
417
*/
416
418
final def skipConstructor : Symbol = if (isConstructor) owner else this
417
419
418
420
/** Conditions where we omit the prefix when printing a symbol, to avoid
419
421
* unpleasantries like Predef.String, $iw.$iw.Foo and <empty>.Bippy.
420
422
*/
421
- final def printWithoutPrefix = ! settings.debug.value && (
422
- isScalaPackageClass || isPredefModule || isEffectiveRoot || isAnonOrRefinementClass ||
423
- nme.isReplWrapperName(name) // not isInterpreterWrapper due to nesting
423
+ final def isOmittablePrefix = ! settings.debug.value && (
424
+ UnqualifiedOwners (skipPackageObject)
425
+ || isEmptyPrefix
426
+ )
427
+ def isEmptyPrefix = (
428
+ isEffectiveRoot // has no prefix for real, <empty> or <root>
429
+ || isAnonOrRefinementClass // has uninteresting <anon> or <refinement> prefix
430
+ || nme.isReplWrapperName(name) // has ugly $iw. prefix (doesn't call isInterpreterWrapper due to nesting)
424
431
)
425
-
426
432
def isFBounded = info.baseTypeSeq exists (_ contains this )
427
433
428
434
/** Is symbol a monomorphic type?
@@ -723,7 +729,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
723
729
724
730
/** The decoded name of the symbol, e.g. `==` instead of `\$eq\$eq`.
725
731
*/
726
- def decodedName : String = stripLocalSuffix (NameTransformer .decode(encodedName))
732
+ def decodedName : String = stripNameString (NameTransformer .decode(encodedName))
727
733
728
734
def moduleSuffix : String = (
729
735
if (hasModuleFlag && ! isMethod && ! isImplClass && ! isJavaDefined) nme.MODULE_SUFFIX_STRING
@@ -732,22 +738,32 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
732
738
733
739
/** These should be moved somewhere like JavaPlatform.
734
740
*/
735
- def javaSimpleName = stripLocalSuffix (" " + simpleName) + moduleSuffix
736
- def javaBinaryName = fullName ('/' ) + moduleSuffix
737
- def javaClassName = fullName ('.' ) + moduleSuffix
741
+ def javaSimpleName = (" " + simpleName).trim + moduleSuffix
742
+ def javaBinaryName = fullNameInternal ('/' ) + moduleSuffix
743
+ def javaClassName = fullNameInternal ('.' ) + moduleSuffix
738
744
739
745
/** The encoded full path name of this symbol, where outer names and inner names
740
746
* are separated by `separator` characters.
741
747
* Never translates expansions of operators back to operator symbol.
742
748
* Never adds id.
749
+ * Drops package objects.
750
+ */
751
+ final def fullName (separator : Char ): String = stripNameString(fullNameInternal(separator))
752
+
753
+ /** Doesn't drop package objects, for those situations (e.g. classloading)
754
+ * where the true path is needed.
743
755
*/
744
- final def fullName (separator : Char ): String = stripLocalSuffix {
756
+ private def fullNameInternal (separator : Char ): String = (
745
757
if (isRoot || isRootPackage || this == NoSymbol ) this .toString
746
758
else if (owner.isEffectiveRoot) encodedName
747
- else owner .enclClass.fullName(separator) + separator + encodedName
748
- }
759
+ else effectiveOwner .enclClass.fullName(separator) + separator + encodedName
760
+ )
749
761
750
- private def stripLocalSuffix (s : String ) = s stripSuffix nme.LOCAL_SUFFIX_STRING
762
+ /** Strip package objects and any local suffix.
763
+ */
764
+ private def stripNameString (s : String ) =
765
+ if (settings.debug.value) s
766
+ else s.replaceAllLiterally(" .package" , " " ).trim
751
767
752
768
/** The encoded full path name of this symbol, where outer names and inner names
753
769
* are separated by periods.
@@ -1358,11 +1374,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
1358
1374
1359
1375
/** The package containing this symbol, or NoSymbol if there
1360
1376
* is not one. */
1361
- def enclosingPackage : Symbol = {
1362
- val packSym = enclosingPackageClass
1363
- if (packSym != NoSymbol ) packSym.companionModule
1364
- else packSym
1365
- }
1377
+ def enclosingPackage : Symbol = enclosingPackageClass.companionModule
1366
1378
1367
1379
/** Return the original enclosing method of this symbol. It should return
1368
1380
* the same thing as enclMethod when called before lambda lift,
@@ -1420,8 +1432,8 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
1420
1432
/** Is this symbol defined in the same scope and compilation unit as `that` symbol? */
1421
1433
def isCoDefinedWith (that : Symbol ) = (
1422
1434
(this .rawInfo ne NoType ) &&
1423
- (this .owner == that.owner ) && {
1424
- ! this .owner .isPackageClass ||
1435
+ (this .effectiveOwner == that.effectiveOwner ) && {
1436
+ ! this .effectiveOwner .isPackageClass ||
1425
1437
(this .sourceFile eq null ) ||
1426
1438
(that.sourceFile eq null ) ||
1427
1439
(this .sourceFile == that.sourceFile) || {
@@ -1784,11 +1796,10 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
1784
1796
* to the name of the owner.
1785
1797
*/
1786
1798
def hasMeaninglessName = (
1787
- isSetterParameter // x$1
1788
- || isClassConstructor // this
1789
- || isPackageObject // package
1790
- || isPackageObjectClass // package$
1791
- || isRefinementClass // <refinement>
1799
+ isSetterParameter // x$1
1800
+ || isClassConstructor // this
1801
+ || isPackageObjectOrClass // package
1802
+ || isRefinementClass // <refinement>
1792
1803
)
1793
1804
1794
1805
/** String representation of symbol's simple name.
@@ -1812,9 +1823,8 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
1812
1823
/** String representation of location.
1813
1824
*/
1814
1825
def ownsString = {
1815
- val owns = owner.skipPackageObject
1816
- if (owns.isClass && ! owns.printWithoutPrefix && ! isScalaPackageClass) " " + owns
1817
- else " "
1826
+ val owns = effectiveOwner
1827
+ if (owns.isClass && ! owns.isEmptyPrefix) " " + owns else " "
1818
1828
}
1819
1829
1820
1830
/** String representation of location, plus a preposition. Doesn't do much,
@@ -1963,7 +1973,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
1963
1973
1964
1974
protected def doCookJavaRawInfo () {
1965
1975
def cook (sym : Symbol ) {
1966
- require(sym hasFlag JAVA )
1976
+ require(sym.isJavaDefined, sym )
1967
1977
// @M: I think this is more desirable, but Martin prefers to leave raw-types as-is as much as possible
1968
1978
// object rawToExistentialInJava extends TypeMap {
1969
1979
// def apply(tp: Type): Type = tp match {
@@ -1985,9 +1995,9 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
1985
1995
1986
1996
if (isJavaDefined)
1987
1997
cook(this )
1988
- else if (hasFlag( OVERLOADED ) )
1998
+ else if (isOverloaded )
1989
1999
for (sym2 <- alternatives)
1990
- if (sym2 hasFlag JAVA )
2000
+ if (sym2.isJavaDefined )
1991
2001
cook(sym2)
1992
2002
}
1993
2003
}
0 commit comments