summaryrefslogtreecommitdiff
path: root/src/reflect
diff options
context:
space:
mode:
Diffstat (limited to 'src/reflect')
-rw-r--r--src/reflect/scala/reflect/macros/ExprUtils.scala13
-rw-r--r--src/reflect/scala/reflect/macros/Parsers.scala3
-rw-r--r--src/reflect/scala/reflect/macros/TreeBuilder.scala19
-rw-r--r--src/reflect/scala/reflect/macros/Universe.scala1
-rw-r--r--src/reflect/scala/reflect/runtime/JavaMirrors.scala42
-rw-r--r--src/reflect/scala/reflect/runtime/ReflectionUtils.scala14
-rw-r--r--src/reflect/scala/reflect/runtime/SymbolLoaders.scala4
7 files changed, 65 insertions, 31 deletions
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]].
diff --git a/src/reflect/scala/reflect/runtime/JavaMirrors.scala b/src/reflect/scala/reflect/runtime/JavaMirrors.scala
index 1e2dd6b7d3..8e822ca4f0 100644
--- a/src/reflect/scala/reflect/runtime/JavaMirrors.scala
+++ b/src/reflect/scala/reflect/runtime/JavaMirrors.scala
@@ -18,7 +18,7 @@ import internal.pickling.ByteCodecs
import internal.pickling.UnPickler
import scala.collection.mutable.{ HashMap, ListBuffer }
import internal.Flags._
-import ReflectionUtils.{staticSingletonInstance, innerSingletonInstance, scalacShouldntLoadClass}
+import ReflectionUtils._
import scala.language.existentials
import scala.runtime.{ScalaRunTime, BoxesRunTime}
@@ -777,33 +777,19 @@ private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUni
/**
* The Scala owner of the Scala class corresponding to the Java class `jclazz`
*/
- private def sOwner(jclazz: jClass[_]): Symbol =
- if (jclazz.isMemberClass) {
- val jEnclosingClass = jclazz.getEnclosingClass
- val sEnclosingClass = classToScala(jEnclosingClass)
- followStatic(sEnclosingClass, jclazz.javaFlags)
- } else if (jclazz.isLocalClass0) {
- val jEnclosingMethod = jclazz.getEnclosingMethod
- if (jEnclosingMethod != null) {
- methodToScala(jEnclosingMethod)
- } else {
- val jEnclosingConstructor = jclazz.getEnclosingConstructor
- constructorToScala(jEnclosingConstructor)
- }
- } else if (jclazz.isPrimitive || jclazz.isArray) {
- ScalaPackageClass
- } else if (jclazz.getPackage != null) {
- val jPackage = jclazz.getPackage
- packageToScala(jPackage).moduleClass
- } else {
- // @eb: a weird classloader might return a null package for something with a non-empty package name
- // for example, http://groups.google.com/group/scala-internals/browse_thread/thread/7be09ff8f67a1e5c
- // in that case we could invoke packageNameToScala(jPackageName) and, probably, be okay
- // however, I think, it's better to blow up, since weirdness of the class loader might bite us elsewhere
- // [martin] I think it's better to be forgiving here. Restoring packageNameToScala.
- val jPackageName = jclazz.getName take jclazz.getName.lastIndexOf('.')
- packageNameToScala(jPackageName).moduleClass
- }
+ // @eb: a weird classloader might return a null package for something with a non-empty package name
+ // for example, http://groups.google.com/group/scala-internals/browse_thread/thread/7be09ff8f67a1e5c
+ // in that case we could invoke packageNameToScala(jPackageName) and, probably, be okay
+ // however, I think, it's better to blow up, since weirdness of the class loader might bite us elsewhere
+ // [martin] I think it's better to be forgiving here. Restoring packageNameToScala.
+ private def sOwner(jclazz: jClass[_]): Symbol = jclazz match {
+ case PrimitiveOrArray() => ScalaPackageClass
+ case EnclosedInMethod(jowner) => methodToScala(jowner)
+ case EnclosedInConstructor(jowner) => constructorToScala(jowner)
+ case EnclosedInClass(jowner) => followStatic(classToScala(jowner), jclazz.javaFlags)
+ case EnclosedInPackage(jowner) => packageToScala(jowner).moduleClass
+ case _ => packageNameToScala(jclazz.getName take jclazz.getName.lastIndexOf('.')).moduleClass
+ }
/**
* The Scala owner of the Scala symbol corresponding to the Java member `jmember`
diff --git a/src/reflect/scala/reflect/runtime/ReflectionUtils.scala b/src/reflect/scala/reflect/runtime/ReflectionUtils.scala
index 710ec02acd..813c0e1386 100644
--- a/src/reflect/scala/reflect/runtime/ReflectionUtils.scala
+++ b/src/reflect/scala/reflect/runtime/ReflectionUtils.scala
@@ -84,4 +84,18 @@ private[scala] object ReflectionUtils {
def scalacShouldntLoadClassfile(fileName: String) = isTraitImplementation(fileName)
def scalacShouldntLoadClass(name: scala.reflect.internal.SymbolTable#Name) = scalacShouldntLoadClassfile(name + ".class")
+
+ object PrimitiveOrArray {
+ def unapply(jclazz: jClass[_]) = jclazz.isPrimitive || jclazz.isArray
+ }
+
+ class EnclosedIn[T](enclosure: jClass[_] => T) {
+ def unapply(jclazz: jClass[_]): Option[T] = if (enclosure(jclazz) != null) Some(enclosure(jclazz)) else None
+ }
+
+ object EnclosedInMethod extends EnclosedIn(_.getEnclosingMethod)
+ object EnclosedInConstructor extends EnclosedIn(_.getEnclosingConstructor)
+ object EnclosedInClass extends EnclosedIn(_.getEnclosingClass)
+ object EnclosedInPackage extends EnclosedIn(_.getPackage)
}
+
diff --git a/src/reflect/scala/reflect/runtime/SymbolLoaders.scala b/src/reflect/scala/reflect/runtime/SymbolLoaders.scala
index c6059ac402..30a3855d70 100644
--- a/src/reflect/scala/reflect/runtime/SymbolLoaders.scala
+++ b/src/reflect/scala/reflect/runtime/SymbolLoaders.scala
@@ -97,9 +97,7 @@ private[reflect] trait SymbolLoaders { self: SymbolTable =>
if (isCompilerUniverse) super.enter(sym)
else {
val existing = super.lookupEntry(sym.name)
- // commented out to provide a hotfix for strange class files that javac sometimes emits
- // see more details at: https://groups.google.com/forum/#!topic/scala-internals/hcnUFk75MgQ
- // assert(existing == null || existing.sym.isMethod, s"pkgClass = $pkgClass, sym = $sym, existing = $existing")
+ assert(existing == null || existing.sym.isMethod, s"pkgClass = $pkgClass, sym = $sym, existing = $existing")
super.enter(sym)
}
}