/src/library/scala/reflect/generic/Symbols.scala

http://github.com/greedy/scala-llvm · Scala · 187 lines · 89 code · 40 blank · 58 comment · 47 complexity · 6c09aa2046e07015f96bf57da98618ce MD5 · raw file

  1. package scala.reflect
  2. package generic
  3. import Flags._
  4. @deprecated("scala.reflect.generic will be removed", "2.9.1") trait Symbols { self: Universe =>
  5. type Symbol >: Null <: AbsSymbol
  6. abstract class AbsSymbol extends HasFlags {
  7. this: Symbol =>
  8. type FlagsType = Long
  9. type AccessBoundaryType = Symbol
  10. type AnnotationType = AnnotationInfo
  11. /** The owner of this symbol.
  12. */
  13. def owner: Symbol
  14. /** The flags of this symbol */
  15. def flags: Long
  16. /** The name of the symbol as a member of the `Name` type.
  17. */
  18. def name: Name
  19. /** The name of the symbol before decoding, e.g. `\$eq\$eq` instead of `==`.
  20. */
  21. def encodedName: String = name.toString
  22. /** The decoded name of the symbol, e.g. `==` instead of `\$eq\$eq`.
  23. */
  24. def decodedName: String = stripLocalSuffix(NameTransformer.decode(encodedName))
  25. /** The encoded full path name of this symbol, where outer names and inner names
  26. * are separated by `separator` characters.
  27. * Never translates expansions of operators back to operator symbol.
  28. * Never adds id.
  29. */
  30. final def fullName(separator: Char): String = stripLocalSuffix {
  31. if (isRoot || isRootPackage || this == NoSymbol) this.toString
  32. else if (owner.isEffectiveRoot) encodedName
  33. else owner.enclClass.fullName(separator) + separator + encodedName
  34. }
  35. private def stripLocalSuffix(s: String) = s stripSuffix nme.LOCAL_SUFFIX_STRING
  36. /** The encoded full path name of this symbol, where outer names and inner names
  37. * are separated by periods.
  38. */
  39. final def fullName: String = fullName('.')
  40. /** Does symbol have ANY flag in `mask` set? */
  41. final def hasFlag(mask: Long): Boolean = (flags & mask) != 0L
  42. /** Does symbol have ALL the flags in `mask` set? */
  43. final def hasAllFlags(mask: Long): Boolean = (flags & mask) == mask
  44. /** Set when symbol has a modifier of the form private[X], NoSymbol otherwise.
  45. */
  46. def privateWithin: Symbol
  47. final def hasAccessBoundary = (privateWithin != null) && (privateWithin != NoSymbol)
  48. /** The raw info of the type
  49. */
  50. def rawInfo: Type
  51. /** The type of the symbol
  52. */
  53. def tpe: Type = info
  54. /** The info of the symbol. This is like tpe, except for class symbols where the `info`
  55. * describes the contents of the class whereas the `tpe` is a reference to the class.
  56. */
  57. def info: Type = {
  58. val tp = rawInfo
  59. tp.complete(this)
  60. tp
  61. }
  62. /** If this symbol is a class or trait, its self type, otherwise the type of the symbol itse;lf
  63. */
  64. def typeOfThis: Type
  65. def owner_=(sym: Symbol) { throw new UnsupportedOperationException("owner_= inapplicable for " + this) }
  66. def flags_=(flags: Long) { throw new UnsupportedOperationException("flags_= inapplicable for " + this) }
  67. def info_=(tp: Type) { throw new UnsupportedOperationException("info_= inapplicable for " + this) }
  68. def typeOfThis_=(tp: Type) { throw new UnsupportedOperationException("typeOfThis_= inapplicable for " + this) }
  69. def privateWithin_=(sym: Symbol) { throw new UnsupportedOperationException("privateWithin_= inapplicable for " + this) }
  70. def sourceModule_=(sym: Symbol) { throw new UnsupportedOperationException("sourceModule_= inapplicable for " + this) }
  71. def addChild(sym: Symbol) { throw new UnsupportedOperationException("addChild inapplicable for " + this) }
  72. def addAnnotation(annot: AnnotationInfo) { throw new UnsupportedOperationException("addAnnotation inapplicable for " + this) }
  73. /** For a module class its linked class, for a plain class
  74. * the module class of its linked module.
  75. * For instance
  76. * object Foo
  77. * class Foo
  78. *
  79. * Then object Foo has a `moduleClass` (invisible to the user, the backend calls it Foo$
  80. * linkedClassOfClass goes from class Foo$ to class Foo, and back.
  81. */
  82. def linkedClassOfClass: Symbol
  83. /** The module corresponding to this module class (note that this
  84. * is not updated when a module is cloned), or NoSymbol if this is not a ModuleClass
  85. */
  86. def sourceModule: Symbol = NoSymbol
  87. /** If symbol is an object definition, it's implied associated class,
  88. * otherwise NoSymbol
  89. */
  90. def moduleClass: Symbol
  91. /**
  92. * If symbol is a lazy val, it's lazy accessor
  93. */
  94. def lazyAccessor: Symbol
  95. // flags and kind tests
  96. def isTerm = false // to be overridden
  97. def isType = false // to be overridden
  98. def isClass = false // to be overridden
  99. def isAliasType = false // to be overridden
  100. def isAbstractType = false // to be overridden
  101. private[scala] def isSkolem = false // to be overridden
  102. override def isTrait: Boolean = isClass && hasFlag(TRAIT) // refined later for virtual classes.
  103. final def isAbstractClass = isClass && hasFlag(ABSTRACT)
  104. final def isBridge = hasFlag(BRIDGE)
  105. final def isContravariant = isType && hasFlag(CONTRAVARIANT)
  106. final def isCovariant = isType && hasFlag(COVARIANT)
  107. final def isEarlyInitialized: Boolean = isTerm && hasFlag(PRESUPER)
  108. final def isExistentiallyBound = isType && hasFlag(EXISTENTIAL)
  109. final def isImplClass = isClass && hasFlag(IMPLCLASS) // Is this symbol an implementation class for a mixin?
  110. final def isLazyAccessor = isLazy && lazyAccessor != NoSymbol
  111. final def isMethod = isTerm && hasFlag(METHOD)
  112. final def isVarargsMethod = isMethod && hasFlag(VARARGS)
  113. final def isModule = isTerm && hasFlag(MODULE)
  114. final def isModuleClass = isClass && hasFlag(MODULE)
  115. final def isOverloaded = hasFlag(OVERLOADED)
  116. final def isRefinementClass = isClass && name == tpnme.REFINE_CLASS_NAME
  117. final def isSourceMethod = isMethod && !hasFlag(STABLE) // exclude all accessors!!!
  118. final def isTypeParameter = isType && isParameter && !isSkolem
  119. /** Package tests */
  120. final def isEmptyPackage = isPackage && name == nme.EMPTY_PACKAGE_NAME
  121. final def isEmptyPackageClass = isPackageClass && name == tpnme.EMPTY_PACKAGE_NAME
  122. final def isPackage = isModule && hasFlag(PACKAGE)
  123. final def isPackageClass = isClass && hasFlag(PACKAGE)
  124. final def isRoot = isPackageClass && owner == NoSymbol
  125. final def isRootPackage = isPackage && owner == NoSymbol
  126. /** Is this symbol an effective root for fullname string?
  127. */
  128. def isEffectiveRoot = isRoot || isEmptyPackageClass
  129. /** If this is NoSymbol, evaluate the argument: otherwise, this.
  130. */
  131. def orElse[T](alt: => Symbol): Symbol = if (this ne NoSymbol) this else alt
  132. // creators
  133. def newAbstractType(name: TypeName, pos: Position = NoPosition): Symbol
  134. def newAliasType(name: TypeName, pos: Position = NoPosition): Symbol
  135. def newClass(name: TypeName, pos: Position = NoPosition): Symbol
  136. def newMethod(name: TermName, pos: Position = NoPosition): Symbol
  137. def newModule(name: TermName, clazz: Symbol, pos: Position = NoPosition): Symbol
  138. def newModuleClass(name: TypeName, pos: Position = NoPosition): Symbol
  139. def newValue(name: TermName, pos: Position = NoPosition): Symbol
  140. // access to related symbols
  141. /** The next enclosing class */
  142. def enclClass: Symbol = if (isClass) this else owner.enclClass
  143. /** The next enclosing method */
  144. def enclMethod: Symbol = if (isSourceMethod) this else owner.enclMethod
  145. }
  146. val NoSymbol: Symbol
  147. }