@@ -43,9 +43,9 @@ final class MutableState {
43
43
44
44
def result (): Array [String ] = synchronized {
45
45
// Because - comes before . in ASCII this little hack affects the ordering so that A[X] comes before A.B[X]
46
- val sortHack = " -OMG- "
46
+ val sortHack = " -"
47
47
48
- val b = SortedSet .newBuilder[String ]
48
+ val b = SortedSet .newBuilder[Result ]
49
49
50
50
// Pass 1
51
51
for (root <- scopes.valuesIterator) {
@@ -55,30 +55,30 @@ final class MutableState {
55
55
56
56
// Pass 2
57
57
for (root <- scopes.valuesIterator) {
58
- val name = root.symbol.value.stripSuffix(" #" ).stripSuffix(" ." )
59
- val prefix = {
60
- val lang = if ( root.isJsType) " J " else " S "
61
- val typ = root.scopeType.id
62
- s " $name$sortHack [ $lang$typ ] "
63
- }
58
+ val scopeName = root.symbol.value.stripSuffix(" #" ).stripSuffix(" ." )
59
+ val flagLang = if (root.isJsType) " J " else " S "
60
+ val flagTyp = root.scopeType.id
61
+ val flags = flagLang + flagTyp
62
+ val prefix = s " $scopeName [ $flags ] "
63
+ val scopeKey = s " $scopeName$sortHack [ $flags "
64
64
65
65
var membersFound = false
66
66
for {
67
67
s <- root :: scopeParents(root)
68
68
v <- s.directMembers
69
69
} {
70
70
membersFound = true
71
- b += prefix + v
71
+ val key = (scopeKey, v.name, v.desc)
72
+ b += Result (key, prefix + v.desc)
72
73
}
73
74
74
- if (! membersFound && ! name.endsWith(" /package" ))
75
- b += prefix.trim
75
+ if (! membersFound && ! scopeName.endsWith(" /package" )) {
76
+ val key = (scopeKey, " " , " " )
77
+ b += Result (key, prefix.trim)
78
+ }
76
79
}
77
80
78
- val array = b.result().toArray
79
- for (i <- array.indices)
80
- array(i) = array(i).replace(sortHack, " " )
81
- array
81
+ b.result().iterator.map(_.value).toArray
82
82
}
83
83
}
84
84
@@ -96,13 +96,19 @@ object MutableState {
96
96
(val scopeType : ScopeType ,
97
97
val parents : Set [Symbol ]) {
98
98
99
- private [MutableState ] val directMembers = mutable.Set .empty[String ]
99
+ private [MutableState ] val directMembers = mutable.Set .empty[Member ]
100
100
private [MutableState ] var isJsType = false
101
101
102
- def add (ov : Option [String ]): Unit =
103
- ov.foreach(add(_))
104
-
105
- def add (v : String ): Unit =
102
+ def add (v : Member ): Unit =
106
103
synchronized (directMembers += v)
107
104
}
105
+
106
+ final case class Member (name : String , desc : String )
107
+
108
+ private [MutableState ] final case class Result (sortKey : Result .SortKey , value : String )
109
+
110
+ private [MutableState ] object Result {
111
+ type SortKey = (String , String , String ) // prefix, name, desc
112
+ implicit val ordering : Ordering [Result ] = Ordering .by(_.sortKey)
113
+ }
108
114
}
0 commit comments