diff options
Diffstat (limited to 'dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/EntityFactories.scala')
-rw-r--r-- | dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/EntityFactories.scala | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/EntityFactories.scala b/dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/EntityFactories.scala new file mode 100644 index 000000000..5e459a766 --- /dev/null +++ b/dottydoc/shared/src/main/scala/dotty/tools/dottydoc/model/EntityFactories.scala @@ -0,0 +1,37 @@ +package dotty.tools.dottydoc +package model + +import dotty.tools.dotc +import dotc.core.Types._ +import dotc.core.Contexts.Context +import dotc.core.Symbols.Symbol +import dotc.core.{ Flags => DottyFlags } +import dotc.ast.Trees._ +import DottyFlags.FlagSet + +object EntityFactories { + import dotty.tools.dotc.ast.tpd._ + import DottyFlags._ + + def flags(t: Tree)(implicit ctx: Context): List[String] = + (t.symbol.flags & SourceModifierFlags).flagStrings.toList + + def path(t: Tree, name: String)(implicit ctx: Context): List[String] = { + def pathList(tpe: Type): List[String] = tpe match { + case t: ThisType => + pathList(t.tref) + case t: NamedType if t.prefix == NoPrefix && t.name.toString == "<root>" => + Nil + case t: NamedType if t.prefix == NoPrefix => + t.name.toString :: Nil + case t: NamedType => + pathList(t.prefix) :+ t.name.toString + } + + val ref = + if (t.symbol.isTerm) t.symbol.termRef + else t.symbol.typeRef + + pathList(ref) + } +} |