@@ -17,13 +17,13 @@ import collection.mutable
17
17
import java .lang .Character .{isJavaIdentifierPart , isJavaIdentifierStart }
18
18
import java .nio .file .Paths
19
19
20
- abstract class ExtractSemanticDB extends Phase {
20
+ class ExtractSemanticDB extends Phase {
21
21
import ast .tpd ._
22
22
23
23
override val phaseName : String = ExtractSemanticDB .name
24
24
25
25
override def isRunnable (implicit ctx : Context ) =
26
- super .isRunnable && ctx.settings.YretainTrees .value
26
+ true || super .isRunnable && ctx.settings.YretainTrees .value
27
27
28
28
// Check not needed since it does not transform trees
29
29
override def isCheckable : Boolean = false
@@ -49,9 +49,12 @@ abstract class ExtractSemanticDB extends Phase {
49
49
50
50
class Extractor extends TreeTraverser {
51
51
52
- private val locals = mutable.HashMap [Symbol , java.lang.Integer ]()
52
+ private val locals = mutable.HashMap [Symbol , Int ]()
53
+
53
54
val occurrences = new mutable.ListBuffer [SymbolOccurrence ]()
54
55
56
+ val localIndex = mutable.HashMap [Int , Int ]()
57
+
55
58
private var myLocalIdx : Int = - 1
56
59
private def nextLocalIdx () =
57
60
myLocalIdx += 1
@@ -61,6 +64,8 @@ abstract class ExtractSemanticDB extends Phase {
61
64
62
65
def isJavaIdent (str : String ) =
63
66
isJavaIdentifierStart(str.head) && str.tail.forall(isJavaIdentifierPart)
67
+ || str == nme.CONSTRUCTOR .toString
68
+ || str == nme.STATIC_CONSTRUCTOR .toString
64
69
65
70
def nameToString (name : Name ) =
66
71
val str = name.toString
@@ -71,7 +76,7 @@ abstract class ExtractSemanticDB extends Phase {
71
76
|| (sym.is(Param ) || sym.owner.isClass) && isGlobal(sym.owner)
72
77
73
78
def ownerString (owner : Symbol ): String =
74
- if owner.isRoot then " " else symbolName(owner) + " /"
79
+ if owner.isRoot || owner.isEmptyPackage then " " else symbolName(owner) + " /"
75
80
76
81
def overloadIdx (sym : Symbol ): String =
77
82
val alts = sym.owner.info.decls.lookupAll(sym.name).toList
@@ -87,15 +92,15 @@ abstract class ExtractSemanticDB extends Phase {
87
92
else
88
93
val str = nameToString(sym.name)
89
94
if sym.is(Package ) then str
90
- else if sym.is(Module ) || sym.isGetter && ! sym.is(Mutable ) then str + " ."
91
95
else if sym.isType then str + " #"
92
- else if sym.is( Method ) then str + " (" + overloadIdx(sym) + " )"
93
- else if sym.is(TermParam ) then " (" + str + " )"
96
+ else if sym.isRealMethod then str + " (" + overloadIdx(sym) + " )"
97
+ else if sym.is(TermParam ) || sym.is( ParamAccessor ) then " (" + str + " )"
94
98
else if sym.is(TypeParam ) then " [" + str + " ]"
95
- else throw new AssertionError (i " unhandled symbol: $sym" )
99
+ else if sym.isTerm then str + " ."
100
+ else throw new AssertionError (i " unhandled symbol: $sym: ${sym.info} with ${sym.flagsString}" )
96
101
97
- def localIdx (sym : Symbol ): Int =
98
- locals .getOrElseUpdate(sym, nextLocalIdx())
102
+ def localIdx (sym : Symbol )( given Context ) : Int =
103
+ localIndex .getOrElseUpdate(sym.span.start , nextLocalIdx())
99
104
100
105
if sym.isRoot then " _root_"
101
106
else if sym.isEmptyPackage then " _empty_"
@@ -110,8 +115,13 @@ abstract class ExtractSemanticDB extends Phase {
110
115
val (endLine, endCol) = lineCol(pos.span.end)
111
116
Some (Range (startLine, startCol, endLine, endCol))
112
117
118
+ private def excluded (sym : Symbol )(given Context ): Boolean =
119
+ ! sym.exists || sym.isLocalDummy
120
+
113
121
private def registerOccurrence (sym : Symbol , pos : SourcePosition , role : SymbolOccurrence .Role )(given Context ): Unit =
114
- occurrences += SymbolOccurrence (symbolName(sym), range(pos), role)
122
+ if ! excluded(sym) then
123
+ // println(i"register: ${symbolName(sym)}")
124
+ occurrences += SymbolOccurrence (symbolName(sym), range(pos), role)
115
125
116
126
private def registerUse (sym : Symbol , pos : SourcePosition )(given Context ) =
117
127
registerOccurrence(sym, pos, SymbolOccurrence .Role .REFERENCE )
0 commit comments