Skip to content

Commit 10f57a3

Browse files
committed
remove companionClass and companionModule. Updated readme. Refactored getchildren
1 parent 013a8ae commit 10f57a3

File tree

5 files changed

+22
-26
lines changed

5 files changed

+22
-26
lines changed

compiler/src/dotty/tools/dotc/tastyreflect/SymbolOpsImpl.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ trait SymbolOpsImpl extends scala.tasty.reflect.SymbolOps with CoreImpl {
3030

3131
def owner(implicit ctx: Context): Symbol = symbol.owner
3232

33-
def companionModule(implicit ctx: Context): Symbol = symbol.companionModule
34-
35-
def companionClass(implicit ctx: Context): Symbol = symbol.companionClass
36-
3733
def localContext(implicit ctx: Context): Context = {
3834
if (symbol.exists) ctx.withOwner(symbol)
3935
else ctx

library/src/scala/tasty/reflect/SymbolOps.scala

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ trait SymbolOps extends Core {
2626
/** The full name of this symbol up to the root package. */
2727
def fullName(implicit ctx: Context): String
2828

29-
30-
def companionModule(implicit ctx: Context): Symbol
31-
32-
def companionClass(implicit ctx: Context): Symbol
33-
3429
def pos(implicit ctx: Context): Position
3530

3631
def localContext(implicit ctx: Context): Context

semanticdb/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ test: all
88
cd ..; sbt dotty-semanticdb/test; cd -
99

1010
%.tasty: $(files)
11-
cd $(dir $^); $(CURDIR)/../bin/dotc $(notdir $^)
11+
cd $(dir $<); $(CURDIR)/../bin/dotc $(notdir $^)

semanticdb/readme.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ sbt
1010
> compile
1111
```
1212

13+
You will also need to generate the tasty files for the test. For now, you can
14+
easily do it by executing the makefile in this folder:
15+
```
16+
make
17+
```
18+
Please note that the makefile will also compile the `semanticdb/input` project.
19+
20+
1321
In the second terminal, run `sbt dotty-semanticdb/test` from the main dotty
1422
build
1523

semanticdb/src/dotty/semanticdb/SemanticdbConsumer.scala

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,16 @@ class SemanticdbConsumer extends TastyConsumer {
2323
import reflect._
2424

2525
object ChildTraverser extends TreeTraverser {
26-
var depth: Int = 0
2726
var children: List[Tree] = Nil
28-
override def traverseTree(tree: Tree)(implicit ctx: Context): Unit = {
29-
if (depth == 0) {
30-
depth = depth + 1
31-
super.traverseTree(tree)
32-
depth = depth - 1
33-
} else {
34-
children = tree :: children
35-
}
36-
}
37-
def getChildren(tree: Tree)(implicit ctx: Context): List[Position] = {
27+
override def traverseTree(tree: Tree)(implicit ctx: Context): Unit = children = tree::children
28+
override def traversePattern(pattern: Pattern)(implicit ctx: Context): Unit = ()
29+
override def traverseTypeTree(tree: TypeOrBoundsTree)(implicit ctx: Context): Unit = ()
30+
override def traverseCaseDef(tree: CaseDef)(implicit ctx: Context): Unit = ()
31+
32+
def getChildren(tree: Tree)(implicit ctx: Context): List[Tree] = {
3833
children = Nil
39-
depth = 0
40-
traverseTree(tree)(ctx)
41-
return children.map(_.pos)
34+
traverseTreeChildren(tree)(ctx)
35+
return children
4236
}
4337
}
4438

@@ -48,7 +42,7 @@ class SemanticdbConsumer extends TastyConsumer {
4842
implicit class TreeExtender(tree: Tree) {
4943
def isUserCreated: Boolean = {
5044
val children: List[Position] =
51-
ChildTraverser.getChildren(tree)(reflect.rootContext)
45+
ChildTraverser.getChildren(tree)(reflect.rootContext).map(_.pos)
5246
return !((tree.pos.exists && tree.pos.start == tree.pos.end && children == Nil) || children
5347
.exists(_ == tree.pos))
5448
}
@@ -117,7 +111,10 @@ class SemanticdbConsumer extends TastyConsumer {
117111
if (symbol.isPackage) {
118112
d.Package(symbol.name)
119113
} else if (symbol.isObject) {
120-
d.Term(symbol.companionModule.name)
114+
symbol.asClass.companionModule match {
115+
case Some(module) => d.Term(module.name)
116+
case _ => d.Term(symbol.name)
117+
}
121118
} else if (symbol.isMethod) {
122119
d.Method(symbol.name,
123120
disimbiguate(previous_symbol + symbol.name))

0 commit comments

Comments
 (0)