Skip to content

Commit 5160763

Browse files
committed
improve 'isUserCreated' for typetrees
1 parent 7ae6c6e commit 5160763

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package example
22

33
class BinaryOp {
4-
1 #:: 2 #:: Stream.empty
4+
1 #:: 2 #:: Stream.empty[Int]
55
}

semanticdb/src/dotty/semanticdb/SemanticdbConsumer.scala

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
3535

3636
object ChildTraverser extends TreeTraverser {
3737
var children: List[Tree] = Nil
38+
var childrenType: List[TypeOrBoundsTree] = Nil
3839
override def traverseTree(tree: Tree)(implicit ctx: Context): Unit =
3940
children = tree :: children
4041
override def traversePattern(pattern: Pattern)(
4142
implicit ctx: Context): Unit = ()
4243
override def traverseTypeTree(tree: TypeOrBoundsTree)(
43-
implicit ctx: Context): Unit = ()
44+
implicit ctx: Context): Unit =
45+
childrenType = tree :: childrenType
4446
override def traverseCaseDef(tree: CaseDef)(implicit ctx: Context): Unit =
4547
()
4648
override def traverseTypeCaseDef(tree: TypeCaseDef)(
@@ -52,6 +54,11 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
5254
traverseTreeChildren(tree)(ctx)
5355
return children
5456
}
57+
def getChildrenType(tree: TypeOrBoundsTree)(implicit ctx: Context): List[TypeOrBoundsTree] = {
58+
childrenType = Nil
59+
traverseTypeTreeChildren(tree)(ctx)
60+
return childrenType
61+
}
5562
}
5663

5764
object Traverser extends TreeTraverser {
@@ -66,6 +73,12 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
6673

6774
implicit class TypeTreeExtender(tree: TypeTree) {
6875
def isUserCreated: Boolean = {
76+
val children: List[Position] =
77+
ChildTraverser.getChildrenType(tree)(reflect.rootContext).collect(_ match {
78+
case IsTypeTree(tt) => tt.pos})
79+
println(children)
80+
return !((tree.pos.exists && tree.pos.start == tree.pos.end && children == Nil) || children
81+
.exists(_ == tree.pos))
6982
return !(tree.pos.exists && tree.pos.start == tree.pos.end)
7083
}
7184
}
@@ -436,7 +449,7 @@ class SemanticdbConsumer(sourceFile: java.nio.file.Path) extends TastyConsumer {
436449
def addOccurenceTypeTree(typetree: TypeTree,
437450
type_symbol: s.SymbolOccurrence.Role,
438451
range: s.Range): Unit = {
439-
println(typetree)
452+
println(typetree.symbol, typetree.isUserCreated)
440453
if (typetree.isUserCreated) {
441454
addOccurence(typetree.symbol, type_symbol, range)
442455
}

semanticdb/test/dotty/semanticdb/Tests.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class Tests {
175175
}
176176

177177

178-
/*@Test def testAccess(): Unit = checkFile("example/Access.scala")
178+
/*@Test def testAccess(): Unit = checkFile("example/Access.scala")
179179
@Test def testAdvanced(): Unit = checkFile("example/Advanced.scala")
180180
@Test def testAnonymous(): Unit = checkFile("example/Anonymous.scala")
181181
@Test def testClasses(): Unit = checkFile("example/Classes.scala")
@@ -205,8 +205,9 @@ class Tests {
205205
@Test def testIgnoredSymbol(): Unit = checkFile("example/IgnoredSymbol.scala")
206206
@Test def testCase(): Unit = checkFile("example/Case.scala")
207207
@Test def testApply(): Unit = checkFile("example/Apply.scala")
208+
@Test def testMethodUsages(): Unit = checkFile("example/MethodUsages.scala")
208209
@Test def testTypeBug(): Unit = checkFile("example/TypeBug.scala")*/
210+
@Test def testTraits(): Unit = checkFile("example/Traits.scala")
209211
//@Test def testSynthetic(): Unit = checkFile("example/Synthetic.scala")
210212
//@Test def testBinaryOp(): Unit = checkFile("example/BinaryOp.scala")
211-
@Test def testMethodUsages(): Unit = checkFile("example/MethodUsages.scala")
212213
}

0 commit comments

Comments
 (0)