Skip to content

Commit

Permalink
Fix warn messages in doc
Browse files Browse the repository at this point in the history
Fix warn messages in doc
  • Loading branch information
mlachkar committed Oct 8, 2020
1 parent e79b791 commit 821161e
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 44 deletions.
51 changes: 25 additions & 26 deletions docs/developers/semantic-tree.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ The variable `doc` in the code examples is an implicit instance of
```scala mdoc:passthrough
import scalafix.docs.PatchDocs
def println(a: Any): Unit = PatchDocs.println(a)
import scalafix.docs.PatchDocs._
implicit var doc: SemanticDocument = null
```

Expand All @@ -53,21 +52,21 @@ parameters
doc.tree.traverse {
// Option.apply
case option @ Term.Select(Term.Name("Option"), Term.Name("apply")) =>
println("synthetic = " + option.synthetic)
println("structure = " + option.synthetic.structure)
println("synthetic = " + option.synthetics)
println("structure = " + option.synthetics.structure)
}
```

The asterisk `*` represents an `OriginalTree` node that matches the enclosing
non-synthetic tree, which is `List` in this example.

The `.synthetic` method is only available on `Term` nodes, using the method on
The `.synthetics` method is only available on `Term` nodes, using the method on
other tree nodes such as types results in compilation error

```scala mdoc:fail
doc.tree.traverse {
case app @ Type.Name("App") =>
println(".synthetic = " + app.synthetic)
println(".synthetic = " + app.synthetics)
}
```

Expand All @@ -83,21 +82,21 @@ Option[Int](2) // inferred: Option.apply[Int](2)
""")
```

Use `Tree.synthetic` in combination with `SemanticTree.symbol` to get the symbol
Use `Tree.synthetics` in combination with `SemanticTree.symbol` to get the symbol
of those inferred `.apply` method calls.

```scala mdoc
doc.tree.traverse {
case Term.Apply(add @ q"add", List(q"2")) =>
println("add(2)")
println("synthetic = " + add.synthetic)
println("symbol = " + add.synthetic.flatMap(_.symbol).structure)
println("structure = " + add.synthetic.structure)
println("synthetic = " + add.synthetics)
println("symbol = " + add.synthetics.flatMap(_.symbol).structure)
println("structure = " + add.synthetics.structure)
case Term.ApplyType(option @ q"Option", List(t"Int")) =>
println("Option[Int]")
println("synthetic = " + option.synthetic)
println("symbol = " + option.synthetic.flatMap(_.symbol).structure)
println("structure = " + option.synthetic.structure)
println("synthetic = " + option.synthetics)
println("symbol = " + option.synthetics.flatMap(_.symbol).structure)
println("structure = " + option.synthetics.structure)
}
```

Expand All @@ -124,14 +123,14 @@ Main.run // implicit argument: message
""")
```

Use `Tree.synthetic` to look up an implicit argument for any `Term` node.
Use `Tree.synthetics` to look up an implicit argument for any `Term` node.

```scala mdoc
doc.tree.traverse {
case term: Term if term.synthetic.isDefined =>
case term: Term if term.synthetics.nonEmpty =>
println("term = " + term.syntax)
println("synthetic = " + term.synthetic)
println("structure = " + term.synthetic.structure)
println("synthetics = " + term.synthetics)
println("structure = " + term.synthetics.structure)
}
```

Expand All @@ -146,18 +145,18 @@ List(1) ++ List(2)
""")
```

Use the `Term.ApplyInfix.syntheticOperator` to look up inferred type parameters
Use the `Term.ApplyInfix.syntheticOperators` to look up inferred type parameters
of infix operators.

```scala mdoc
doc.tree.traverse {
case concat @ Term.ApplyInfix(_, Term.Name("++"), _, _) =>
println(".syntheticOperator = " + concat.syntheticOperator)
println(".structure = " + concat.syntheticOperator.structure)
println(".syntheticOperators = " + concat.syntheticOperators)
println(".structure = " + concat.syntheticOperators.structure)
}
```

The `.syntheticOperator` method is only available for `Term.ApplyInfix` nodes,
The `.syntheticOperators` method is only available for `Term.ApplyInfix` nodes,
using the method on other node types results in a compilation error

[comment]: <> (Todo: add mdoc:fail for this snippet!)
Expand All @@ -173,7 +172,7 @@ Beware that looking up synthetics for the infix operator name returns nothing
```scala mdoc
doc.tree.traverse {
case concat @ Term.Name("++") =>
println(".synthetic = " + concat.synthetic)
println(".synthetics = " + concat.synthetics)
}
```

Expand All @@ -191,18 +190,18 @@ for (number <- numbers) println(number)
""")
```

Use `Tree.synthetic` on the tree node `Term.ForYield` to inspect the desugared
Use `Tree.synthetics` on the tree node `Term.ForYield` to inspect the desugared
version of the `for { .. } yield` expression

```scala mdoc
doc.tree.traverse {
case forYield: Term.ForYield =>
println(".synthetic = " + forYield.synthetic)
println(".synthetics = " + forYield.synthetics)
}
```

The `orig(List(1, 2))` and `orig(1.to(i)` parts represent `OriginalSubTree`
nodes that match non-synthetic tree nodes from the original for-comprension.
nodes that match non-synthetic tree nodes from the original for-comprehension.

## Known limitations

Expand All @@ -228,7 +227,7 @@ Observe the empty `withFilter` body and `<unknown>` parameter symbol.
```scala mdoc
doc.tree.traverse {
case forYield: Term.ForYield =>
println(forYield.synthetic)
println(forYield.synthetics)
}
```

Expand All @@ -250,7 +249,7 @@ Observe the `<unknown>` parameter symbol to the final call to `map`.
```scala mdoc
doc.tree.traverse {
case forYield: Term.ForYield =>
println(forYield.synthetic)
println(forYield.synthetics)
}
```

Expand Down
4 changes: 2 additions & 2 deletions docs/developers/semantic-type.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Use `MethodSignature.returnType` to get the types of vals.

```scala mdoc
def getType(symbol: Symbol): SemanticType =
symbol.info.get.signature match {
(symbol.info.get.signature: @unchecked) match {
case MethodSignature(_, _, returnType) =>
returnType
}
Expand Down Expand Up @@ -167,7 +167,7 @@ def simpleDealias(tpe: SemanticType): SemanticType = {
case _ =>
symbol
}
tpe match {
(tpe: @unchecked) match {
case TypeRef(prefix, symbol, typeArguments) =>
TypeRef(prefix, dealiasSymbol(symbol), typeArguments.map(simpleDealias))
}
Expand Down
26 changes: 13 additions & 13 deletions docs/developers/symbol-information.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Use `MethodSignature.returnType` to inspect the return type of a method.

```scala mdoc
def printReturnType(symbol: Symbol): Unit = {
symbol.info.get.signature match {
(symbol.info.get.signature: @unchecked) match {
case signature @ MethodSignature(_, _, returnType) =>
println("returnType = " + returnType)
println("signature = " + signature)
Expand Down Expand Up @@ -104,7 +104,7 @@ Use `MethodSignature.parameterLists` to look up parameters of a method.

```scala mdoc
def printMethodParameters(symbol: Symbol): Unit = {
symbol.info.get.signature match {
(symbol.info.get.signature: @unchecked) match {
case signature @ MethodSignature(typeParameters, parameterLists, _) =>
if (typeParameters.nonEmpty) {
println("typeParameters")
Expand Down Expand Up @@ -151,7 +151,7 @@ Nullary method signatures are distinguished by having an no parameter lists:

```scala mdoc
def printParameterList(symbol: Symbol): Unit = {
symbol.info.get.signature match {
(symbol.info.get.signature: @unchecked) match {
case MethodSignature(_, parameterLists, _) =>
println(parameterLists)
}
Expand Down Expand Up @@ -189,7 +189,7 @@ Use `TypeSignature` to inspect type aliases.

```scala mdoc
def printTypeAlias(symbol: Symbol): Unit = {
symbol.info.get.signature match {
(symbol.info.get.signature: @unchecked) match {
case signature @ TypeSignature(typeParameters, lowerBound, upperBound) =>
if (lowerBound == upperBound) {
println("Type alias where upperBound == lowerBound")
Expand Down Expand Up @@ -236,11 +236,11 @@ Use `ClassSignature.parents` and `TypeRef.symbol` to lookup the class hierarchy.

```scala mdoc
def getParentSymbols(symbol: Symbol): Set[Symbol] =
symbol.info.get.signature match {
(symbol.info.get.signature: @unchecked) match {
case ClassSignature(_, parents, _, _) =>
Set(symbol) ++ parents.flatMap {
Set(symbol) ++ parents.collect {
case TypeRef(_, symbol, _) => getParentSymbols(symbol)
}
}.flatten
}
getParentSymbols(Symbol("java/lang/String#"))
```
Expand All @@ -256,9 +256,9 @@ def getClassMethods(symbol: Symbol): Set[SymbolInformation] =
symbol.info.get.signature match {
case ClassSignature(_, parents, _, declarations) =>
val methods = declarations.filter(_.isMethod)
methods.toSet ++ parents.flatMap {
methods.toSet ++ parents.collect {
case TypeRef(_, symbol, _) => getClassMethods(symbol)
}
}.flatten
case _ => Set.empty
}
getClassMethods(Symbol("scala/Some#")).take(5)
Expand Down Expand Up @@ -347,7 +347,7 @@ Use the primary constructor to get the names of the case class fields
```scala mdoc
getConstructors(Symbol("example/User#")).foreach {
case ctor if ctor.isPrimary =>
ctor.signature match {
(ctor.signature: @unchecked) match {
case MethodSignature(_, parameters :: _, _) =>
val names = parameters.map(_.displayName)
println("names: " + names.mkString(", "))
Expand All @@ -362,15 +362,15 @@ Use `SymbolInformation.{isMethod,displayName}` to query for overloaded methods.

```scala mdoc
def getMethodOverloads(classSymbol: Symbol, methodName: String): Set[SymbolInformation] =
classSymbol.info.get.signature match {
(classSymbol.info.get.signature: @unchecked) match {
case ClassSignature(_, parents, _, declarations) =>
val overloadedMethods = declarations.filter { declaration =>
declaration.isMethod &&
declaration.displayName == methodName
}
overloadedMethods.toSet ++ parents.flatMap {
overloadedMethods.toSet ++ parents.collect {
case TypeRef(_, symbol, _) => getMethodOverloads(symbol, methodName)
}
}.flatten
case _ => Set.empty
}
getMethodOverloads(Symbol("java/lang/String#"), "substring")
Expand Down
1 change: 0 additions & 1 deletion docs/developers/symbol-matcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import scala.meta._
```scala mdoc:passthrough
import scalafix.docs.PatchDocs
def println(a: Any): Unit = PatchDocs.println(a)
import scalafix.docs.PatchDocs._
```

## SemanticDB
Expand Down
2 changes: 1 addition & 1 deletion docs/developers/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ trees.

```scala mdoc
println(q"complete(true)".structure) // line wrap at 80th column
println(q"complete(true)".structure(30)) // line wrap at 30th column
println(q"complete(true)".structureWidth(30)) // line wrap at 30th column
```

The output of `tree.structure` can be copy-pasted for use in pattern matching.
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ExplicitSynthetic(insertInfixTypeParam: Boolean)
None
case infix: Term.ApplyInfix if insertInfixTypeParam =>
for {
synthetic <- infix.syntheticOperator.collect {
synthetic <- infix.syntheticOperators.collect {
case tappl: TypeApplyTree => tappl
}
} yield {
Expand Down

0 comments on commit 821161e

Please sign in to comment.