aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/dotty/tools/dotc/core/NameInfos.scala
blob: 650a0c0a4174d8c1f86c853e642a28a909ac08ba (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package dotty.tools.dotc
package core

import Names._

/** Additional info associated with a name. At a minimum its kind and
 *  a way to turn it into a string.
 */
abstract class NameInfo extends util.DotClass {
  def kind: NameInfo.Kind
  def mkString(underlying: TermName): String
  def contains(ch: Char): Boolean = false
  def ++(other: String): NameInfo = unsupported("++")
}

object NameInfo {

  type Kind = Int

  val TermNameKind = 0
  val QualifiedKind = 1
  val ModuleClassKind = 2

  def definesNewName(kind: Kind) = kind <= QualifiedKind

  /** TermNames have the lowest possible kind */
  val TermName = new NameInfo {
    def kind = TermNameKind
    def mkString(underlying: TermName) = underlying.toString // will cause an unsupported exception
  }

  case class Qualified(name: TermName, separator: String) extends NameInfo {
    def kind = QualifiedKind
    def mkString(underlying: TermName) = s"$underlying$separator$name"
    override def contains(ch: Char): Boolean = name.contains(ch)
    override def ++(other: String): NameInfo = Qualified(name ++ other, separator)
    override def toString = s"Qualified($name, $separator)"
  }

  val ModuleClass = new NameInfo {
    def kind = ModuleClassKind
    def mkString(underlying: TermName) = underlying + "$"
    override def toString = "ModuleClass"
  }
}