Skip to content

Commit

Permalink
Drop more outdated import given selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed Feb 11, 2020
1 parent 1daedbf commit fc4b25a
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions docs/docs/reference/contextual/derivation-macro.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ from the signature. The body of the `derived` method is shown below:

```scala
given derived[T: Type](using qctx: QuoteContext) as Expr[Eq[T]] = {
import qctx.tasty.{_, given}
import qctx.tasty.{_, given _}

val ev: Expr[Mirror.Of[T]] = summonExpr(using '[Mirror.Of[T]]).get

Expand Down Expand Up @@ -176,7 +176,7 @@ object Eq {
}

given derived[T: Type](using qctx: QuoteContext) as Expr[Eq[T]] = {
import qctx.tasty.{_, given}
import qctx.tasty.{_, given _}

val ev: Expr[Mirror.Of[T]] = summonExpr(using '[Mirror.Of[T]]).get

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/reference/metaprogramming/macros.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ Here’s a compiler that maps an expression given in the interpreted
language to quoted Scala code of type `Expr[Int]`.
The compiler takes an environment that maps variable names to Scala `Expr`s.
```scala
import scala.quoted.{given, _}
import scala.quoted.{given _, _}

def compile(e: Exp, env: Map[String, Expr[Int]]): Expr[Int] = e match {
case Num(n) =>
Expand Down
10 changes: 5 additions & 5 deletions docs/docs/reference/metaprogramming/tasty-reflect.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ import scala.quoted._
inline def natConst(x: => Int): Int = ${natConstImpl('{x})}

def natConstImpl(x: Expr[Int])(using qctx: QuoteContext): Expr[Int] = {
import qctx.tasty.{_, given}
import qctx.tasty.{_, given _}
...
}
```

### Sealing and Unsealing

`import qctx.tasty.{_, given}` will provide an `unseal` extension method on `quoted.Expr`
`import qctx.tasty.{_, given _}` will provide an `unseal` extension method on `quoted.Expr`
and `quoted.Type` which returns a `qctx.tasty.Term` that represents the tree of
the expression and `qctx.tasty.TypeTree` that represents the tree of the type
respectively. It will also import all extractors and methods on TASTy Reflect
trees. For example the `Literal(_)` extractor used below.

```scala
def natConstImpl(x: Expr[Int])(using qctx: QuoteContext): Expr[Int] = {
import qctx.tasty.{_, given}
import qctx.tasty.{_, given _}
val xTree: Term = x.unseal
xTree match {
case Inlined(_, _, Literal(Constant(n: Int))) =>
Expand Down Expand Up @@ -81,7 +81,7 @@ operation expression passed while calling the `macro` below.
inline def macro(param: => Boolean): Unit = ${ macroImpl('param) }

def macroImpl(param: Expr[Boolean])(using qctx: QuoteContext): Expr[Unit] = {
import qctx.tasty.{_, given}
import qctx.tasty.{_, given _}
import util._

param.unseal.underlyingArgument match {
Expand All @@ -103,7 +103,7 @@ point.

```scala
def macroImpl()(qctx: QuoteContext): Expr[Unit] = {
import qctx.tasty.{_, given}
import qctx.tasty.{_, given _}
val pos = rootPosition

val path = pos.sourceFile.jpath.toString
Expand Down
2 changes: 1 addition & 1 deletion library/src/scala/tasty/reflect/TreeTraverser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package reflect
* ```
* class MyTraverser[R <: scala.tasty.Reflection & Singleton](val reflect: R)
* extends scala.tasty.reflect.TreeTraverser {
* import reflect.{given, _}
* import reflect.{given _, _}
* override def traverseTree(tree: Tree)(using ctx: Context): Unit = ...
* }
* ```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ object Main extends App {

val inspector = new TastyInspector {
protected def processCompilationUnit(reflect: Reflection)(root: reflect.Tree): Unit = {
import reflect.{given, _}
import reflect.{given _, _}
val tastyStr = root.show
println(tastyStr)
}
Expand Down
16 changes: 8 additions & 8 deletions tastydoc/src/dotty/tastydoc/TastyExtractor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import dotty.tastydoc.representations._
/** A trait containing useful methods for extracting information from the reflect API */
trait TastyExtractor extends TastyTypeConverter with CommentParser with CommentCleaner{
def extractPath(reflect: Reflection)(symbol: reflect.Symbol) : List[String] = {
import reflect.{given, _}
import reflect.{given _, _}

val pathArray = symbol.show.split("\\.") // NOTE: this should print w/o colors, inspect afterwards
pathArray.iterator.slice(0, pathArray.length - 1).toList
}

def extractModifiers(reflect: Reflection)(flags: reflect.Flags, privateWithin: Option[reflect.Type], protectedWithin: Option[reflect.Type]) : (List[String], Option[Reference], Option[Reference]) = {
import reflect.{given, _}
import reflect.{given _, _}

(((if(flags.is(Flags.Override)) "override" else "") ::
(if(flags.is(Flags.Private)) "private" else "")::
Expand All @@ -40,7 +40,7 @@ trait TastyExtractor extends TastyTypeConverter with CommentParser with CommentC
}

def extractComments(reflect: Reflection)(comment: Option[reflect.Comment], rep: Representation) : (Map[String, EmulatedPackageRepresentation], String) => Option[Comment] = {
import reflect.{given, _}
import reflect.{given _, _}

comment match {
case Some(com) =>
Expand All @@ -59,7 +59,7 @@ trait TastyExtractor extends TastyTypeConverter with CommentParser with CommentC
}

def extractClassMembers(reflect: Reflection)(body: List[reflect.Statement], symbol: reflect.Symbol, parentRepresentation: Some[Representation])(using mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]) : List[Representation with Modifiers] = {
import reflect.{given, _}
import reflect.{given _, _}

/** Filter fields which shouldn't be displayed in the doc
*/
Expand Down Expand Up @@ -99,7 +99,7 @@ trait TastyExtractor extends TastyTypeConverter with CommentParser with CommentC
}

def extractParents(reflect: Reflection)(parents: List[reflect.Tree]): List[Reference] = {
import reflect.{given, _}
import reflect.{given _, _}

val parentsReferences = parents.map{
case c: TypeTree => convertTypeToReference(reflect)(c.tpe)
Expand All @@ -118,7 +118,7 @@ trait TastyExtractor extends TastyTypeConverter with CommentParser with CommentC
* @return (is case, is a trait, is an object, the kind as a String)
*/
def extractKind(reflect: Reflection)(flags: reflect.Flags): (Boolean, Boolean, Boolean, String) = {
import reflect.{given, _}
import reflect.{given _, _}

val isCase = flags.is(reflect.Flags.Case)
val isTrait = flags.is(reflect.Flags.Trait)
Expand All @@ -143,7 +143,7 @@ trait TastyExtractor extends TastyTypeConverter with CommentParser with CommentC
}

def extractCompanion(reflect: Reflection)(companionModule: Option[reflect.Symbol], companionClass: Option[reflect.Symbol], companionIsObject: Boolean): Option[CompanionReference] = {
import reflect.{given, _}
import reflect.{given _, _}

if(companionIsObject){
companionModule match {
Expand All @@ -165,7 +165,7 @@ trait TastyExtractor extends TastyTypeConverter with CommentParser with CommentC
}

def extractAnnotations(reflect: Reflection)(annots: List[reflect.Term]): List[TypeReference] = {
import reflect.{given, _}
import reflect.{given _, _}

def keepAnnot(label: String, link: String): Boolean = {
!(label == "SourceFile" && link == "/internal") &&
Expand Down
4 changes: 2 additions & 2 deletions tastydoc/src/dotty/tastydoc/TastyTypeConverter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import dotty.tastydoc.references._
trait TastyTypeConverter {

def convertTypeOrBoundsToReference(reflect: Reflection)(typeOrBounds: reflect.TypeOrBounds): Reference = {
import reflect.{given, _}
import reflect.{given _, _}

def anyOrNothing(reference: Reference): Boolean = reference match {
case TypeReference("Any", "/scala", _, _) => true
Expand All @@ -30,7 +30,7 @@ trait TastyTypeConverter {
}

def convertTypeToReference(reflect: Reflection)(tp: reflect.Type): Reference = {
import reflect.{given, _}
import reflect.{given _, _}

//Inner method to avoid passing the reflection each time
def inner(tp: reflect.Type): Reference = tp match {
Expand Down
14 changes: 7 additions & 7 deletions tastydoc/src/dotty/tastydoc/representations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ object representations extends TastyExtractor {
}

class PackageRepresentation(reflect: Reflection, internal: reflect.PackageClause, override val parentRepresentation: Option[Representation])(using mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]) extends Representation with Members {
import reflect.{given, _}
import reflect.{given _, _}

override val (name, path) = extractPackageNameAndPath(internal.pid.show)
override val members = internal.stats.map(convertToRepresentation(reflect)(_, Some(this)))
Expand All @@ -93,7 +93,7 @@ object representations extends TastyExtractor {
}

class ImportRepresentation(reflect: Reflection, internal: reflect.Import, override val parentRepresentation: Option[Representation])(using mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]) extends Representation {
import reflect.{given, _}
import reflect.{given _, _}

override val name = if (internal.selectors.size > 1){
internal.selectors.map(_.toString).mkString("{", ", ", "}")
Expand All @@ -107,7 +107,7 @@ object representations extends TastyExtractor {
}

class ClassRepresentation(reflect: Reflection, internal: reflect.ClassDef, override val parentRepresentation: Option[Representation])(using mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]) extends Representation with Members with Parents with Modifiers with Companion with Constructors with TypeParams {
import reflect.{given, _}
import reflect.{given _, _}

override val path = extractPath(reflect)(internal.symbol)
override val parents = extractParents(reflect)(internal.parents)
Expand Down Expand Up @@ -143,7 +143,7 @@ object representations extends TastyExtractor {
}

class DefRepresentation(reflect: Reflection, internal: reflect.DefDef, override val parentRepresentation: Option[Representation])(using mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]) extends Representation with Modifiers with TypeParams with MultipleParamList with ReturnValue {
import reflect.{given, _}
import reflect.{given _, _}

override val name = internal.name
override val path = extractPath(reflect)(internal.symbol)
Expand All @@ -162,7 +162,7 @@ object representations extends TastyExtractor {
}

class ValRepresentation(reflect: Reflection, internal: reflect.ValDef, override val parentRepresentation: Option[Representation])(using mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]) extends Representation with Modifiers with ReturnValue {
import reflect.{given, _}
import reflect.{given _, _}

override val name = internal.name
override val path = extractPath(reflect)(internal.symbol)
Expand All @@ -175,7 +175,7 @@ object representations extends TastyExtractor {
}

class TypeRepresentation(reflect: Reflection, internal: reflect.TypeDef, override val parentRepresentation: Option[Representation])(using mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]) extends Representation with Modifiers with TypeParams {
import reflect.{given, _}
import reflect.{given _, _}

override val name = internal.name
override val path = extractPath(reflect)(internal.symbol)
Expand All @@ -192,7 +192,7 @@ object representations extends TastyExtractor {
}

def convertToRepresentation(reflect: Reflection)(tree: reflect.Tree, parentRepresentation: Option[Representation])(using mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]): Representation = {
import reflect.{given, _}
import reflect.{given _, _}

tree match {
case t: reflect.PackageClause =>
Expand Down

0 comments on commit fc4b25a

Please sign in to comment.