summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2012-07-30 21:14:42 +0200
committerEugene Burmako <xeno.by@gmail.com>2012-08-02 15:50:01 +0200
commit013acf6eb0117ca12ab2a0d0e8560df40a7392a3 (patch)
tree2f69939025e5796381327bd16f602b5be9cfcba4 /src/library
parent367b82de04bdee24b0994e30c1464297eae16d74 (diff)
downloadscala-013acf6eb0117ca12ab2a0d0e8560df40a7392a3.tar.gz
scala-013acf6eb0117ca12ab2a0d0e8560df40a7392a3.tar.bz2
scala-013acf6eb0117ca12ab2a0d0e8560df40a7392a3.zip
renames asType to toType and asXXXSymbol to asXXX
This renaming arguably makes the intent of `asType` more clear, but more importantly it shaves 6 symbols off pervasive casts that are required to anything meaningful with reflection API (as in mirror.reflectMethod(tpe.member(newTermName("x")).asMethodSymbol)).
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/reflect/base/Base.scala12
-rw-r--r--src/library/scala/reflect/base/Symbols.scala54
2 files changed, 43 insertions, 23 deletions
diff --git a/src/library/scala/reflect/base/Base.scala b/src/library/scala/reflect/base/Base.scala
index 6d13395019..385dc6275f 100644
--- a/src/library/scala/reflect/base/Base.scala
+++ b/src/library/scala/reflect/base/Base.scala
@@ -62,7 +62,9 @@ class Base extends Universe { self =>
class TypeSymbol(val owner: Symbol, override val name: TypeName, flags: FlagSet)
extends Symbol(name, flags) with TypeSymbolBase {
- override val asTypeConstructor = TypeRef(ThisType(owner), this, Nil)
+ override def toTypeConstructor = TypeRef(ThisType(owner), this, Nil)
+ override def toType = TypeRef(ThisType(owner), this, Nil)
+ override def toTypeIn(site: Type) = TypeRef(ThisType(owner), this, Nil)
}
implicit val TypeSymbolTag = ClassTag[TypeSymbol](classOf[TypeSymbol])
@@ -295,16 +297,16 @@ class Base extends Universe { self =>
object build extends BuildBase {
def selectType(owner: Symbol, name: String): TypeSymbol = {
val clazz = new ClassSymbol(owner, newTypeName(name), NoFlags)
- cached(clazz.fullName)(clazz).asTypeSymbol
+ cached(clazz.fullName)(clazz).asType
}
def selectTerm(owner: Symbol, name: String): TermSymbol = {
val valu = new MethodSymbol(owner, newTermName(name), NoFlags)
- cached(valu.fullName)(valu).asTermSymbol
+ cached(valu.fullName)(valu).asTerm
}
def selectOverloadedMethod(owner: Symbol, name: String, index: Int): MethodSymbol =
- selectTerm(owner, name).asMethodSymbol
+ selectTerm(owner, name).asMethod
def newNestedSymbol(owner: Symbol, name: Name, pos: Position, flags: Long, isClass: Boolean): Symbol =
if (name.isTypeName)
@@ -384,7 +386,7 @@ class Base extends Universe { self =>
object definitions extends DefinitionsBase {
lazy val ScalaPackage = staticModule("scala")
- lazy val ScalaPackageClass = ScalaPackage.moduleClass.asClassSymbol
+ lazy val ScalaPackageClass = ScalaPackage.moduleClass.asClass
lazy val AnyClass = staticClass("scala.Any")
lazy val AnyValClass = staticClass("scala.Any")
diff --git a/src/library/scala/reflect/base/Symbols.scala b/src/library/scala/reflect/base/Symbols.scala
index ced1f33395..052571dbcb 100644
--- a/src/library/scala/reflect/base/Symbols.scala
+++ b/src/library/scala/reflect/base/Symbols.scala
@@ -134,7 +134,7 @@ trait Symbols { self: Universe =>
/** This symbol cast to a TypeSymbol.
* Returns ClassCastException if `isType` is false.
*/
- def asTypeSymbol: TypeSymbol = throw new ClassCastException(toString)
+ def asType: TypeSymbol = throw new ClassCastException(toString)
/** Does this symbol represent the definition of a term?
* Note that every symbol is either a term or a term.
@@ -146,7 +146,7 @@ trait Symbols { self: Universe =>
/** This symbol cast to a TermSymbol.
* Returns ClassCastException if `isTerm` is false.
*/
- def asTermSymbol: TermSymbol = throw new ClassCastException(toString)
+ def asTerm: TermSymbol = throw new ClassCastException(toString)
/** Does this symbol represent the definition of a method?
* If yes, `isTerm` is also guaranteed to be true.
@@ -156,7 +156,7 @@ trait Symbols { self: Universe =>
/** This symbol cast to a MethodSymbol.
* Returns ClassCastException if `isMethod` is false.
*/
- def asMethodSymbol: MethodSymbol = throw new ClassCastException(toString)
+ def asMethod: MethodSymbol = throw new ClassCastException(toString)
/** Does this symbol represent the definition of a module (i.e. it
* results from an object definition?).
@@ -167,7 +167,7 @@ trait Symbols { self: Universe =>
/** This symbol cast to a ModuleSymbol defined by an object definition.
* Returns ClassCastException if `isModule` is false.
*/
- def asModuleSymbol: ModuleSymbol = throw new ClassCastException(toString)
+ def asModule: ModuleSymbol = throw new ClassCastException(toString)
/** Does this symbol represent the definition of a class or trait?
* If yes, `isType` is also guaranteed to be true.
@@ -183,7 +183,7 @@ trait Symbols { self: Universe =>
/** This symbol cast to a ClassSymbol representing a class or trait.
* Returns ClassCastException if `isClass` is false.
*/
- def asClassSymbol: ClassSymbol = throw new ClassCastException(toString)
+ def asClass: ClassSymbol = throw new ClassCastException(toString)
/** Does this symbol represent a free term captured by reification?
* If yes, `isTerm` is also guaranteed to be true.
@@ -193,7 +193,7 @@ trait Symbols { self: Universe =>
/** This symbol cast to a free term symbol.
* Returns ClassCastException if `isFreeTerm` is false.
*/
- def asFreeTermSymbol: FreeTermSymbol = throw new ClassCastException(toString)
+ def asFreeTerm: FreeTermSymbol = throw new ClassCastException(toString)
/** Does this symbol represent a free type captured by reification?
* If yes, `isType` is also guaranteed to be true.
@@ -203,7 +203,7 @@ trait Symbols { self: Universe =>
/** This symbol cast to a free type symbol.
* Returns ClassCastException if `isFreeType` is false.
*/
- def asFreeTypeSymbol: FreeTypeSymbol = throw new ClassCastException(toString)
+ def asFreeType: FreeTypeSymbol = throw new ClassCastException(toString)
def newTermSymbol(name: TermName, pos: Position = NoPosition, flags: FlagSet = NoFlags): TermSymbol
def newModuleAndClassSymbol(name: Name, pos: Position = NoPosition, flags: FlagSet = NoFlags): (ModuleSymbol, ClassSymbol)
@@ -219,16 +219,34 @@ trait Symbols { self: Universe =>
final type NameType = TypeName
/** The type constructor corresponding to this type symbol.
- * This is different from `asType` in that type parameters
- * are part of results of `asType`, but not of `asTypeConstructor`.
+ * This is different from `toType` in that type parameters
+ * are part of results of `toType`, but not of `toTypeConstructor`.
*
* Example: Given a class declaration `class C[T] { ... } `, that generates a symbol
- * `C`. Then `C.asType` is the type `C[T]`, but `C.asTypeConstructor` is `C`.
+ * `C`. Then `C.toType` is the type `C[T]`, but `C.toTypeConstructor` is `C`.
*/
- def asTypeConstructor: Type
+ def toTypeConstructor: Type
+
+ /** A type reference that refers to this type symbol seen
+ * as a member of given type `site`.
+ */
+ def toTypeIn(site: Type): Type
+
+ /** A type reference that refers to this type symbol
+ * Note if symbol is a member of a class, one almost always is interested
+ * in `asTypeIn` with a site type instead.
+ *
+ * Example: Given a class declaration `class C[T] { ... } `, that generates a symbol
+ * `C`. Then `C.toType` is the type `C[T]`.
+ *
+ * By contrast, `C.typeSignature` would be a type signature of form
+ * `PolyType(ClassInfoType(...))` that describes type parameters, value
+ * parameters, parent types, and members of `C`.
+ */
+ def toType: Type
override def isType = true
- override def asTypeSymbol = this
+ override def asType = this
}
/** The base API that all term symbols support */
@@ -238,13 +256,13 @@ trait Symbols { self: Universe =>
final type NameType = TermName
final override def isTerm = true
- final override def asTermSymbol = this
+ final override def asTerm = this
}
/** The base API that all method symbols support */
trait MethodSymbolBase extends TermSymbolBase { this: MethodSymbol =>
final override def isMethod = true
- final override def asMethodSymbol = this
+ final override def asMethod = this
}
/** The base API that all module symbols support */
@@ -257,24 +275,24 @@ trait Symbols { self: Universe =>
// [Eugene++] when this becomes `moduleClass: ClassSymbol`, it will be the happiest day in my life
final override def isModule = true
- final override def asModuleSymbol = this
+ final override def asModule = this
}
/** The base API that all class symbols support */
trait ClassSymbolBase extends TypeSymbolBase { this: ClassSymbol =>
final override def isClass = true
- final override def asClassSymbol = this
+ final override def asClass = this
}
/** The base API that all free type symbols support */
trait FreeTypeSymbolBase extends TypeSymbolBase { this: FreeTypeSymbol =>
final override def isFreeType = true
- final override def asFreeTypeSymbol = this
+ final override def asFreeType = this
}
/** The base API that all free term symbols support */
trait FreeTermSymbolBase extends TermSymbolBase { this: FreeTermSymbol =>
final override def isFreeTerm = true
- final override def asFreeTermSymbol = this
+ final override def asFreeTerm = this
}
}