From 3b4dc75710ac51de729224929690422d1b44e3ad Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Thu, 17 Oct 2013 19:12:59 +0200 Subject: deprecates raw tree manipulation facilities in macros.Context --- src/compiler/scala/tools/nsc/typechecker/Macros.scala | 2 +- src/reflect/scala/reflect/macros/ExprUtils.scala | 13 +++++++++++++ src/reflect/scala/reflect/macros/Parsers.scala | 3 +++ src/reflect/scala/reflect/macros/TreeBuilder.scala | 19 +++++++++++++++++++ src/reflect/scala/reflect/macros/Universe.scala | 1 + 5 files changed, 37 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/typechecker/Macros.scala b/src/compiler/scala/tools/nsc/typechecker/Macros.scala index 4765c301dd..d1045757a5 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Macros.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Macros.scala @@ -111,7 +111,7 @@ trait Macros extends FastTrack with MacroRuntimes with Traces with Helpers { * with synthetic content that carries the payload described in `MacroImplBinding`. * * For example, for a pair of macro definition and macro implementation: - * def impl(c: scala.reflect.macros.Context): c.Expr[Unit] = c.literalUnit; + * def impl(c: scala.reflect.macros.Context): c.Expr[Unit] = ??? * def foo: Unit = macro impl * * We will have the following annotation added on the macro definition `foo`: diff --git a/src/reflect/scala/reflect/macros/ExprUtils.scala b/src/reflect/scala/reflect/macros/ExprUtils.scala index af11bd6efc..76a8392b9c 100644 --- a/src/reflect/scala/reflect/macros/ExprUtils.scala +++ b/src/reflect/scala/reflect/macros/ExprUtils.scala @@ -12,41 +12,54 @@ trait ExprUtils { self: Context => /** Shorthand for `Literal(Constant(null))` in the underlying `universe`. */ + @deprecated("Use quasiquotes instead", "2.11.0") def literalNull: Expr[Null] /** Shorthand for `Literal(Constant(()))` in the underlying `universe`. */ + @deprecated("Use quasiquotes instead", "2.11.0") def literalUnit: Expr[Unit] /** Shorthand for `Literal(Constant(true))` in the underlying `universe`. */ + @deprecated("Use quasiquotes instead", "2.11.0") def literalTrue: Expr[Boolean] /** Shorthand for `Literal(Constant(false))` in the underlying `universe`. */ + @deprecated("Use quasiquotes instead", "2.11.0") def literalFalse: Expr[Boolean] /** Shorthand for `Literal(Constant(x: Boolean))` in the underlying `universe`. */ + @deprecated("Use quasiquotes instead", "2.11.0") def literal(x: Boolean): Expr[Boolean] /** Shorthand for `Literal(Constant(x: Byte))` in the underlying `universe`. */ + @deprecated("Use quasiquotes instead", "2.11.0") def literal(x: Byte): Expr[Byte] /** Shorthand for `Literal(Constant(x: Short))` in the underlying `universe`. */ + @deprecated("Use quasiquotes instead", "2.11.0") def literal(x: Short): Expr[Short] /** Shorthand for `Literal(Constant(x: Int))` in the underlying `universe`. */ + @deprecated("Use quasiquotes instead", "2.11.0") def literal(x: Int): Expr[Int] /** Shorthand for `Literal(Constant(x: Long))` in the underlying `universe`. */ + @deprecated("Use quasiquotes instead", "2.11.0") def literal(x: Long): Expr[Long] /** Shorthand for `Literal(Constant(x: Float))` in the underlying `universe`. */ + @deprecated("Use quasiquotes instead", "2.11.0") def literal(x: Float): Expr[Float] /** Shorthand for `Literal(Constant(x: Double))` in the underlying `universe`. */ + @deprecated("Use quasiquotes instead", "2.11.0") def literal(x: Double): Expr[Double] /** Shorthand for `Literal(Constant(x: String))` in the underlying `universe`. */ + @deprecated("Use quasiquotes instead", "2.11.0") def literal(x: String): Expr[String] /** Shorthand for `Literal(Constant(x: Char))` in the underlying `universe`. */ + @deprecated("Use quasiquotes instead", "2.11.0") def literal(x: Char): Expr[Char] } diff --git a/src/reflect/scala/reflect/macros/Parsers.scala b/src/reflect/scala/reflect/macros/Parsers.scala index 3b25309614..4232b05f8c 100644 --- a/src/reflect/scala/reflect/macros/Parsers.scala +++ b/src/reflect/scala/reflect/macros/Parsers.scala @@ -8,6 +8,7 @@ package macros * A slice of [[scala.reflect.macros.Context the Scala macros context]] that * exposes functions to parse strings with Scala code into trees. */ +@deprecated("Use quasiquotes instead", "2.11.0") trait Parsers { self: Context => @@ -15,9 +16,11 @@ trait Parsers { * Only works for expressions, i.e. parsing a package declaration will fail. * @throws [[scala.reflect.macros.ParseException]] */ + @deprecated("Use quasiquotes instead", "2.11.0") def parse(code: String): Tree } /** Indicates an error during [[scala.reflect.macros.Parsers#parse]]. */ + @deprecated("Use quasiquotes instead", "2.11.0") case class ParseException(pos: scala.reflect.api.Position, msg: String) extends Exception(msg) diff --git a/src/reflect/scala/reflect/macros/TreeBuilder.scala b/src/reflect/scala/reflect/macros/TreeBuilder.scala index 427b4f70d1..7f57274347 100644 --- a/src/reflect/scala/reflect/macros/TreeBuilder.scala +++ b/src/reflect/scala/reflect/macros/TreeBuilder.scala @@ -8,6 +8,7 @@ package macros * A helper available in [[scala.reflect.macros.Universe]] that defines shorthands for the * most common tree-creating functions. */ +@deprecated("Use quasiquotes instead", "2.11.0") abstract class TreeBuilder { val global: Universe @@ -17,6 +18,7 @@ abstract class TreeBuilder { * The type must be suitable for this. For example, it * must not be a TypeRef pointing to an abstract type variable. */ + @deprecated("Use quasiquotes instead", "2.11.0") def mkAttributedQualifier(tpe: Type): Tree /** Builds a reference to value whose type is given stable prefix. @@ -25,27 +27,35 @@ abstract class TreeBuilder { * termSym as the Ident's symbol. In that case, termSym must * not be NoSymbol. */ + @deprecated("Use quasiquotes instead", "2.11.0") def mkAttributedQualifier(tpe: Type, termSym: Symbol): Tree /** Builds a typed reference to given symbol with given stable prefix. */ + @deprecated("Use quasiquotes instead", "2.11.0") def mkAttributedRef(pre: Type, sym: Symbol): RefTree /** Builds a typed reference to given symbol. */ + @deprecated("Use quasiquotes instead", "2.11.0") def mkAttributedRef(sym: Symbol): RefTree /** Builds an untyped reference to given symbol. Requires the symbol to be static. */ + @deprecated("Use quasiquotes instead", "2.11.0") def mkUnattributedRef(sym: Symbol): RefTree /** Builds an untyped reference to symbol with given name. Requires the symbol to be static. */ + @deprecated("Use quasiquotes instead", "2.11.0") def mkUnattributedRef(fullName: Name): RefTree /** Builds a typed This reference to given symbol. */ + @deprecated("Use quasiquotes instead", "2.11.0") def mkAttributedThis(sym: Symbol): This /** Builds a typed Ident with an underlying symbol. */ + @deprecated("Use quasiquotes instead", "2.11.0") def mkAttributedIdent(sym: Symbol): RefTree /** Builds a typed Select with an underlying symbol. */ + @deprecated("Use quasiquotes instead", "2.11.0") def mkAttributedSelect(qual: Tree, sym: Symbol): RefTree /** A creator for method calls, e.g. fn[T1, T2, ...](v1, v2, ...) @@ -57,22 +67,31 @@ abstract class TreeBuilder { * @param args value arguments * @return the newly created trees. */ + @deprecated("Use quasiquotes instead", "2.11.0") def mkMethodCall(receiver: Symbol, methodName: Name, targs: List[Type], args: List[Tree]): Tree + @deprecated("Use quasiquotes instead", "2.11.0") def mkMethodCall(method: Symbol, targs: List[Type], args: List[Tree]): Tree + @deprecated("Use quasiquotes instead", "2.11.0") def mkMethodCall(method: Symbol, args: List[Tree]): Tree + @deprecated("Use quasiquotes instead", "2.11.0") def mkMethodCall(target: Tree, args: List[Tree]): Tree + @deprecated("Use quasiquotes instead", "2.11.0") def mkMethodCall(receiver: Symbol, methodName: Name, args: List[Tree]): Tree + @deprecated("Use quasiquotes instead", "2.11.0") def mkMethodCall(receiver: Tree, method: Symbol, targs: List[Type], args: List[Tree]): Tree + @deprecated("Use quasiquotes instead", "2.11.0") def mkMethodCall(target: Tree, targs: List[Type], args: List[Tree]): Tree + @deprecated("Use quasiquotes instead", "2.11.0") def mkNullaryCall(method: Symbol, targs: List[Type]): Tree /** A tree that refers to the runtime reflexive universe, `scala.reflect.runtime.universe`. */ + @deprecated("Use quasiquotes instead", "2.11.0") def mkRuntimeUniverseRef: Tree } diff --git a/src/reflect/scala/reflect/macros/Universe.scala b/src/reflect/scala/reflect/macros/Universe.scala index d1d90f53c9..297bac2999 100644 --- a/src/reflect/scala/reflect/macros/Universe.scala +++ b/src/reflect/scala/reflect/macros/Universe.scala @@ -20,6 +20,7 @@ abstract class Universe extends scala.reflect.api.Universe { /** A factory that encapsulates common tree-building functions. * @group Macros */ + @deprecated("Use quasiquotes instead", "2.11.0") val treeBuild: TreeBuilder { val global: Universe.this.type } /** The API of reflection artifacts that support [[scala.reflect.macros.Attachments]]. -- cgit v1.2.3