Skip to content

Commit 1ebd4af

Browse files
committed
Implment QualifiedModifier unapplies
1 parent 5ccc050 commit 1ebd4af

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

compiler/src/dotty/tools/dotc/tasty/internal/Modifiers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import scala.tasty.modifiers
88
object Modifiers {
99

1010
def apply(tree: tpd.MemberDef)(implicit ctx: Context): List[modifiers.Modifier] = {
11-
// TODO QualifiedModifier
11+
QualifiedModifier(tree).toList :::
1212
tree.symbol.annotations.map(AnnotationModifier(_)) :::
1313
tree.rawMods.mods.map(Modifier(_))
1414
}
Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,41 @@
1-
package dotty.tools.dotc.tasty.internal
1+
package dotty.tools.dotc.tasty
2+
package internal
23

34
import dotty.tools.dotc.ast.tpd
4-
import dotty.tools.dotc.ast.Trees
55
import dotty.tools.dotc.core.Contexts.Context
6-
import dotty.tools.dotc.core.Decorators.sourcePos
6+
import dotty.tools.dotc.core.Flags
77

88
import scala.tasty.modifiers
99

1010
object QualifiedModifier {
1111

12-
// TODO make sure all extractors are tested
13-
14-
def apply(tree: tpd.DefTree)(implicit ctx: Context): modifiers.Modifier = Impl(tree, ctx)
12+
def apply(tree: tpd.DefTree)(implicit ctx: Context): Option[modifiers.Modifier] =
13+
if (tree.symbol.privateWithin.exists) Some(Impl(tree, ctx)) else None
1514

1615
def unapplyQualifiedPrivate(mod: modifiers.Modifier): Option[modifiers.QualifiedPrivate.Data] = mod match {
1716
case Impl(tree, ctx) =>
18-
implicit val c = ctx
19-
???
17+
implicit val ctx_ = ctx
18+
if (tree.symbol.is(Flags.Protected)) None
19+
else Some(Type(tree.symbol.privateWithin.typeRef))
2020
case _ => None
2121
}
2222

2323
def unapplyQualifiedProtected(mod: modifiers.Modifier): Option[modifiers.QualifiedProtected.Data] = mod match {
2424
case Impl(tree, ctx) =>
25-
???
25+
implicit val ctx_ = ctx
26+
if (tree.symbol.is(Flags.Protected)) Some(Type(tree.symbol.privateWithin.typeRef))
27+
else None
2628
case _ => None
2729
}
2830

2931
private case class Impl(tree: tpd.DefTree, ctx: Context) extends modifiers.Modifier with Positioned {
3032

31-
override def toString: String = this match {
32-
case _ => s"###"
33+
override def toString: String = {
34+
import Toolbox.extractor
35+
this match {
36+
case modifiers.QualifiedPrivate(tpe) => s"QualifiedPrivate($tpe)"
37+
case modifiers.QualifiedProtected(tpe) => s"QualifiedProtected($tpe)"
38+
}
3339
}
3440
}
3541
}

tests/run-with-compiler/tasty-extractors.check

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ Block(List(ClassDef(Foo, DefDef(<init>, List(), List(List()), Synthetic(), None,
178178
Block(List(ClassDef(Foo, DefDef(<init>, List(), List(List()), Synthetic(), None, List()), List(Apply(Select(New(Synthetic()), <init>), Nil)), None, List(DefDef(a, List(), List(), Synthetic(), Some(Literal(Int(0))), List())), List())), Literal(Unit()))
179179
###
180180

181+
Block(List(ClassDef(Foo, DefDef(<init>, List(), List(List()), Synthetic(), None, List()), List(Apply(Select(New(Synthetic()), <init>), Nil)), None, List(DefDef(a, List(), List(), Synthetic(), Some(Literal(Int(0))), List(QualifiedPrivate(###)))), List())), Literal(Unit()))
182+
###
183+
184+
Block(List(ClassDef(Foo, DefDef(<init>, List(), List(List()), Synthetic(), None, List()), List(Apply(Select(New(Synthetic()), <init>), Nil)), None, List(DefDef(a, List(), List(), Synthetic(), Some(Literal(Int(0))), List(QualifiedProtected(###)))), List())), Literal(Unit()))
185+
###
186+
181187
Block(List(ClassDef(Foo1, DefDef(<init>, List(), List(List(ValDef(a, Ident(Int), None, List()))), Synthetic(), None, List()), List(Apply(Select(New(Synthetic()), <init>), Nil)), None, List(ValDef(a, Synthetic(), None, List())), List())), Literal(Unit()))
182188
###
183189

tests/run-with-compiler/tasty-extractors.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ object Test {
8585
'{ type Foo >: Null <: Object },
8686
'{ class Foo { @volatile var a = 0 } },
8787
'{ class Foo { final def a = 0 } }, // FIXME modifier not printed
88+
'{ class Foo { private[Foo] def a = 0 } },
89+
'{ class Foo { protected[Foo] def a = 0 } },
8890
// '{ case class Foo() },
8991
'{ class Foo1(a: Int) },
9092
'{ class Foo2(val b: Int) },

0 commit comments

Comments
 (0)