summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIulian Dragos <jaguarul@gmail.com>2012-07-21 15:02:40 +0200
committerIulian Dragos <jaguarul@gmail.com>2012-07-23 17:02:03 +0200
commitf2819ff3796427378c4688e13bc0f4a20b550df9 (patch)
treee458ca024c35f147bddb24bd6559da1a1de269a5
parent40ddd083592ba3947cb5182d6db26798bad9a9cb (diff)
downloadscala-f2819ff3796427378c4688e13bc0f4a20b550df9.tar.gz
scala-f2819ff3796427378c4688e13bc0f4a20b550df9.tar.bz2
scala-f2819ff3796427378c4688e13bc0f4a20b550df9.zip
Small changes to reflection API to make it safe for IDE use.
* Removed `typeSymbol` and `termSymbol` from `reflect.api.base`, and pushed them down to `reflect.api`. * extracted `TypeTree.symbol` to a top-level method so it can be overridden in other layers
-rw-r--r--src/library/scala/reflect/base/Base.scala2
-rw-r--r--src/library/scala/reflect/base/Types.scala17
-rw-r--r--src/reflect/scala/reflect/api/Types.scala9
-rw-r--r--src/reflect/scala/reflect/internal/Trees.scala10
4 files changed, 22 insertions, 16 deletions
diff --git a/src/library/scala/reflect/base/Base.scala b/src/library/scala/reflect/base/Base.scala
index 4457a6cf14..5df48307fe 100644
--- a/src/library/scala/reflect/base/Base.scala
+++ b/src/library/scala/reflect/base/Base.scala
@@ -96,8 +96,8 @@ class Base extends Universe { self =>
// todo. write a decent toString that doesn't crash on recursive types
class Type extends TypeBase {
- def typeSymbol: Symbol = NoSymbol
def termSymbol: Symbol = NoSymbol
+ def typeSymbol: Symbol = NoSymbol
}
implicit val TypeTagg = ClassTag[Type](classOf[Type])
diff --git a/src/library/scala/reflect/base/Types.scala b/src/library/scala/reflect/base/Types.scala
index 6e8ffc7984..28aaf2d04d 100644
--- a/src/library/scala/reflect/base/Types.scala
+++ b/src/library/scala/reflect/base/Types.scala
@@ -3,25 +3,14 @@ package base
trait Types { self: Universe =>
- /** The base API that all types support */
- abstract class TypeBase {
-
- /** The term symbol associated with the type, or `NoSymbol` for types
- * that do not refer to a term symbol.
- */
- def termSymbol: Symbol
-
- /** The type symbol associated with the type, or `NoSymbol` for types
- * that do not refer to a type symbol.
- */
- def typeSymbol: Symbol
- }
-
/** The type of Scala types, and also Scala type signatures.
* (No difference is internally made between the two).
*/
type Type >: Null <: TypeBase
+ /** The base API that all types support */
+ abstract class TypeBase
+
/** A tag that preserves the identity of the `Type` abstract type from erasure.
* Can be used for pattern matching, instance tests, serialization and likes.
*/
diff --git a/src/reflect/scala/reflect/api/Types.scala b/src/reflect/scala/reflect/api/Types.scala
index 231b9b248b..01de5fa9a7 100644
--- a/src/reflect/scala/reflect/api/Types.scala
+++ b/src/reflect/scala/reflect/api/Types.scala
@@ -8,6 +8,15 @@ trait Types extends base.Types { self: Universe =>
/** The extended API of types
*/
abstract class TypeApi extends TypeBase {
+ /** The term symbol associated with the type, or `NoSymbol` for types
+ * that do not refer to a term symbol.
+ */
+ def termSymbol: Symbol
+
+ /** The type symbol associated with the type, or `NoSymbol` for types
+ * that do not refer to a type symbol.
+ */
+ def typeSymbol: Symbol
/** The defined or declared members with name `name` in this type;
* an OverloadedSymbol if several exist, NoSymbol if none exist.
diff --git a/src/reflect/scala/reflect/internal/Trees.scala b/src/reflect/scala/reflect/internal/Trees.scala
index e92d644f4a..619e3bc170 100644
--- a/src/reflect/scala/reflect/internal/Trees.scala
+++ b/src/reflect/scala/reflect/internal/Trees.scala
@@ -469,7 +469,7 @@ trait Trees extends api.Trees { self: SymbolTable =>
private var orig: Tree = null
private[scala] var wasEmpty: Boolean = false
- override def symbol = if (tpe == null) null else tpe.typeSymbol
+ override def symbol = typeTreeSymbol(this) // if (tpe == null) null else tpe.typeSymbol
override def isEmpty = (tpe eq null) || tpe == NoType
def original: Tree = orig
@@ -1024,6 +1024,14 @@ trait Trees extends api.Trees { self: SymbolTable =>
}
}
+
+ /** Delegate for a TypeTree symbol. This operation is unsafe because
+ * it may trigger type checking when forcing the type symbol of the
+ * underlying type.
+ */
+ protected def typeTreeSymbol(tree: TypeTree): Symbol =
+ if (tree.tpe == null) null else tree.tpe.typeSymbol
+
// --- generic traversers and transformers
override protected def itraverse(traverser: Traverser, tree: Tree): Unit = {