Skip to content

Commit 77d3f4b

Browse files
committed
added apply methods to import selectors in Quotes scala#21225
1 parent f7e5df5 commit 77d3f4b

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,6 +1694,8 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
16941694
end SimpleSelectorTypeTest
16951695

16961696
object SimpleSelector extends SimpleSelectorModule:
1697+
def apply(name: String): SimpleSelector =
1698+
withDefaultPos(untpd.ImportSelector(untpd.Ident(name.toTermName)))
16971699
def unapply(x: SimpleSelector): Some[String] = Some(x.name.toString)
16981700
end SimpleSelector
16991701

@@ -1713,6 +1715,8 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
17131715
end RenameSelectorTypeTest
17141716

17151717
object RenameSelector extends RenameSelectorModule:
1718+
def apply(fromName: String, toName: String): RenameSelector =
1719+
withDefaultPos(untpd.ImportSelector(untpd.Ident(fromName.toTermName), untpd.Ident(toName.toTermName)))
17161720
def unapply(x: RenameSelector): (String, String) = (x.fromName, x.toName)
17171721
end RenameSelector
17181722

@@ -1738,6 +1742,8 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
17381742
end OmitSelectorTypeTest
17391743

17401744
object OmitSelector extends OmitSelectorModule:
1745+
def apply(name: String): OmitSelector =
1746+
withDefaultPos(untpd.ImportSelector(untpd.Ident(name.toTermName), untpd.Ident(nme.WILDCARD)))
17411747
def unapply(x: OmitSelector): Some[String] = Some(x.imported.name.toString)
17421748
end OmitSelector
17431749

@@ -1758,6 +1764,11 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
17581764
end GivenSelectorTypeTest
17591765

17601766
object GivenSelector extends GivenSelectorModule:
1767+
def apply(bound: Option[TypeTree]): GivenSelector =
1768+
withDefaultPos(untpd.ImportSelector(
1769+
untpd.Ident(nme.EMPTY),
1770+
bound = bound.map(tpt => untpd.TypedSplice(tpt)).getOrElse(EmptyTree)
1771+
))
17611772
def unapply(x: GivenSelector): Some[Option[TypeTree]] =
17621773
Some(GivenSelectorMethods.bound(x))
17631774
end GivenSelector

library/src/scala/quoted/Quotes.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2545,6 +2545,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
25452545

25462546
/** Methods of the module object `val SimpleSelector` */
25472547
trait SimpleSelectorModule { this: SimpleSelector.type =>
2548+
@experimental def apply(name: String): SimpleSelector
25482549
def unapply(x: SimpleSelector): Some[String]
25492550
}
25502551

@@ -2570,6 +2571,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
25702571

25712572
/** Methods of the module object `val RenameSelector` */
25722573
trait RenameSelectorModule { this: RenameSelector.type =>
2574+
@experimental def apply(fromName: String, toName: String): RenameSelector
25732575
def unapply(x: RenameSelector): (String, String)
25742576
}
25752577

@@ -2597,6 +2599,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
25972599

25982600
/** Methods of the module object `val OmitSelector` */
25992601
trait OmitSelectorModule { this: OmitSelector.type =>
2602+
@experimental def apply(name: String): OmitSelector
26002603
def unapply(x: OmitSelector): Some[String]
26012604
}
26022605

@@ -2621,6 +2624,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
26212624

26222625
/** Methods of the module object `val GivenSelector` */
26232626
trait GivenSelectorModule { this: GivenSelector.type =>
2627+
@experimental def apply(bound: Option[TypeTree]): GivenSelector
26242628
def unapply(x: GivenSelector): Some[Option[TypeTree]]
26252629
}
26262630

0 commit comments

Comments
 (0)