aboutsummaryrefslogtreecommitdiff
path: root/dottydoc/js/src/model/entities.scala
blob: 27db4ec0a768e6169c81ef39dda278fb34505465 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package dotty.tools
package dottydoc
package js
package model

import scala.scalajs.{ js => sjs }

/** This file defines the interface for which to interact with the searchable
 *  index. To use the normal operations available on the traits on the JVM:
 *
 *  {{{
 *  import dotty.tools.dottydoc.js.model.ops._
 *  val x: Package = ...
 *  }}}
 *
 *  Please note that some of the actual fields have not been added to this
 *  interface, this is simply due to the fact that they're not necessary for
 *  search - YET. They could be added, for instance `comment` is missing.
 */
@sjs.native
trait Entity extends sjs.Any {
  val kind: String = sjs.native

  val name: String = sjs.native

  val path: sjs.Array[String] = sjs.native

  val parent: Entity = sjs.native
}

@sjs.native
trait Members extends sjs.Any {
  val members: sjs.Array[Entity] = sjs.native
}

@sjs.native
trait Package extends Entity with Members

@sjs.native
trait Class extends Entity with Members

@sjs.native
trait CaseClass extends Entity with Members

@sjs.native
trait Object extends Class

@sjs.native
trait Trait extends Class

@sjs.native
trait Def extends Entity

@sjs.native
trait Val extends Def

@sjs.native
trait Var extends Def

object ops {
  val EntitiesWithMembers =
    "package" :: "case class" :: "class" :: "object" :: "trait" :: Nil

  implicit class PackageOps(val p: Package) {
    def children: sjs.Array[Entity with Members] =
      p.members.collect {
        case x if EntitiesWithMembers contains x.kind =>
          x.asInstanceOf[Entity with Members]
      }
  }
}