diff options
Diffstat (limited to 'src')
21 files changed, 117 insertions, 116 deletions
diff --git a/src/compiler/scala/reflect/makro/runtime/ExprUtils.scala b/src/compiler/scala/reflect/makro/runtime/ExprUtils.scala index e301dfc2a4..c89606289f 100644 --- a/src/compiler/scala/reflect/makro/runtime/ExprUtils.scala +++ b/src/compiler/scala/reflect/makro/runtime/ExprUtils.scala @@ -29,7 +29,7 @@ trait ExprUtils { def literal(x: Double) = Expr[Double](Literal(Constant(x)))(TypeTag.Double) - def literal(x: String) = Expr[String](Literal(Constant(x)))(TypeTag[String](definitions.StringClass.asTypeConstructor)) + def literal(x: String) = Expr[String](Literal(Constant(x)))(TypeTag[String](definitions.StringClass.toTypeConstructor)) def literal(x: Char) = Expr[Char](Literal(Constant(x)))(TypeTag.Char) } diff --git a/src/compiler/scala/reflect/makro/runtime/Typers.scala b/src/compiler/scala/reflect/makro/runtime/Typers.scala index e43b0459ea..7e92c1e9ca 100644 --- a/src/compiler/scala/reflect/makro/runtime/Typers.scala +++ b/src/compiler/scala/reflect/makro/runtime/Typers.scala @@ -37,7 +37,7 @@ trait Typers { def inferImplicitView(tree: Tree, from: Type, to: Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: Position = enclosingPosition): Tree = { macroLogVerbose("inferring implicit view from %s to %s for %s, macros = %s".format(from, to, tree, !withMacrosDisabled)) - val viewTpe = universe.appliedType(universe.definitions.FunctionClass(1).asTypeConstructor, List(from, to)) + val viewTpe = universe.appliedType(universe.definitions.FunctionClass(1).toTypeConstructor, List(from, to)) inferImplicit(tree, viewTpe, isView = true, silent = silent, withMacrosDisabled = withMacrosDisabled, pos = pos) } diff --git a/src/compiler/scala/reflect/reify/codegen/GenSymbols.scala b/src/compiler/scala/reflect/reify/codegen/GenSymbols.scala index 38c8fedac5..59651bcdf9 100644 --- a/src/compiler/scala/reflect/reify/codegen/GenSymbols.scala +++ b/src/compiler/scala/reflect/reify/codegen/GenSymbols.scala @@ -36,7 +36,7 @@ trait GenSymbols { else if (sym.isEmptyPackageClass) mirrorMirrorSelect(nme.EmptyPackageClass) else if (sym.isModuleClass) - Select(Select(reify(sym.sourceModule), nme.asModuleSymbol), nme.moduleClass) + Select(Select(reify(sym.sourceModule), nme.asModule), nme.moduleClass) else if (sym.isPackage) mirrorMirrorCall(nme.staticPackage, reify(sym.fullName)) else if (sym.isLocatable) { diff --git a/src/compiler/scala/reflect/reify/codegen/GenTypes.scala b/src/compiler/scala/reflect/reify/codegen/GenTypes.scala index c49e5b3342..c762a28f99 100644 --- a/src/compiler/scala/reflect/reify/codegen/GenTypes.scala +++ b/src/compiler/scala/reflect/reify/codegen/GenTypes.scala @@ -30,7 +30,7 @@ trait GenTypes { val tsym = tpe.typeSymbolDirect if (tsym.isClass && tpe == tsym.typeConstructor && tsym.isStatic) - Select(Select(reify(tsym), nme.asTypeSymbol), nme.asTypeConstructor) + Select(Select(reify(tsym), nme.asType), nme.toTypeConstructor) else tpe match { case tpe @ NoType => reifyMirrorObject(tpe) @@ -42,7 +42,7 @@ trait GenTypes { mirrorBuildCall(nme.thisPrefix, mirrorMirrorSelect(nme.EmptyPackageClass)) case tpe @ ThisType(clazz) if clazz.isModuleClass && clazz.isStatic => val module = reify(clazz.sourceModule) - val moduleClass = Select(Select(module, nme.asModuleSymbol), nme.moduleClass) + val moduleClass = Select(Select(module, nme.asModule), nme.moduleClass) mirrorFactoryCall(nme.ThisType, moduleClass) case tpe @ ThisType(_) => reifyProduct(tpe) @@ -94,7 +94,7 @@ trait GenTypes { } case success => if (reifyDebug) println("implicit search has produced a result: " + success) - state.reificationIsConcrete &= concrete || success.tpe <:< TypeTagClass.asTypeConstructor + state.reificationIsConcrete &= concrete || success.tpe <:< TypeTagClass.toTypeConstructor Select(Apply(Select(success, nme.in), List(Ident(nme.MIRROR_SHORT))), nme.tpe) } if (result != EmptyTree) return result @@ -109,7 +109,7 @@ trait GenTypes { def searchForManifest(typer: analyzer.Typer): Tree = analyzer.inferImplicit( EmptyTree, - appliedType(FullManifestClass.asTypeConstructor, List(tpe)), + appliedType(FullManifestClass.toTypeConstructor, List(tpe)), reportAmbiguous = false, isView = false, context = typer.context, diff --git a/src/compiler/scala/reflect/reify/package.scala b/src/compiler/scala/reflect/reify/package.scala index 80011368a8..e4cf451643 100644 --- a/src/compiler/scala/reflect/reify/package.scala +++ b/src/compiler/scala/reflect/reify/package.scala @@ -29,7 +29,7 @@ package object reify { import definitions._ val enclosingErasure = reifyEnclosingRuntimeClass(global)(typer0) // JavaUniverse is defined in scala-reflect.jar, so we must be very careful in case someone reifies stuff having only scala-library.jar on the classpath - val isJavaUniverse = JavaUniverseClass != NoSymbol && universe.tpe <:< JavaUniverseClass.asTypeConstructor + val isJavaUniverse = JavaUniverseClass != NoSymbol && universe.tpe <:< JavaUniverseClass.toTypeConstructor if (isJavaUniverse && !enclosingErasure.isEmpty) Apply(Select(universe, nme.runtimeMirror), List(Select(enclosingErasure, sn.GetClassLoader))) else Select(universe, nme.rootMirror) } @@ -69,7 +69,7 @@ package object reify { if (isThisInScope) { val enclosingClasses = typer0.context.enclosingContextChain map (_.tree) collect { case classDef: ClassDef => classDef } val classInScope = enclosingClasses.headOption getOrElse EmptyTree - if (!classInScope.isEmpty) reifyRuntimeClass(global)(typer0, classInScope.symbol.asTypeConstructor, concrete = true) + if (!classInScope.isEmpty) reifyRuntimeClass(global)(typer0, classInScope.symbol.toTypeConstructor, concrete = true) else Select(This(tpnme.EMPTY), sn.GetClass) } else EmptyTree } diff --git a/src/compiler/scala/reflect/reify/utils/Extractors.scala b/src/compiler/scala/reflect/reify/utils/Extractors.scala index 86265ec77a..7352b2cbd5 100644 --- a/src/compiler/scala/reflect/reify/utils/Extractors.scala +++ b/src/compiler/scala/reflect/reify/utils/Extractors.scala @@ -40,7 +40,7 @@ trait Extractors { // def apply[U >: Nothing <: scala.reflect.base.Universe with Singleton]($m$untyped: scala.reflect.base.MirrorOf[U]): U#Type = { // val $u: U = $m$untyped.universe; // val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror]; - // $u.TypeRef($u.ThisType($m.staticPackage("scala.collection.immutable").moduleClass), $m.staticClass("scala.collection.immutable.List"), List($m.staticClass("scala.Int").asTypeConstructor)) + // $u.TypeRef($u.ThisType($m.staticPackage("scala.collection.immutable").moduleClass), $m.staticClass("scala.collection.immutable.List"), List($m.staticClass("scala.Int").toTypeConstructor)) // } // }; // new $typecreator1() diff --git a/src/compiler/scala/tools/nsc/typechecker/Tags.scala b/src/compiler/scala/tools/nsc/typechecker/Tags.scala index 052484e8e1..f82e009be8 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Tags.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Tags.scala @@ -61,7 +61,7 @@ trait Tags { */ def resolveTypeTag(pos: Position, pre: Type, tp: Type, concrete: Boolean, allowMaterialization: Boolean = true): Tree = { val tagSym = if (concrete) TypeTagClass else AbsTypeTagClass - val tagTp = if (pre == NoType) TypeRef(BaseUniverseClass.asTypeConstructor, tagSym, List(tp)) else singleType(pre, pre member tagSym.name) + val tagTp = if (pre == NoType) TypeRef(BaseUniverseClass.toTypeConstructor, tagSym, List(tp)) else singleType(pre, pre member tagSym.name) val taggedTp = appliedType(tagTp, List(tp)) resolveTag(pos, taggedTp, allowMaterialization) } diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index e57cae00e0..b06ea639b0 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -5089,7 +5089,7 @@ trait Typers extends Modes with Adaptations with Tags { // convert new Array^N[T](len) for N > 1 to evidence[ClassTag[Array[...Array[T]...]]].newArray(len), where Array HK gets applied (N-1) times // [Eugene] no more MaxArrayDims. ClassTags are flexible enough to allow creation of arrays of arbitrary dimensionality (w.r.t JVM restrictions) val Some((level, componentType)) = erasure.GenericArray.unapply(tpt.tpe) - val tagType = List.iterate(componentType, level)(tpe => appliedType(ArrayClass.asType, List(tpe))).last + val tagType = List.iterate(componentType, level)(tpe => appliedType(ArrayClass.toTypeConstructor, List(tpe))).last val newArrayApp = atPos(tree.pos) { val tag = resolveClassTag(tree.pos, tagType) if (tag.isEmpty) MissingClassTagError(tree, tagType) diff --git a/src/compiler/scala/tools/reflect/StdTags.scala b/src/compiler/scala/tools/reflect/StdTags.scala index 25a42a82cd..30bded4f86 100644 --- a/src/compiler/scala/tools/reflect/StdTags.scala +++ b/src/compiler/scala/tools/reflect/StdTags.scala @@ -20,7 +20,7 @@ trait StdTags { def apply[U <: BaseUniverse with Singleton](m: MirrorOf[U]): U # Type = { val u = m.universe val pre = u.ThisType(m.staticPackage("scala.collection.immutable").moduleClass.asInstanceOf[u.Symbol]) - u.TypeRef(pre, u.definitions.ListClass, List(u.definitions.StringClass.asTypeConstructor)) + u.TypeRef(pre, u.definitions.ListClass, List(u.definitions.StringClass.toTypeConstructor)) } }) @@ -29,7 +29,7 @@ trait StdTags { m, new TypeCreator { def apply[U <: BaseUniverse with Singleton](m: MirrorOf[U]): U # Type = - m.staticClass(classTag[T].runtimeClass.getName).asTypeConstructor.asInstanceOf[U # Type] + m.staticClass(classTag[T].runtimeClass.getName).toTypeConstructor.asInstanceOf[U # Type] }) lazy val tagOfInt = u.TypeTag.Int lazy val tagOfString = tagOfStaticClass[String] diff --git a/src/compiler/scala/tools/reflect/ToolBoxFactory.scala b/src/compiler/scala/tools/reflect/ToolBoxFactory.scala index 6c48762200..9987931cf3 100644 --- a/src/compiler/scala/tools/reflect/ToolBoxFactory.scala +++ b/src/compiler/scala/tools/reflect/ToolBoxFactory.scala @@ -85,7 +85,7 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf => if (tree.hasSymbol && tree.symbol.isFreeTerm) { tree match { case Ident(_) => - val freeTermRef = Ident(freeTermNames(tree.symbol.asFreeTermSymbol)) + val freeTermRef = Ident(freeTermNames(tree.symbol.asFreeTerm)) if (wrapFreeTermRefs) Apply(freeTermRef, List()) else freeTermRef case _ => throw new Error("internal error: %s (%s, %s) is not supported".format(tree, tree.productPrefix, tree.getClass)) @@ -350,7 +350,7 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf => } def inferImplicitView(tree: u.Tree, from: u.Type, to: u.Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: u.Position = u.NoPosition): u.Tree = { - val viewTpe = u.appliedType(u.definitions.FunctionClass(1).asTypeConstructor, List(from, to)) + val viewTpe = u.appliedType(u.definitions.FunctionClass(1).toTypeConstructor, List(from, to)) inferImplicit(tree, viewTpe, isView = true, silent = silent, withMacrosDisabled = withMacrosDisabled, pos = pos) } 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 } } diff --git a/src/reflect/scala/reflect/api/Mirrors.scala b/src/reflect/scala/reflect/api/Mirrors.scala index fe4348d568..a4d86cf1fd 100644 --- a/src/reflect/scala/reflect/api/Mirrors.scala +++ b/src/reflect/scala/reflect/api/Mirrors.scala @@ -34,7 +34,7 @@ trait Mirrors { self: Universe => * that can be used to get and, if appropriate, set the value of the field. * * To get a field symbol by the name of the field you would like to reflect, - * use `<this mirror>.symbol.typeSignature.member(newTermName(<name of the field>)).asTermSymbol.accessed`. + * use `<this mirror>.symbol.typeSignature.member(newTermName(<name of the field>)).asTerm.accessed`. * For further information about member lookup refer to `Symbol.typeSignature`. * * The input symbol can be either private or non-private (Scala reflection transparently deals with visibility). @@ -54,7 +54,7 @@ trait Mirrors { self: Universe => * that can be used to invoke the method provided. * * To get a method symbol by the name of the method you would like to reflect, - * use `<this mirror>.symbol.typeSignature.member(newTermName(<name of the method>)).asMethodSymbol`. + * use `<this mirror>.symbol.typeSignature.member(newTermName(<name of the method>)).asMethod`. * For further information about member lookup refer to `Symbol.typeSignature`. * * The input symbol can be either private or non-private (Scala reflection transparently deals with visibility). @@ -66,7 +66,7 @@ trait Mirrors { self: Universe => * that can be used to create instances of the class, inspect its companion object or perform further reflections. * * To get a class symbol by the name of the class you would like to reflect, - * use `<this mirror>.symbol.typeSignature.member(newTypeName(<name of the class>)).asClassSymbol`. + * use `<this mirror>.symbol.typeSignature.member(newTypeName(<name of the class>)).asClass`. * For further information about member lookup refer to `Symbol.typeSignature`. * * The input symbol can be either private or non-private (Scala reflection transparently deals with visibility). @@ -78,7 +78,7 @@ trait Mirrors { self: Universe => * that can be used to get the instance of the object or inspect its companion class. * * To get a module symbol by the name of the object you would like to reflect, - * use `<this mirror>.symbol.typeSignature.member(newTermName(<name of the object>)).asModuleSymbol`. + * use `<this mirror>.symbol.typeSignature.member(newTermName(<name of the object>)).asModule`. * For further information about member lookup refer to `Symbol.typeSignature`. * * The input symbol can be either private or non-private (Scala reflection transparently deals with visibility). @@ -201,7 +201,7 @@ trait Mirrors { self: Universe => * that can be used to invoke it and construct instances of this mirror's symbols. * * To get a constructor symbol you would like to reflect, - * use `<this mirror>.symbol.typeSignature.member(nme.CONSTRUCTOR).asMethodSymbol`. + * use `<this mirror>.symbol.typeSignature.member(nme.CONSTRUCTOR).asMethod`. * For further information about member lookup refer to `Symbol.typeSignature`. * * The input symbol can be either private or non-private (Scala reflection transparently deals with visibility). diff --git a/src/reflect/scala/reflect/api/Symbols.scala b/src/reflect/scala/reflect/api/Symbols.scala index cd9044c934..e55c1ea11a 100644 --- a/src/reflect/scala/reflect/api/Symbols.scala +++ b/src/reflect/scala/reflect/api/Symbols.scala @@ -236,24 +236,6 @@ trait Symbols extends base.Symbols { self: Universe => /** Does this symbol represent an existentially bound type? */ def isExistential : Boolean - - /** A type reference that refers to this type symbol seen - * as a member of given type `site`. - */ - def asTypeIn(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.asType` 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 asType: Type // !!! Same as typeSignature. } /** The API of method symbols */ diff --git a/src/reflect/scala/reflect/api/TagInterop.scala b/src/reflect/scala/reflect/api/TagInterop.scala index f1938083b5..4d2254cb9f 100644 --- a/src/reflect/scala/reflect/api/TagInterop.scala +++ b/src/reflect/scala/reflect/api/TagInterop.scala @@ -27,8 +27,8 @@ trait TagInterop { self: JavaUniverse => val jm = mirror.asInstanceOf[ju.Mirror] val sym = jm.classSymbol(manifest.erasure) val tpe = - if (manifest.typeArguments.isEmpty) sym.asType - else ju.appliedType(sym.asTypeConstructor, manifest.typeArguments map (targ => ju.manifestToTypeTag(jm, targ)) map (_.in(jm).tpe)) + if (manifest.typeArguments.isEmpty) sym.toType + else ju.appliedType(sym.toTypeConstructor, manifest.typeArguments map (targ => ju.manifestToTypeTag(jm, targ)) map (_.in(jm).tpe)) tpe.asInstanceOf[U # Type] case u => u.manifestToTypeTag(mirror.asInstanceOf[u.Mirror], manifest).in(mirror).tpe diff --git a/src/reflect/scala/reflect/internal/BuildUtils.scala b/src/reflect/scala/reflect/internal/BuildUtils.scala index ad59605760..74b9442076 100644 --- a/src/reflect/scala/reflect/internal/BuildUtils.scala +++ b/src/reflect/scala/reflect/internal/BuildUtils.scala @@ -8,11 +8,11 @@ trait BuildUtils extends base.BuildUtils { self: SymbolTable => class BuildImpl extends BuildBase { def selectType(owner: Symbol, name: String): TypeSymbol = - select(owner, newTypeName(name)).asTypeSymbol + select(owner, newTypeName(name)).asType def selectTerm(owner: Symbol, name: String): TermSymbol = { - val result = select(owner, newTermName(name)).asTermSymbol - if (result.isOverloaded) result.suchThat(!_.isMethod).asTermSymbol + val result = select(owner, newTermName(name)).asTerm + if (result.isOverloaded) result.suchThat(!_.isMethod).asTerm else result } @@ -26,7 +26,7 @@ trait BuildUtils extends base.BuildUtils { self: SymbolTable => def selectOverloadedMethod(owner: Symbol, name: String, index: Int): MethodSymbol = { val result = owner.info.decl(newTermName(name)).alternatives(index) - if (result ne NoSymbol) result.asMethodSymbol + if (result ne NoSymbol) result.asMethod else MissingRequirementError.notFound("overloaded method %s #%d in %s".format(name, index, owner.fullName)) } diff --git a/src/reflect/scala/reflect/internal/Definitions.scala b/src/reflect/scala/reflect/internal/Definitions.scala index 90aa0b732c..7248fac5fb 100644 --- a/src/reflect/scala/reflect/internal/Definitions.scala +++ b/src/reflect/scala/reflect/internal/Definitions.scala @@ -20,21 +20,21 @@ trait Definitions extends api.StandardDefinitions { object definitions extends DefinitionsClass // [Eugene] find a way to make these non-lazy - lazy val ByteTpe = definitions.ByteClass.asType - lazy val ShortTpe = definitions.ShortClass.asType - lazy val CharTpe = definitions.CharClass.asType - lazy val IntTpe = definitions.IntClass.asType - lazy val LongTpe = definitions.LongClass.asType - lazy val FloatTpe = definitions.FloatClass.asType - lazy val DoubleTpe = definitions.DoubleClass.asType - lazy val BooleanTpe = definitions.BooleanClass.asType - lazy val UnitTpe = definitions.UnitClass.asType - lazy val AnyTpe = definitions.AnyClass.asType - lazy val ObjectTpe = definitions.ObjectClass.asType - lazy val AnyValTpe = definitions.AnyValClass.asType - lazy val AnyRefTpe = definitions.AnyRefClass.asType - lazy val NothingTpe = definitions.NothingClass.asType - lazy val NullTpe = definitions.NullClass.asType + lazy val ByteTpe = definitions.ByteClass.toTypeConstructor + lazy val ShortTpe = definitions.ShortClass.toTypeConstructor + lazy val CharTpe = definitions.CharClass.toTypeConstructor + lazy val IntTpe = definitions.IntClass.toTypeConstructor + lazy val LongTpe = definitions.LongClass.toTypeConstructor + lazy val FloatTpe = definitions.FloatClass.toTypeConstructor + lazy val DoubleTpe = definitions.DoubleClass.toTypeConstructor + lazy val BooleanTpe = definitions.BooleanClass.toTypeConstructor + lazy val UnitTpe = definitions.UnitClass.toTypeConstructor + lazy val AnyTpe = definitions.AnyClass.toTypeConstructor + lazy val ObjectTpe = definitions.ObjectClass.toTypeConstructor + lazy val AnyValTpe = definitions.AnyValClass.toTypeConstructor + lazy val AnyRefTpe = definitions.AnyRefClass.toTypeConstructor + lazy val NothingTpe = definitions.NothingClass.toTypeConstructor + lazy val NullTpe = definitions.NullClass.toTypeConstructor /** Since both the value parameter types and the result type may * require access to the type parameter symbols, we model polymorphic @@ -183,11 +183,11 @@ trait Definitions extends api.StandardDefinitions { // It becomes tricky to create dedicated objects for other symbols because // of initialization order issues. lazy val JavaLangPackage = getRequiredPackage(sn.JavaLang) - lazy val JavaLangPackageClass = JavaLangPackage.moduleClass.asClassSymbol + lazy val JavaLangPackageClass = JavaLangPackage.moduleClass.asClass lazy val ScalaPackage = getRequiredPackage(nme.scala_) - lazy val ScalaPackageClass = ScalaPackage.moduleClass.asClassSymbol + lazy val ScalaPackageClass = ScalaPackage.moduleClass.asClass lazy val RuntimePackage = getRequiredPackage("scala.runtime") - lazy val RuntimePackageClass = RuntimePackage.moduleClass.asClassSymbol + lazy val RuntimePackageClass = RuntimePackage.moduleClass.asClass lazy val JavaLangEnumClass = requiredClass[java.lang.Enum[_]] @@ -1045,7 +1045,7 @@ trait Definitions extends api.StandardDefinitions { // System.err.println("isMethod = " + result.isMethod) // System.err.println("isTerm = " + result.isTerm) // System.err.println("isValue = " + result.isValue) - // result.asMethodSymbol + // result.asMethod // // prints this: // @@ -1074,8 +1074,8 @@ trait Definitions extends api.StandardDefinitions { // [scalacfork] // [scalacfork] uncaught exception during compilation: java.lang.ClassCastException // [scalacfork] error: java.lang.ClassCastException: value apply - // [scalacfork] at scala.reflect.base.Symbols$SymbolBase$class.asMethodSymbol(Symbols.scala:118) - // [scalacfork] at scala.reflect.internal.Symbols$SymbolContextApiImpl.asMethodSymbol(Symbols.scala:63) + // [scalacfork] at scala.reflect.base.Symbols$SymbolBase$class.asMethod(Symbols.scala:118) + // [scalacfork] at scala.reflect.internal.Symbols$SymbolContextApiImpl.asMethod(Symbols.scala:63) // [scalacfork] at scala.reflect.internal.Definitions$DefinitionsClass.Symbol_apply(Definitions.scala:381) // [Eugene++] should be a ClassCastException instead? diff --git a/src/reflect/scala/reflect/internal/StdNames.scala b/src/reflect/scala/reflect/internal/StdNames.scala index 75962ff9d0..133b035228 100644 --- a/src/reflect/scala/reflect/internal/StdNames.scala +++ b/src/reflect/scala/reflect/internal/StdNames.scala @@ -628,14 +628,13 @@ trait StdNames { val array_length : NameType = "array_length" val array_update : NameType = "array_update" val arraycopy: NameType = "arraycopy" - val asTermSymbol: NameType = "asTermSymbol" - val asModuleSymbol: NameType = "asModuleSymbol" - val asMethodSymbol: NameType = "asMethodSymbol" - val asTypeSymbol: NameType = "asTypeSymbol" - val asClassSymbol: NameType = "asClassSymbol" + val asTerm: NameType = "asTerm" + val asModule: NameType = "asModule" + val asMethod: NameType = "asMethod" + val asType: NameType = "asType" + val asClass: NameType = "asClass" val asInstanceOf_ : NameType = "asInstanceOf" val asInstanceOf_Ob : NameType = "$asInstanceOf" - val asTypeConstructor: NameType = "asTypeConstructor" val assert_ : NameType = "assert" val assume_ : NameType = "assume" val basis : NameType = "basis" @@ -767,6 +766,7 @@ trait StdNames { val toObjectArray : NameType = "toObjectArray" val toSeq: NameType = "toSeq" val toString_ : NameType = if (forMSIL) "ToString" else "toString" + val toTypeConstructor: NameType = "toTypeConstructor" val tpe : NameType = "tpe" val tree : NameType = "tree" val true_ : NameType = "true" diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala index 68144da2d7..372520e48f 100644 --- a/src/reflect/scala/reflect/internal/Symbols.scala +++ b/src/reflect/scala/reflect/internal/Symbols.scala @@ -75,9 +75,9 @@ trait Symbols extends api.Symbols { self: SymbolTable => def typeSignature: Type = info def typeSignatureIn(site: Type): Type = site memberInfo this - def asType: Type = tpe - def asTypeIn(site: Type): Type = site.memberType(this) - def asTypeConstructor: Type = typeConstructor + def toType: Type = tpe + def toTypeIn(site: Type): Type = site.memberType(this) + def toTypeConstructor: Type = typeConstructor def setFlags(flags: FlagSet): this.type = setInternalFlags(flags) def setInternalFlags(flag: Long): this.type = { setFlag(flag); this } def setTypeSignature(tpe: Type): this.type = { setInfo(tpe); this } diff --git a/src/reflect/scala/reflect/internal/Trees.scala b/src/reflect/scala/reflect/internal/Trees.scala index 619e3bc170..ddc40b2e9f 100644 --- a/src/reflect/scala/reflect/internal/Trees.scala +++ b/src/reflect/scala/reflect/internal/Trees.scala @@ -1024,14 +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 = { @@ -1266,7 +1266,7 @@ trait Trees extends api.Trees { self: SymbolTable => } } - private def mclass(sym: Symbol) = sym map (_.asModuleSymbol.moduleClass) + private def mclass(sym: Symbol) = sym map (_.asModule.moduleClass) // --- specific traversers and transformers diff --git a/src/reflect/scala/reflect/runtime/JavaMirrors.scala b/src/reflect/scala/reflect/runtime/JavaMirrors.scala index 0878801715..6ae7e6d7eb 100644 --- a/src/reflect/scala/reflect/runtime/JavaMirrors.scala +++ b/src/reflect/scala/reflect/runtime/JavaMirrors.scala @@ -150,7 +150,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym def classSymbol(rtcls: RuntimeClass): ClassSymbol = classToScala(rtcls) - def moduleSymbol(rtcls: RuntimeClass): ModuleSymbol = classToScala(rtcls).companionModule.asModuleSymbol + def moduleSymbol(rtcls: RuntimeClass): ModuleSymbol = classToScala(rtcls).companionModule.asModule private def checkMemberOf(wannabe: Symbol, owner: Symbol) = if (!owner.info.member(wannabe.name).alternatives.contains(wannabe)) ErrorNotMember(wannabe, owner) @@ -166,7 +166,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym if (field.isGetter) nme.getterToLocal(field.name) else if (field.isSetter) nme.getterToLocal(nme.setterToGetter(field.name)) else field.name - val field1 = (field.owner.info decl name).asTermSymbol + val field1 = (field.owner.info decl name).asTerm try fieldToJava(field1) catch { case _: NoSuchFieldException => ErrorNonExistentField(field1) @@ -260,7 +260,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym private class JavaModuleMirror(val outer: AnyRef, val symbol: ModuleSymbol) extends JavaTemplateMirror with ModuleMirror { - def erasure = symbol.moduleClass.asClassSymbol + def erasure = symbol.moduleClass.asClass def isStatic = true def instance = { if (!symbol.owner.isPackageClass) throw new Error("inner and nested modules are not supported yet") @@ -629,7 +629,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym val preOwner = classToScala(jOwner) val owner = followStatic(preOwner, jmeth.getModifiers) (lookup(owner, jmeth.getName) suchThat (erasesTo(_, jmeth)) orElse jmethodAsScala(jmeth)) - .asMethodSymbol + .asMethod } /** @@ -643,7 +643,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym private def constructorToScala1(jconstr: jConstructor[_]): MethodSymbol = { val owner = followStatic(classToScala(jconstr.getDeclaringClass), jconstr.getModifiers) (lookup(owner, jconstr.getName) suchThat (erasesTo(_, jconstr)) orElse jconstrAsScala(jconstr)) - .asMethodSymbol + .asMethod } /** @@ -657,8 +657,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym private def fieldToScala1(jfield: jField): TermSymbol = { val owner = followStatic(classToScala(jfield.getDeclaringClass), jfield.getModifiers) - (lookup(owner, jfield.getName) suchThat (!_.isMethod) orElse jfieldAsScala(jfield)) - .asTermSymbol + (lookup(owner, jfield.getName) suchThat (!_.isMethod) orElse jfieldAsScala(jfield)).asTerm } /** @@ -691,7 +690,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym val name = (fullname: TermName) drop split + 1 val opkg = owner.info decl name if (opkg.isPackage) - opkg.asModuleSymbol + opkg.asModule else if (opkg == NoSymbol) { val pkg = owner.newPackage(name) pkg.moduleClass setInfo new LazyPackageType @@ -758,7 +757,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym s"""${if (cls == NoSymbol) "not a type: symbol" else "no symbol could be"} | loaded from $jclazz in $owner with name $simpleName and classloader $classLoader""".stripMargin) - cls.asClassSymbol + cls.asClass } } @@ -773,7 +772,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym private def typeParamToScala1(jparam: jTypeVariable[_ <: GenericDeclaration]): TypeSymbol = { val owner = genericDeclarationToScala(jparam.getGenericDeclaration) owner.info match { - case PolyType(tparams, _) => tparams.find(_.name.toString == jparam.getName).get.asTypeSymbol + case PolyType(tparams, _) => tparams.find(_.name.toString == jparam.getName).get.asType } } @@ -941,7 +940,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym else if (clazz.owner.isPackageClass) javaClass(clazz.javaClassName) else if (clazz.owner.isClass) - classToJava(clazz.owner.asClassSymbol) + classToJava(clazz.owner.asClass) .getDeclaredClasses .find(_.getSimpleName == clazz.name.toString) .getOrElse(noClass) @@ -957,7 +956,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym * @param meth The Scala field. */ def fieldToJava(fld: TermSymbol): jField = fieldCache.toJava(fld) { - val jclazz = classToJava(fld.owner.asClassSymbol) + val jclazz = classToJava(fld.owner.asClass) val jname = nme.dropLocalSuffix(fld.name).toString try jclazz getDeclaredField jname catch { @@ -969,7 +968,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym * @param meth The Scala method */ def methodToJava(meth: MethodSymbol): jMethod = methodCache.toJava(meth) { - val jclazz = classToJava(meth.owner.asClassSymbol) + val jclazz = classToJava(meth.owner.asClass) val paramClasses = transformedType(meth).paramTypes map typeToJavaClass val jname = nme.dropLocalSuffix(meth.name).toString try jclazz getDeclaredMethod (jname, paramClasses: _*) @@ -983,7 +982,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym * @param constr The Scala constructor */ def constructorToJava(constr: MethodSymbol): jConstructor[_] = constructorCache.toJava(constr) { - val jclazz = classToJava(constr.owner.asClassSymbol) + val jclazz = classToJava(constr.owner.asClass) val paramClasses = transformedType(constr).paramTypes map typeToJavaClass val effectiveParamClasses = if (!constr.owner.owner.isStaticOwner) jclazz.getEnclosingClass +: paramClasses @@ -1001,7 +1000,7 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { self: Sym def typeToJavaClass(tpe: Type): jClass[_] = tpe match { case ExistentialType(_, rtpe) => typeToJavaClass(rtpe) case TypeRef(_, ArrayClass, List(elemtpe)) => jArrayClass(typeToJavaClass(elemtpe)) - case TypeRef(_, sym: ClassSymbol, _) => classToJava(sym.asClassSymbol) + case TypeRef(_, sym: ClassSymbol, _) => classToJava(sym.asClass) case tpe @ TypeRef(_, sym: AliasTypeSymbol, _) => typeToJavaClass(tpe.dealias) case _ => throw new NoClassDefFoundError("no Java class corresponding to "+tpe+" found") } |