Skip to content

Commit a63dde5

Browse files
committed
adjustement for init symbol in class definition
1 parent 35cfbd7 commit a63dde5

File tree

5 files changed

+53
-192
lines changed

5 files changed

+53
-192
lines changed

semanticdb/input/src/main/scala/example/DependantModule.scala

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

3-
class DepTemp() {
3+
class DepTemp {
44

55
}
66

semanticdb/input/src/main/scala/example/Example.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ class Example {
1616
)
1717
}
1818

19-
class ExampleInit() {
19+
class ExampleInit {
2020

2121
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package example
2+
3+
class TestNew extends C {
4+
val b = new B
5+
}

semanticdb/src/dotty/semanticdb/SemanticdbConsumer.scala

Lines changed: 45 additions & 190 deletions
Original file line numberDiff line numberDiff line change
@@ -342,19 +342,6 @@ class SemanticdbConsumer extends TastyConsumer {
342342
} else {
343343
(iterateParent(symbol), true)
344344
}
345-
/*println(symbol, symbol.isUselessOccurrence)
346-
347-
println(symbol, "isWildCard", symbol.isWildCard)
348-
println(symbol, "isAnonymousCl", symbol.isAnonymousClass)
349-
println(symbol, "isAnonymousFun", symbol.isAnonymousFunction)
350-
println(symbol, "isSyntheticCon", symbol.isSyntheticConstructor)
351-
println(symbol, "isStaticConstr", symbol.isStaticConstructor)
352-
println(symbol, "isLocalChil", symbol.isLocalChild)
353-
println(symbol, "isSyntheticVal", symbol.isSyntheticValueClassCompanion)
354-
println(symbol, "isUselessFie", symbol.isUselessField)
355-
println(symbol, "isSyntheticCas", symbol.isSyntheticCaseAccessor)
356-
println(symbol, "isRefinementCl", symbol.isRefinementClass)
357-
println(symbol, "isSyntheticJav", symbol.isSyntheticJavaModule)*/
358345

359346
println(symbol_path, range)
360347
if (symbol_path == "" || symbol.isUselessOccurrence) return
@@ -378,8 +365,7 @@ class SemanticdbConsumer extends TastyConsumer {
378365
type_symbol: s.SymbolOccurrence.Role,
379366
range: s.Range,
380367
force_add: Boolean = false): Unit = {
381-
382-
if (tree.isUserCreated || force_add) {
368+
if (tree.isUserCreated || (force_add && !(!tree.isUserCreated && iterateParent(tree.symbol) == "java/lang/Object#`<init>`()."))) {
383369
addOccurence(tree.symbol, type_symbol, range)
384370
}
385371
}
@@ -475,96 +461,8 @@ class SemanticdbConsumer extends TastyConsumer {
475461
case IsTypeTree(t) => t
476462
}
477463

478-
/*
479-
def traverseType(tree: TypeOrBounds)(implicit ctx: Context): Unit = {
480-
//println(tree)
481-
tree match {
482-
case IsType(t) => {
483-
if(t.typeSymbol.pos.exists)
484-
println(t.typeSymbol, t.typeSymbol.pos.startColumn, t.typeSymbol.pos.endColumn)
485-
}
486-
case _ => ()
487-
}
488-
tree match {
489-
case Type.ConstantType(Constant.Symbol(symbol)) =>
490-
println("TYPE", symbol)
491-
case Type.ConstantType(_) => {println("CNST")}
492-
case Type.SymRef(_, a) => {
493-
traverseType(a)
494-
}
495-
case Type.TermRef(_, a) => {
496-
traverseType(a)
497-
}
498-
case Type.TypeRef(_, a) => {
499-
traverseType(a)
500-
}
501-
case Type.SuperType(a, b) => {
502-
traverseType(a)
503-
traverseType(b)
504-
}
505-
case Type.Refinement(a, _, b) => {
506-
traverseType(a)
507-
traverseType(b)
508-
}
509-
case Type.AppliedType(a, l) => {
510-
traverseType(a)
511-
l.foreach(traverseType)
512-
}
513-
case Type.AnnotatedType(a, b) => {
514-
traverseType(a)
515-
super.traverseTree(b)
516-
}
517-
case Type.AndType(a, b) => {
518-
traverseType(a)
519-
traverseType(b)
520-
}
521-
case Type.OrType(a, b) => {
522-
traverseType(a)
523-
traverseType(b)
524-
}
525-
case Type.MatchType(a, b, l) => {
526-
traverseType(a)
527-
traverseType(b)
528-
l.foreach(traverseType)
529-
}
530-
case Type.ByNameType(a) => {
531-
traverseType(a)
532-
}
533-
case Type.ParamRef(a, _) => {
534-
traverseType(a)
535-
}
536-
case Type.ThisType(a) => {
537-
traverseType(a)
538-
}
539-
case Type.RecursiveThis(a) => {
540-
traverseType(a)
541-
}
542-
case Type.RecursiveType(a) => {
543-
traverseType(a)
544-
}
545-
case Type.MethodType(_, l, a) => {
546-
traverseType(a)
547-
l.foreach(traverseType)
548-
}
549-
case Type.PolyType(_, l, a) => {
550-
traverseType(a)
551-
l.foreach(traverseType)
552-
}
553-
case Type.TypeLambda(_, l, a) => {
554-
traverseType(a)
555-
l.foreach(traverseType)
556-
}
557-
case NoPrefix() => ()
558-
case TypeBounds(a, b) => {
559-
traverseType(a)
560-
traverseType(b)
561-
}
562-
}
563-
}*/
564-
565464
override def traverseTypeTree(tree: TypeOrBoundsTree)(
566465
implicit ctx: Context): Unit = {
567-
//println("--->", tree)
568466
tree match {
569467
case TypeTree.Ident(_) => {
570468
val typetree = extractTypeTree(tree)
@@ -585,92 +483,63 @@ class SemanticdbConsumer extends TastyConsumer {
585483
}
586484
case _ =>
587485
super.traverseTypeTree(tree)
588-
/*case TypeTree.Applied(_, _) => {
589-
val typetree = extractTypeTree(tree)
590-
println("APPLIED", typetree.pos.startColumn, typetree.pos.endColumn)
591-
super.traverseTypeTree(tree)
592-
}
593-
case TypeTree.Synthetic() => {
594-
val typetree = extractTypeTree(tree)
595-
println("Synthetic", typetree.pos.startColumn, typetree.pos.endColumn)
596-
super.traverseTypeTree(tree)
597-
}
598-
case TypeTree.Project(_, _) => {
599-
println("Project")
600-
super.traverseTypeTree(tree)
601-
}
602-
case TypeTree.Singleton(_) => {
603-
println("Singleton")
604-
super.traverseTypeTree(tree)
605-
}
606-
case TypeTree.Refined(_, _) => {
607-
println("Refined")
608-
super.traverseTypeTree(tree)
609-
}
610-
case TypeTree.Annotated(_, _) => {
611-
println("Annotated")
612-
super.traverseTypeTree(tree)
613-
}
614-
case TypeTree.And(_, _) => {
615-
println("And")
616-
super.traverseTypeTree(tree)
617-
}
618-
case TypeTree.Or(_, _) => {
619-
println("Or")
620-
super.traverseTypeTree(tree)
621-
}
622-
case TypeTree.MatchType(_, _, _) => {
623-
println("MatchType")
624-
super.traverseTypeTree(tree)
625-
}
626-
case TypeTree.ByName(_, _, _) => {
627-
println("ByName")
628-
super.traverseTypeTree(tree)
629-
}
630-
case TypeTree.TypeLambdaTree(_, _) => {
631-
println("TypeLambdaTree")
632-
super.traverseTypeTree(tree)
633-
}
634-
case TypeTree.Bind(_, _) => {
635-
println("Bind")
636-
super.traverseTypeTree(tree)
637-
}
638-
case TypeTree.Block(_, _) => {
639-
println("Block")
640-
super.traverseTypeTree(tree)
641-
}
642-
case SyntheticBounds() => {
643-
println("synthetic bounds")
644-
super.traverseTypeTree(tree)
645-
}
646-
case TypeBoundsTree(_, _) => {
647-
//println("typetree")
648-
super.traverseTypeTree(tree)
649-
}*/
650486
}
651-
652487
}
653488

489+
var fittedInitClassRange: Option[s.Range] = None
490+
var forceAddBecauseParents: Boolean = false
491+
654492
override def traverseTree(tree: Tree)(implicit ctx: Context): Unit = {
655-
/*println("\n")
656-
println(tree)
657-
println(tree.pos.startColumn, tree.symbol.name, tree.pos.endColumn)*/
658493
tree match {
659494
case Import(path, selectors) =>
660495
val key = (tree.symbol.name, tree.pos.start)
661496
if (!package_definitions(key)) {
662497
package_definitions += key
663498
getImportSelectors(getImportPath(path), selectors)
664499
}
665-
case Term.New(_) => {
500+
case Term.New(ty) => {
666501
super.traverseTree(tree)
667502
}
668503
case Term.Apply(_, _) => {
669-
println("---------------")
670-
println(tree.symbol)
671504
super.traverseTree(tree)
672505

673506
}
507+
case ClassDef(classname, constr, parents, selfopt, statements) => {
508+
// we first add the class to the symbol list
509+
addOccurenceTree(tree,
510+
s.SymbolOccurrence.Role.DEFINITION,
511+
range(tree, tree.symbol.pos, tree.symbol.name))
512+
println("constr symbol pos: ", constr.symbol.pos.startColumn, constr.symbol.pos.endColumn)
513+
println("constr pos: ", constr.pos.startColumn, constr.pos.endColumn)
514+
// then the constructor
515+
if (!constr.isUserCreated) {
516+
fittedInitClassRange = Some(
517+
s.Range(tree.symbol.pos.startLine,
518+
tree.symbol.pos.startColumn + classname.length + 1,
519+
tree.symbol.pos.startLine,
520+
tree.symbol.pos.startColumn + classname.length + 1))
521+
} else {
522+
fittedInitClassRange = Some(s.Range(constr.symbol.pos.startLine,
523+
constr.symbol.pos.startColumn,
524+
constr.symbol.pos.endLine,
525+
constr.symbol.pos.endColumn))
526+
}
527+
traverseTree(constr)
528+
fittedInitClassRange = None
529+
530+
// we add the parents to the symbol list
531+
forceAddBecauseParents = true
532+
parents.foreach(_ match {
533+
case IsTypeTree(t) => traverseTypeTree(t)
534+
case IsTerm(t) => traverseTree(t)
535+
})
536+
forceAddBecauseParents = false
537+
538+
selfopt.foreach(traverseTree)
539+
540+
541+
statements.foreach(traverseTree)
542+
}
674543
case IsDefinition(cdef) => {
675544

676545
if (cdef.symbol.flags.is(Flags.Protected)) {
@@ -706,22 +575,13 @@ class SemanticdbConsumer extends TastyConsumer {
706575
}
707576
if (tree.symbol.name != "<none>") {
708577
val range_symbol = range(tree, tree.symbol.pos, tree.symbol.name)
709-
println(tree.symbol.flags)
710-
println(tree.symbol.pos.startColumn,
711-
tree.symbol.pos.endColumn,
712-
tree.pos.startColumn,
713-
tree.pos.endColumn)
714-
if (tree.symbol.name == "<init>" && (!tree.isUserCreated || tree.symbol.pos.startColumn == tree.symbol.pos.endColumn) && !tree.symbol.owner.flags.is(Flags.Object)) {
715-
println("yes")
716-
val range_symbol2 = s.Range(tree.pos.startLine,
717-
tree.pos.endColumn,
718-
tree.pos.endLine,
719-
tree.pos.endColumn)
578+
if (tree.symbol.name == "<init>" && tree.symbol.flags.is(Flags.Object)) {
579+
580+
} else if (tree.symbol.name == "<init>" && fittedInitClassRange != None) {
720581
addOccurenceTree(tree,
721582
s.SymbolOccurrence.Role.DEFINITION,
722-
range_symbol2,
583+
fittedInitClassRange.get,
723584
true)
724-
725585
} else {
726586
addOccurenceTree(tree,
727587
s.SymbolOccurrence.Role.DEFINITION,
@@ -732,7 +592,6 @@ class SemanticdbConsumer extends TastyConsumer {
732592
}
733593

734594
case Term.Select(qualifier, _) => {
735-
println("[Select] " + tree.symbol + " <-> " + qualifier)
736595
val range = {
737596
val r = rangeSelect(tree.symbol.name, tree.pos)
738597
if (tree.symbol.name == "<init>")
@@ -750,17 +609,13 @@ class SemanticdbConsumer extends TastyConsumer {
750609
}
751610

752611
case Term.Ident(name) => {
753-
println("[Ident] " + name)
754612
addOccurenceTree(tree,
755613
s.SymbolOccurrence.Role.REFERENCE,
756614
range(tree, tree.pos, tree.symbol.name))
757615

758616
super.traverseTree(tree)
759617
}
760618

761-
case Term.Literal(name) => {
762-
println("Litteral: " + name)
763-
}
764619
case PackageClause(_) =>
765620
val key = (tree.symbol.name, tree.pos.start)
766621
if (!package_definitions(key)) {

semanticdb/test/dotty/semanticdb/Tests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ class Tests {
202202
//WIP @Test def testTypes(): Unit = checkFile("example/Types.scala")
203203
//@Test def testVals(): Unit = checkFile("example/Vals.scala")
204204
@Test def testDependantModule(): Unit = checkFile("example/DependantModule.scala")
205+
//@Test def testNew(): Unit = checkFile("example/New.scala")
205206
//@Test def testIgnoredSymbol(): Unit = checkFile("example/IgnoredSymbol.scala")
206207

207208

0 commit comments

Comments
 (0)