-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
63 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
24 changes: 24 additions & 0 deletions
24
runtime/src/main/scala-3.0.0-M3/mdoc/internal/pprint/TypePrinter.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package mdoc.internal.pprint | ||
|
||
import scala.language.implicitConversions | ||
import scala.quoted._ | ||
import scala.quoted.runtime.impl.printers.SyntaxHighlight | ||
|
||
trait TPrint[T]{ | ||
def render: String | ||
} | ||
|
||
object TPrint { | ||
inline given default[T]: TPrint[T] = ${ TypePrinter.typeString[T] } | ||
} | ||
|
||
object TypePrinter{ | ||
|
||
def typeString[T](using ctx: Quotes, tpe: Type[T]): Expr[TPrint[T]] = { | ||
import ctx.reflect._ | ||
|
||
val valueType = TypeTree.of[T](using tpe).tpe.show(using Printer.TypeReprShortCode) | ||
|
||
'{ new TPrint[T]{ def render: String = ${ Expr(valueType) } } } | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
runtime/src/main/scala-3.0.0-M3/mdoc/internal/sourcecode/Macros.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package mdoc.internal.sourcecode | ||
|
||
import scala.language.implicitConversions | ||
import scala.quoted._ | ||
|
||
trait StatementMacro { | ||
inline implicit def generate[T](v: => T): SourceStatement[T] = ${ Macros.text('v) } | ||
inline def apply[T](v: => T): SourceStatement[T] = ${ Macros.text('v) } | ||
} | ||
|
||
object Macros{ | ||
|
||
def text[T: Type](v: Expr[T])(using ctx: Quotes): Expr[SourceStatement[T]] = { | ||
import ctx.reflect.{_, given} | ||
val txt = Term.of(v).pos.sourceCode.getOrElse("") | ||
'{SourceStatement[T]($v, ${Expr(txt)})} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters