diff options
author | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-07-24 05:15:23 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-07-24 05:15:23 -0700 |
commit | 9b6cb872e38d622032e42c55e77389b4d08a6c24 (patch) | |
tree | c6e106efbcbc6376524a013b09afb434d69af17f | |
parent | 84c0aa63d13008bdb0a9ab43064c3281a6f6b006 (diff) | |
parent | f2819ff3796427378c4688e13bc0f4a20b550df9 (diff) | |
download | scala-9b6cb872e38d622032e42c55e77389b4d08a6c24.tar.gz scala-9b6cb872e38d622032e42c55e77389b4d08a6c24.tar.bz2 scala-9b6cb872e38d622032e42c55e77389b4d08a6c24.zip |
Merge pull request #971 from dragos/ide/safe-reflection-base
SI-6122: Small changes to reflection API to make it safe for IDE use.
-rw-r--r-- | src/library/scala/reflect/base/Base.scala | 2 | ||||
-rw-r--r-- | src/library/scala/reflect/base/Types.scala | 17 | ||||
-rw-r--r-- | src/reflect/scala/reflect/api/Types.scala | 9 | ||||
-rw-r--r-- | src/reflect/scala/reflect/internal/Trees.scala | 10 |
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 = { |