diff options
author | Paul Phillips <paulp@improving.org> | 2012-04-18 05:58:37 +0100 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-04-18 05:58:37 +0100 |
commit | adf53b66f7f30da72e990ba544e19484b6578f43 (patch) | |
tree | 4c83dd9f758cc796688c93584193fd485e70f6b8 /src/library | |
parent | 80aaed000d877010bed54be76155e9034d9531b5 (diff) | |
parent | 745fe4e36631f86665eb1bef9cb22e6623894a56 (diff) | |
download | scala-adf53b66f7f30da72e990ba544e19484b6578f43.tar.gz scala-adf53b66f7f30da72e990ba544e19484b6578f43.tar.bz2 scala-adf53b66f7f30da72e990ba544e19484b6578f43.zip |
Merge commit 'refs/pull/412/head'; commit 'refs/pull/413/head' into develop
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/reflect/ClassTag.scala | 139 | ||||
-rw-r--r-- | src/library/scala/reflect/DummyMirror.scala | 740 | ||||
-rw-r--r-- | src/library/scala/reflect/DynamicProxy.scala | 20 | ||||
-rw-r--r-- | src/library/scala/reflect/TagMaterialization.scala | 49 | ||||
-rw-r--r-- | src/library/scala/reflect/api/Attachment.scala | 9 | ||||
-rwxr-xr-x | src/library/scala/reflect/api/Symbols.scala | 10 | ||||
-rw-r--r-- | src/library/scala/reflect/api/TreeBuildUtil.scala | 20 | ||||
-rw-r--r-- | src/library/scala/reflect/api/Trees.scala | 43 | ||||
-rw-r--r-- | src/library/scala/reflect/api/TypeTags.scala | 108 | ||||
-rwxr-xr-x | src/library/scala/reflect/api/Types.scala | 14 | ||||
-rw-r--r-- | src/library/scala/reflect/makro/Reifiers.scala | 4 | ||||
-rw-r--r-- | src/library/scala/reflect/makro/internal/Utils.scala | 45 | ||||
-rw-r--r-- | src/library/scala/reflect/package.scala | 61 |
13 files changed, 1031 insertions, 231 deletions
diff --git a/src/library/scala/reflect/ClassTag.scala b/src/library/scala/reflect/ClassTag.scala index 7138837f0d..06960a5478 100644 --- a/src/library/scala/reflect/ClassTag.scala +++ b/src/library/scala/reflect/ClassTag.scala @@ -117,52 +117,101 @@ object ClassTag { case _ => apply[T](rm.typeToClass(tpe.erasure)) } - implicit def toDeprecatedClassManifestApis[T](ctag: ClassTag[T]): DeprecatedClassManifestApis[T] = new DeprecatedClassManifestApis[T](ctag) -} - -// this class should not be used directly in client code -class DeprecatedClassManifestApis[T](ctag: ClassTag[T]) { - import scala.collection.mutable.{ WrappedArray, ArrayBuilder } - - @deprecated("Use `tpe` to analyze the underlying type", "2.10.0") - def <:<(that: ClassManifest[_]): Boolean = ctag.tpe <:< that.tpe - - @deprecated("Use `tpe` to analyze the underlying type", "2.10.0") - def >:>(that: ClassManifest[_]): Boolean = that <:< ctag - - @deprecated("Use `wrap` instead", "2.10.0") - def arrayManifest: ClassManifest[Array[T]] = ctag.wrap - - @deprecated("Use a combination of `wrap` and `newArray` instead", "2.10.0") - def newArray2(len: Int): Array[Array[T]] = ctag.wrap.newArray(len) - - @deprecated("Use a combination of `wrap` and `newArray` instead", "2.10.0") - def newArray3(len: Int): Array[Array[Array[T]]] = ctag.wrap.wrap.newArray(len) + def apply[T](ttag: rm.ConcreteTypeTag[T]): ClassTag[T] = + if (ttag.erasure != null) ClassTag[T](ttag.erasure) + else ClassTag[T](ttag.tpe) - @deprecated("Use a combination of `wrap` and `newArray` instead", "2.10.0") - def newArray4(len: Int): Array[Array[Array[Array[T]]]] = ctag.wrap.wrap.wrap.newArray(len) - - @deprecated("Use a combination of `wrap` and `newArray` instead", "2.10.0") - def newArray5(len: Int): Array[Array[Array[Array[Array[T]]]]] = ctag.wrap.wrap.wrap.wrap.newArray(len) - - @deprecated("Use `@scala.collection.mutable.WrappedArray` object instead", "2.10.0") - def newWrappedArray(len: Int): WrappedArray[T] = - ctag.erasure match { - case java.lang.Byte.TYPE => new WrappedArray.ofByte(new Array[Byte](len)).asInstanceOf[WrappedArray[T]] - case java.lang.Short.TYPE => new WrappedArray.ofShort(new Array[Short](len)).asInstanceOf[WrappedArray[T]] - case java.lang.Character.TYPE => new WrappedArray.ofChar(new Array[Char](len)).asInstanceOf[WrappedArray[T]] - case java.lang.Integer.TYPE => new WrappedArray.ofInt(new Array[Int](len)).asInstanceOf[WrappedArray[T]] - case java.lang.Long.TYPE => new WrappedArray.ofLong(new Array[Long](len)).asInstanceOf[WrappedArray[T]] - case java.lang.Float.TYPE => new WrappedArray.ofFloat(new Array[Float](len)).asInstanceOf[WrappedArray[T]] - case java.lang.Double.TYPE => new WrappedArray.ofDouble(new Array[Double](len)).asInstanceOf[WrappedArray[T]] - case java.lang.Boolean.TYPE => new WrappedArray.ofBoolean(new Array[Boolean](len)).asInstanceOf[WrappedArray[T]] - case java.lang.Void.TYPE => new WrappedArray.ofUnit(new Array[Unit](len)).asInstanceOf[WrappedArray[T]] - case _ => new WrappedArray.ofRef[T with AnyRef](ctag.newArray(len).asInstanceOf[Array[T with AnyRef]]).asInstanceOf[WrappedArray[T]] - } + implicit def toDeprecatedClassManifestApis[T](ctag: ClassTag[T]): DeprecatedClassManifestApis[T] = new DeprecatedClassManifestApis[T](ctag) - @deprecated("Use `@scala.collection.mutable.ArrayBuilder` object instead", "2.10.0") - def newArrayBuilder(): ArrayBuilder[T] = ArrayBuilder.make[T]()(ctag) + /** Manifest for the singleton type `value.type'. */ + @deprecated("Manifests aka type tags now support arbitrary types. Build a manifest directly from the type instead", "2.10.0") + def singleType[T <: AnyRef](value: AnyRef): Manifest[T] = ??? + + /** ClassManifest for the class type `clazz', where `clazz' is + * a top-level or static class. + * @note This no-prefix, no-arguments case is separate because we + * it's called from ScalaRunTime.boxArray itself. If we + * pass varargs as arrays into this, we get an infinitely recursive call + * to boxArray. (Besides, having a separate case is more efficient) + */ + @deprecated("Manifests aka type tags now support arbitrary types. Build a manifest directly from the type instead", "2.10.0") + def classType[T <: AnyRef](clazz: jClass[_]): ClassManifest[T] = ClassTag[T](clazz) + + /** ClassManifest for the class type `clazz[args]', where `clazz' is + * a top-level or static class and `args` are its type arguments */ + @deprecated("Manifests aka type tags now support arbitrary types. Build a manifest directly from the type instead", "2.10.0") + def classType[T <: AnyRef](clazz: jClass[_], arg1: OptManifest[_], args: OptManifest[_]*): ClassManifest[T] = ClassTag[T](clazz) + + /** ClassManifest for the class type `clazz[args]', where `clazz' is + * a class with non-package prefix type `prefix` and type arguments `args`. + */ + @deprecated("Manifests aka type tags now support arbitrary types. Build a manifest directly from the type instead", "2.10.0") + def classType[T <: AnyRef](prefix: OptManifest[_], clazz: jClass[_], args: OptManifest[_]*): ClassManifest[T] = ClassTag[T](clazz) + + @deprecated("Manifests aka type tags now support arbitrary types. Build a manifest directly from the type instead", "2.10.0") + def arrayType[T](arg: OptManifest[_]): ClassManifest[Array[T]] = arg match { + case x: ConcreteTypeTag[_] => ClassManifest[Array[T]](x.erasure) + case _ => Object.asInstanceOf[ClassManifest[Array[T]]] // was there in 2.9.x + } - @deprecated("`typeArguments` is no longer supported, and will always return an empty list. Use `@scala.reflect.TypeTag` or `@scala.reflect.ConcreteTypeTag` to capture and analyze type arguments", "2.10.0") - def typeArguments: List[OptManifest[_]] = List() + /** ClassManifest for the abstract type `prefix # name'. `upperBound' is not + * strictly necessary as it could be obtained by reflection. It was + * added so that erasure can be calculated without reflection. */ + @deprecated("Manifests aka type tags now support arbitrary types. Build a manifest directly from the type instead", "2.10.0") + def abstractType[T](prefix: OptManifest[_], name: String, clazz: jClass[_], args: OptManifest[_]*): ClassManifest[T] = ClassTag[T](clazz) + + /** ClassManifest for the abstract type `prefix # name'. `upperBound' is not + * strictly necessary as it could be obtained by reflection. It was + * added so that erasure can be calculated without reflection. + * todo: remove after next boostrap + */ + @deprecated("Manifests aka type tags now support arbitrary types. Build a manifest directly from the type instead", "2.10.0") + def abstractType[T](prefix: OptManifest[_], name: String, upperbound: ClassManifest[_], args: OptManifest[_]*): ClassManifest[T] = ClassTag[T](upperbound.erasure) + + class DeprecatedClassManifestApis[T](ctag: ClassTag[T]) { + import scala.collection.mutable.{ WrappedArray, ArrayBuilder } + + @deprecated("Use `tpe` to analyze the underlying type", "2.10.0") + def <:<(that: ClassManifest[_]): Boolean = ctag.tpe <:< that.tpe + + @deprecated("Use `tpe` to analyze the underlying type", "2.10.0") + def >:>(that: ClassManifest[_]): Boolean = that <:< ctag + + @deprecated("Use `wrap` instead", "2.10.0") + def arrayManifest: ClassManifest[Array[T]] = ctag.wrap + + @deprecated("Use a combination of `wrap` and `newArray` instead", "2.10.0") + def newArray2(len: Int): Array[Array[T]] = ctag.wrap.newArray(len) + + @deprecated("Use a combination of `wrap` and `newArray` instead", "2.10.0") + def newArray3(len: Int): Array[Array[Array[T]]] = ctag.wrap.wrap.newArray(len) + + @deprecated("Use a combination of `wrap` and `newArray` instead", "2.10.0") + def newArray4(len: Int): Array[Array[Array[Array[T]]]] = ctag.wrap.wrap.wrap.newArray(len) + + @deprecated("Use a combination of `wrap` and `newArray` instead", "2.10.0") + def newArray5(len: Int): Array[Array[Array[Array[Array[T]]]]] = ctag.wrap.wrap.wrap.wrap.newArray(len) + + @deprecated("Use `@scala.collection.mutable.WrappedArray` object instead", "2.10.0") + def newWrappedArray(len: Int): WrappedArray[T] = + ctag.erasure match { + case java.lang.Byte.TYPE => new WrappedArray.ofByte(new Array[Byte](len)).asInstanceOf[WrappedArray[T]] + case java.lang.Short.TYPE => new WrappedArray.ofShort(new Array[Short](len)).asInstanceOf[WrappedArray[T]] + case java.lang.Character.TYPE => new WrappedArray.ofChar(new Array[Char](len)).asInstanceOf[WrappedArray[T]] + case java.lang.Integer.TYPE => new WrappedArray.ofInt(new Array[Int](len)).asInstanceOf[WrappedArray[T]] + case java.lang.Long.TYPE => new WrappedArray.ofLong(new Array[Long](len)).asInstanceOf[WrappedArray[T]] + case java.lang.Float.TYPE => new WrappedArray.ofFloat(new Array[Float](len)).asInstanceOf[WrappedArray[T]] + case java.lang.Double.TYPE => new WrappedArray.ofDouble(new Array[Double](len)).asInstanceOf[WrappedArray[T]] + case java.lang.Boolean.TYPE => new WrappedArray.ofBoolean(new Array[Boolean](len)).asInstanceOf[WrappedArray[T]] + case java.lang.Void.TYPE => new WrappedArray.ofUnit(new Array[Unit](len)).asInstanceOf[WrappedArray[T]] + case _ => new WrappedArray.ofRef[T with AnyRef](ctag.newArray(len).asInstanceOf[Array[T with AnyRef]]).asInstanceOf[WrappedArray[T]] + } + + @deprecated("Use `@scala.collection.mutable.ArrayBuilder` object instead", "2.10.0") + def newArrayBuilder(): ArrayBuilder[T] = ArrayBuilder.make[T]()(ctag) + + @deprecated("`typeArguments` is no longer supported, and will always return an empty list. Use `@scala.reflect.TypeTag` or `@scala.reflect.ConcreteTypeTag` to capture and analyze type arguments", "2.10.0") + def typeArguments: List[OptManifest[_]] = List() + } } + diff --git a/src/library/scala/reflect/DummyMirror.scala b/src/library/scala/reflect/DummyMirror.scala new file mode 100644 index 0000000000..1fbf36be9d --- /dev/null +++ b/src/library/scala/reflect/DummyMirror.scala @@ -0,0 +1,740 @@ +package scala.reflect + +import scala.reflect.api.AbsTreeGen +import scala.reflect.api.Attachment +import scala.reflect.api.Modifier +import scala.reflect.api.Universe + +class DummyMirror(cl: ClassLoader) extends api.Mirror { + // Members declared in scala.reflect.api.AnnotationInfos + implicit def classfileAnnotArgManifest: scala.reflect.ClassManifest[ClassfileAnnotArg] = notSupported() + type AnnotationInfo = DummyAnnotationInfo.type + object DummyAnnotationInfo + val AnnotationInfo: AnnotationInfoExtractor = DummyAnnotationInfoExtractor + object DummyAnnotationInfoExtractor extends AnnotationInfoExtractor { + def apply(atp: Type, args: List[Tree], assocs: List[(Name, ClassfileAnnotArg)]): AnnotationInfo = DummyAnnotationInfo + def unapply(info: AnnotationInfo): Option[(Type, List[Tree], List[(Name, ClassfileAnnotArg)])] = notSupported() + } + type ClassfileAnnotArg = AnyRef + type LiteralAnnotArg = DummyLiteralAnnotArg.type + object DummyLiteralAnnotArg + val LiteralAnnotArg: LiteralAnnotArgExtractor = DummyLiteralAnnotArgExtractor + type ArrayAnnotArg = DummyArrayAnnotArg.type + object DummyArrayAnnotArg + val ArrayAnnotArg: ArrayAnnotArgExtractor = DummyArrayAnnotArgExtractor + type NestedAnnotArg = DummyNestedAnnotArg.type + object DummyNestedAnnotArg + val NestedAnnotArg: NestedAnnotArgExtractor = DummyNestedAnnotArgExtractor + object DummyLiteralAnnotArgExtractor extends LiteralAnnotArgExtractor { + def apply(const: Constant): LiteralAnnotArg = DummyLiteralAnnotArg + def unapply(arg: LiteralAnnotArg): Option[Constant] = notSupported() + } + object DummyArrayAnnotArgExtractor extends ArrayAnnotArgExtractor { + def apply(const: Array[ClassfileAnnotArg]): ArrayAnnotArg = DummyArrayAnnotArg + def unapply(arg: ArrayAnnotArg): Option[Array[ClassfileAnnotArg]] = notSupported() + } + object DummyNestedAnnotArgExtractor extends NestedAnnotArgExtractor { + def apply(anninfo: AnnotationInfo): NestedAnnotArg = DummyNestedAnnotArg + def unapply(arg: NestedAnnotArg): Option[AnnotationInfo] = notSupported() + } + + // Members declared in scala.reflect.api.Constants + type Constant = DummyConstant.type + object DummyConstant extends AbsConstant { + val value: Any = notSupported() + def tpe: Type = notSupported() + def isNaN: Boolean = notSupported() + def booleanValue: Boolean = notSupported() + def byteValue: Byte = notSupported() + def shortValue: Short = notSupported() + def charValue: Char = notSupported() + def intValue: Int = notSupported() + def longValue: Long = notSupported() + def floatValue: Float = notSupported() + def doubleValue: Double = notSupported() + def stringValue: String = notSupported() + def typeValue: Type = notSupported() + def symbolValue: Symbol = notSupported() + def convertTo(pt: Type): Constant = notSupported() + } + val Constant: ConstantExtractor = DummyConstantExtractor + object DummyConstantExtractor extends ConstantExtractor { + def apply(const: Any): Constant = DummyConstant + def unapply(arg: Constant): Option[Any] = notSupported() + } + + // Members declared in scala.reflect.api.FreeVars + type FreeTerm = DummyFreeTerm.type + val DummyFreeTerm = DummySymbol + val FreeTerm: FreeTermExtractor = DummyFreeTermExtractor + object DummyFreeTermExtractor extends FreeTermExtractor { + def unapply(freeTerm: FreeTerm): Option[(TermName, Type, Any, String)] = notSupported() + } + type FreeType = DummyFreeType.type + val DummyFreeType = DummySymbol + val FreeType: FreeTypeExtractor = DummyFreeTypeExtractor + object DummyFreeTypeExtractor extends FreeTypeExtractor { + def unapply(freeType: FreeType): Option[(TypeName, Type, String)] = notSupported() + } + def freeTerms(tree: Tree): List[FreeTerm] = notSupported() + def freeTypes(tree: Tree): List[FreeType] = notSupported() + def substituteFreeTypes(tpe: Type,subs: Map[FreeType,Type]): Type = notSupported() + def substituteFreeTypes(tree: Tree,subs: Map[FreeType,Type]): Tree = notSupported() + + // Members declared in scala.reflect.api.Importers + def mkImporter(from0: scala.reflect.api.Universe): Importer{val from: from0.type} = notSupported() + + // Members declared in scala.reflect.api.Mirror + def classLoader: ClassLoader = cl + def classLoader_=(x$1: ClassLoader): Unit = notSupported() + def classToSymbol(clazz: Class[_]): Symbol = notSupported() + def classToType(clazz: Class[_]): Type = notSupported() + def companionInstance(clazz: Symbol): AnyRef = notSupported() + def getValueOfField(receiver: AnyRef,field: Symbol): Any = notSupported() + def invoke(receiver: AnyRef,meth: Symbol)(args: Any*): Any = notSupported() + def setValueOfField(receiver: AnyRef,field: Symbol,value: Any): Unit = notSupported() + def symbolForName(name: String): Symbol = notSupported() + def symbolOfInstance(instance: Any): Symbol = notSupported() + def symbolToClass(sym: Symbol): Class[_] = notSupported() + def typeOfInstance(instance: Any): Type = notSupported() + def typeToClass(tpe: Type): Class[_] = notSupported() + + // Members declared in scala.reflect.api.Names + type Name = DummyName.type + type TypeName = DummyName.type + type TermName = DummyName.type + object DummyName extends AbsName { + def isTermName: Boolean = notSupported() + def isTypeName: Boolean = notSupported() + def toTermName: TermName = notSupported() + def toTypeName: TypeName = notSupported() + def decoded: String = notSupported() + def encoded: String = notSupported() + def decodedName: Name = notSupported() + def encodedName: Name = notSupported() + } + def newTermName(s: String): TermName = notSupported() + def newTypeName(s: String): TypeName = notSupported() + + // Members declared in scala.reflect.api.Positions + type Position = DummyPosition.type + object DummyPosition extends api.Position { + def pos: Position = notSupported() + def withPos(newPos: scala.reflect.api.Position): Attachment = notSupported() + def payload: Any = notSupported() + def withPayload(newPayload: Any): Attachment = notSupported() + def fileInfo: java.io.File = notSupported() + def fileContent: Array[Char] = notSupported() + def isDefined: Boolean = notSupported() + def isTransparent: Boolean = notSupported() + def isRange: Boolean = notSupported() + def isOpaqueRange: Boolean = notSupported() + def makeTransparent: Position = notSupported() + def start: Int = notSupported() + def startOrPoint: Int = notSupported() + def point: Int = notSupported() + def pointOrElse(default: Int): Int = notSupported() + def end: Int = notSupported() + def endOrPoint: Int = notSupported() + def withStart(off: Int): Position = notSupported() + def withEnd(off: Int): Position = notSupported() + def withPoint(off: Int): Position = notSupported() + def union(pos: scala.reflect.api.Position): Position = notSupported() + def focusStart: Position = notSupported() + def focus: Position = notSupported() + def focusEnd: Position = notSupported() + def includes(pos: scala.reflect.api.Position): Boolean = notSupported() + def properlyIncludes(pos: scala.reflect.api.Position): Boolean = notSupported() + def precedes(pos: scala.reflect.api.Position): Boolean = notSupported() + def properlyPrecedes(pos: scala.reflect.api.Position): Boolean = notSupported() + def overlaps(pos: scala.reflect.api.Position): Boolean = notSupported() + def sameRange(pos: scala.reflect.api.Position): Boolean = notSupported() + def line: Int = notSupported() + def column: Int = notSupported() + def toSingleLine: Position = notSupported() + def lineContent: String = notSupported() + def show: String = notSupported() + } + val NoPosition: Position = DummyPosition + def atPos[T <: Tree](pos: Position)(tree: T): T = tree + def ensureNonOverlapping(tree: Tree,others: List[Tree]): Unit = notSupported() + def wrappingPos(trees: List[Tree]): Position = notSupported() + def wrappingPos(default: Position,trees: List[Tree]): Position = notSupported() + + // Members declared in scala.reflect.api.Reporters + def mkConsoleReporter(minSeverity: Int): Reporter = notSupported() + + // Members declared in scala.reflect.api.Scopes + type Scope = DummyScope.type + object DummyScope extends Iterable[Symbol] { + def iterator: Iterator[Symbol] = notSupported() + } + def newScope: Scope = DummyScope + def newScopeWith(elems: Symbol*): Scope = DummyScope + def newNestedScope(outer: Scope): Scope = DummyScope + + // Members declared in scala.reflect.api.StandardDefinitions + val AnyRefTpe: Type = DummyType + val AnyTpe: Type = DummyType + val AnyValTpe: Type = DummyType + val BooleanTpe: Type = DummyType + val ByteTpe: Type = DummyType + val CharTpe: Type = DummyType + val DoubleTpe: Type = DummyType + val FloatTpe: Type = DummyType + val IntTpe: Type = DummyType + val LongTpe: Type = DummyType + val NothingTpe: Type = DummyType + val NullTpe: Type = DummyType + val ObjectTpe: Type = DummyType + val ShortTpe: Type = DummyType + val StringTpe: Type = DummyType + val UnitTpe: Type = DummyType + val definitions: AbsDefinitions = DummyDefinitions + object DummyDefinitions extends AbsDefinitions { + def AnyClass: Symbol = DummySymbol + def AnyRefClass: Symbol = DummySymbol + def AnyValClass: Symbol = DummySymbol + def ArrayClass: Symbol = DummySymbol + def ArrayModule: Symbol = DummySymbol + def ArrayModule_overloadedApply: Symbol = DummySymbol + def Array_apply: Symbol = DummySymbol + def Array_clone: Symbol = DummySymbol + def Array_length: Symbol = DummySymbol + def Array_update: Symbol = DummySymbol + def BooleanClass: Symbol = DummySymbol + def ByNameParamClass: Symbol = DummySymbol + def ByteClass: Symbol = DummySymbol + def CharClass: Symbol = DummySymbol + def ClassClass: Symbol = DummySymbol + def ClassTagClass: Symbol = DummySymbol + def ClassTagModule: Symbol = DummySymbol + def ConcreteTypeTagClass: Symbol = DummySymbol + def ConcreteTypeTagModule: Symbol = DummySymbol + def ConsClass: Symbol = DummySymbol + def DoubleClass: Symbol = DummySymbol + def EmptyPackage: Symbol = DummySymbol + def EmptyPackageClass: Symbol = DummySymbol + def FloatClass: Symbol = DummySymbol + def FunctionClass: Array[Symbol] = Array() + def IntClass: Symbol = DummySymbol + def IterableClass: Symbol = DummySymbol + def IteratorClass: Symbol = DummySymbol + def IteratorModule: Symbol = DummySymbol + def Iterator_apply: Symbol = DummySymbol + def JavaLangPackage: Symbol = DummySymbol + def JavaLangPackageClass: Symbol = DummySymbol + def JavaRepeatedParamClass: Symbol = DummySymbol + def ListClass: Symbol = DummySymbol + def ListModule: Symbol = DummySymbol + def List_apply: Symbol = DummySymbol + def LongClass: Symbol = DummySymbol + def NilModule: Symbol = DummySymbol + def NoneModule: Symbol = DummySymbol + def NothingClass: Symbol = DummySymbol + def NullClass: Symbol = DummySymbol + def ObjectClass: Symbol = DummySymbol + def OptionClass: Symbol = DummySymbol + def PredefModule: Symbol = DummySymbol + def ProductClass: Array[Symbol] = Array() + def RepeatedParamClass: Symbol = DummySymbol + def RootClass: Symbol = DummySymbol + def RootPackage: Symbol = DummySymbol + def ScalaPackage: Symbol = DummySymbol + def ScalaPackageClass: Symbol = DummySymbol + def ScalaPrimitiveValueClasses: List[Symbol] = List() + def SeqClass: Symbol = DummySymbol + def SeqModule: Symbol = DummySymbol + def ShortClass: Symbol = DummySymbol + def SomeClass: Symbol = DummySymbol + def SomeModule: Symbol = DummySymbol + def StringBuilderClass: Symbol = DummySymbol + def StringClass: Symbol = DummySymbol + def SymbolClass: Symbol = DummySymbol + def TraversableClass: Symbol = DummySymbol + def TupleClass: Array[Symbol] = Array() + def TypeTagClass: Symbol = DummySymbol + def TypeTagModule: Symbol = DummySymbol + def UnitClass: Symbol = DummySymbol + def isNumericValueClass(sym: Symbol): Boolean = notSupported() + def isPrimitiveValueClass(sym: Symbol): Boolean = notSupported() + def vmClassType(arg: Type): Type = DummyType + def vmSignature(sym: Symbol,info: Type): String = notSupported() + } + + // Members declared in scala.reflect.api.StandardNames + val nme: AbsTermNames = DummyAbsTermNames + val tpnme: AbsTypeNames = DummyAbsTypeNames + object DummyAbsTermNames extends AbsTermNames { + type NameType = TermName + val EMPTY: NameType = DummyName + val ANON_FUN_NAME: NameType = DummyName + val ANON_CLASS_NAME: NameType = DummyName + val EMPTY_PACKAGE_NAME: NameType = DummyName + val IMPORT: NameType = DummyName + val MODULE_VAR_SUFFIX: NameType = DummyName + val ROOT: NameType = DummyName + val PACKAGE: NameType = DummyName + val SPECIALIZED_SUFFIX: NameType = DummyName + val ERROR: NameType = DummyName + val NO_NAME: NameType = DummyName + val WILDCARD: NameType = DummyName + def flattenedName(segments: Name*): NameType = notSupported() + val EXPAND_SEPARATOR_STRING: String = "" + val ANYNAME: TermName = DummyName + val CONSTRUCTOR: TermName = DummyName + val FAKE_LOCAL_THIS: TermName = DummyName + val INITIALIZER: TermName = DummyName + val LAZY_LOCAL: TermName = DummyName + val LOCAL_SUFFIX_STRING: String = "" + val MIRROR_PREFIX: TermName = DummyName + val MIRROR_SHORT: TermName = DummyName + val MIRROR_FREE_PREFIX: TermName = DummyName + val MIRROR_FREE_THIS_SUFFIX: TermName = DummyName + val MIRROR_FREE_VALUE_SUFFIX: TermName = DummyName + val MIRROR_SYMDEF_PREFIX: TermName = DummyName + val MIXIN_CONSTRUCTOR: TermName = DummyName + val MODULE_INSTANCE_FIELD: TermName = DummyName + val OUTER: TermName = DummyName + val OUTER_LOCAL: TermName = DummyName + val OUTER_SYNTH: TermName = DummyName + val SELECTOR_DUMMY: TermName = DummyName + val SELF: TermName = DummyName + val SPECIALIZED_INSTANCE: TermName = DummyName + val STAR: TermName = DummyName + val THIS: TermName = DummyName + val BITMAP_NORMAL: TermName = DummyName + val BITMAP_TRANSIENT: TermName = DummyName + val BITMAP_PRIVATE: TermName = DummyName + val BITMAP_CHECKINIT: TermName = DummyName + val BITMAP_CHECKINIT_TRANSIENT: TermName = DummyName + val INTERPRETER_IMPORT_WRAPPER: String = "" + val INTERPRETER_LINE_PREFIX: String = "" + val INTERPRETER_VAR_PREFIX: String = "" + val INTERPRETER_WRAPPER_SUFFIX: String = "" + val ROOTPKG: TermName = DummyName + val ADD: TermName = DummyName + val AND: TermName = DummyName + val ASR: TermName = DummyName + val DIV: TermName = DummyName + val EQ: TermName = DummyName + val EQL: TermName = DummyName + val GE: TermName = DummyName + val GT: TermName = DummyName + val HASHHASH: TermName = DummyName + val LE: TermName = DummyName + val LSL: TermName = DummyName + val LSR: TermName = DummyName + val LT: TermName = DummyName + val MINUS: TermName = DummyName + val MOD: TermName = DummyName + val MUL: TermName = DummyName + val NE: TermName = DummyName + val OR: TermName = DummyName + val PLUS : TermName = DummyName + val SUB: TermName = DummyName + val XOR: TermName = DummyName + val ZAND: TermName = DummyName + val ZOR: TermName = DummyName + val UNARY_~ : TermName = DummyName + val UNARY_+ : TermName = DummyName + val UNARY_- : TermName = DummyName + val UNARY_! : TermName = DummyName + val ??? : TermName = DummyName + val MODULE_SUFFIX_NAME: TermName = DummyName + val NAME_JOIN_NAME: TermName = DummyName + val IMPL_CLASS_SUFFIX: String = "" + val LOCALDUMMY_PREFIX: String = "" + val PROTECTED_PREFIX: String = "" + val PROTECTED_SET_PREFIX: String = "" + val SINGLETON_SUFFIX: String = "" + val SUPER_PREFIX_STRING: String = "" + val TRAIT_SETTER_SEPARATOR_STRING: String = "" + val SETTER_SUFFIX: TermName = DummyName + def isConstructorName(name: Name): Boolean = notSupported() + def isExceptionResultName(name: Name): Boolean = notSupported() + def isImplClassName(name: Name): Boolean = notSupported() + def isLocalDummyName(name: Name): Boolean = notSupported() + def isLocalName(name: Name): Boolean = notSupported() + def isLoopHeaderLabel(name: Name): Boolean = notSupported() + def isProtectedAccessorName(name: Name): Boolean = notSupported() + def isSuperAccessorName(name: Name): Boolean = notSupported() + def isReplWrapperName(name: Name): Boolean = notSupported() + def isSetterName(name: Name): Boolean = notSupported() + def isTraitSetterName(name: Name): Boolean = notSupported() + def isSingletonName(name: Name): Boolean = notSupported() + def isModuleName(name: Name): Boolean = notSupported() + def isOpAssignmentName(name: Name): Boolean = notSupported() + def segments(name: String, assumeTerm: Boolean): List[Name] = notSupported() + def originalName(name: Name): Name = notSupported() + def stripModuleSuffix(name: Name): Name = notSupported() + def unspecializedName(name: Name): Name = notSupported() + def splitSpecializedName(name: Name): (Name, String, String) = notSupported() + def dropLocalSuffix(name: Name): Name = notSupported() + def expandedName(name: TermName, base: Symbol, separator: String = EXPAND_SEPARATOR_STRING): TermName = notSupported() + def expandedSetterName(name: TermName, base: Symbol): TermName = notSupported() + def protName(name: Name): TermName = notSupported() + def protSetterName(name: Name): TermName = notSupported() + def getterName(name: TermName): TermName = notSupported() + def getterToLocal(name: TermName): TermName = notSupported() + def getterToSetter(name: TermName): TermName = notSupported() + def localToGetter(name: TermName): TermName = notSupported() + def setterToGetter(name: TermName): TermName = notSupported() + def defaultGetterName(name: Name, pos: Int): TermName = notSupported() + def defaultGetterToMethod(name: Name): TermName = notSupported() + def dropSingletonName(name: Name): TypeName = notSupported() + def singletonName(name: Name): TypeName = notSupported() + def implClassName(name: Name): TypeName = notSupported() + def interfaceName(implname: Name): TypeName = notSupported() + def localDummyName(clazz: Symbol): TermName = notSupported() + def superName(name: Name): TermName = notSupported() + } + object DummyAbsTypeNames extends AbsTypeNames { + type NameType = TypeName + val EMPTY: NameType = DummyName + val ANON_FUN_NAME: NameType = DummyName + val ANON_CLASS_NAME: NameType = DummyName + val EMPTY_PACKAGE_NAME: NameType = DummyName + val IMPORT: NameType = DummyName + val MODULE_VAR_SUFFIX: NameType = DummyName + val ROOT: NameType = DummyName + val PACKAGE: NameType = DummyName + val SPECIALIZED_SUFFIX: NameType = DummyName + val ERROR: NameType = DummyName + val NO_NAME: NameType = DummyName + val WILDCARD: NameType = DummyName + def flattenedName(segments: Name*): NameType = notSupported() + val REFINE_CLASS_NAME: TypeName = DummyName + val BYNAME_PARAM_CLASS_NAME: TypeName = DummyName + val EQUALS_PATTERN_NAME: TypeName = DummyName + val JAVA_REPEATED_PARAM_CLASS_NAME: TypeName = DummyName + val LOCAL_CHILD: TypeName = DummyName + val REPEATED_PARAM_CLASS_NAME: TypeName = DummyName + val WILDCARD_STAR: TypeName = DummyName + } + + // Members declared in scala.reflect.api.Symbols + type Symbol = DummySymbol.type + val NoSymbol: Symbol = DummySymbol + object DummySymbol extends AbsSymbol { + this: Symbol => + + def pos: Position = notSupported() + def modifiers: Set[Modifier] = notSupported() + def hasModifier(mod: Modifier): Boolean = notSupported() + def annotations: List[AnnotationInfo] = notSupported() + def hasAnnotation(sym: Symbol): Boolean = notSupported() + def owner: Symbol = notSupported() + def name: Name = notSupported() + def fullName: String = notSupported() + def id: Int = notSupported() + def orElse[T](alt: => Symbol): Symbol = notSupported() + def privateWithin: Symbol = notSupported() + def companionSymbol: Symbol = notSupported() + def moduleClass: Symbol = notSupported() + def enclosingTopLevelClass: Symbol = notSupported() + def enclosingClass: Symbol = notSupported() + def enclosingMethod: Symbol = notSupported() + def enclosingPackageClass: Symbol = notSupported() + def isTerm : Boolean = notSupported() + def isPackage : Boolean = notSupported() + def isMethod : Boolean = notSupported() + def isOverloaded : Boolean = notSupported() + def isFreeTerm : Boolean = notSupported() + def isType : Boolean = notSupported() + def isClass : Boolean = notSupported() + def isPackageClass : Boolean = notSupported() + def isPrimitiveValueClass: Boolean = notSupported() + def isDerivedValueClass: Boolean = notSupported() + def isAliasType : Boolean = notSupported() + def isAbstractType : Boolean = notSupported() + def isSkolem : Boolean = notSupported() + def isExistential : Boolean = notSupported() + def isFreeType : Boolean = notSupported() + def isContravariant : Boolean = notSupported() + def isCovariant : Boolean = notSupported() + def isErroneous : Boolean = notSupported() + def typeSignature: Type = notSupported() + def typeSignatureIn(site: Type): Type = notSupported() + def asType: Type = notSupported() + def asTypeIn(site: Type): Type = notSupported() + def asTypeConstructor: Type = notSupported() + def thisPrefix: Type = notSupported() + def selfType: Type = notSupported() + def alternatives: List[Symbol] = notSupported() + def resolveOverloaded(pre: Type = NoPrefix, targs: Seq[Type] = List(), actuals: Seq[Type]): Symbol = notSupported() + def newNestedSymbol(name: Name, pos: Position, flags: Long, isClass: Boolean): Symbol = notSupported() + def setInternalFlags(flags: Long): this.type = notSupported() + def setTypeSignature(tpe: Type): this.type = notSupported() + def setAnnotations(annots: AnnotationInfo*): this.type = notSupported() + def kind: String = notSupported() + } + + // Members declared in scala.reflect.api.ToolBoxes + def mkToolBox(reporter: Reporter,options: String): AbsToolBox = notSupported() + + // Members declared in scala.reflect.api.TreeBuildUtil + // type TreeGen = DummyTreeGen.type // [Eugene] cannot compile if uncomment this + val gen: TreeGen{val global: DummyMirror.this.type} = DummyTreeGen.asInstanceOf[TreeGen{val global: DummyMirror.this.type}] + def modifiersFromInternalFlags(flags: Long,privateWithin: Name,annotations: List[Tree]): Modifiers = DummyModifiers + def newFreeExistential(name: String,info: Type,value: => Any,flags: Long,origin: String): Symbol = DummySymbol + def newFreeTerm(name: String,info: Type,value: => Any,flags: Long,origin: String): Symbol = DummySymbol + def newFreeType(name: String,info: Type,value: => Any,flags: Long,origin: String): Symbol = DummySymbol + def selectOverloadedMethod(owner: Symbol,name: String,index: Int): Symbol = DummySymbol + def selectOverloadedMethodIfDefined(owner: Symbol,name: String,index: Int): Symbol = DummySymbol + def selectTerm(owner: Symbol,name: String): Symbol = DummySymbol + def selectTermIfDefined(owner: Symbol,name: String): Symbol = DummySymbol + def selectType(owner: Symbol,name: String): Symbol = DummySymbol + def selectTypeIfDefined(owner: Symbol,name: String): Symbol = DummySymbol + def staticClass(fullName: String): Symbol = DummySymbol + def staticClassIfDefined(fullName: String): Symbol = DummySymbol + def staticModule(fullName: String): Symbol = DummySymbol + def staticModuleIfDefined(fullName: String): Symbol = DummySymbol + def thisModuleType(fullName: String): Type = DummyType + object DummyTreeGen extends AbsTreeGen { + val global: Universe = DummyMirror.this + type TreeGenTree = global.Tree + type TreeGenType = global.Type + type TreeGenSymbol = global.Symbol + def mkAttributedQualifier(tpe: TreeGenType): TreeGenTree = notSupported() + def mkAttributedQualifier(tpe: TreeGenType, termSym: TreeGenSymbol): TreeGenTree = notSupported() + def mkAttributedRef(pre: TreeGenType, sym: TreeGenSymbol): TreeGenTree = notSupported() + def mkAttributedRef(sym: TreeGenSymbol): TreeGenTree = notSupported() + def mkAttributedThis(sym: TreeGenSymbol): TreeGenTree = notSupported() + def mkAttributedIdent(sym: TreeGenSymbol): TreeGenTree = notSupported() + def mkAttributedSelect(qual: TreeGenTree, sym: TreeGenSymbol): TreeGenTree = notSupported() + } + + // Members declared in scala.reflect.api.TreePrinters + def newTreePrinter(out: java.io.PrintWriter): TreePrinter = notSupported() + + // Members declared in scala.reflect.api.Trees + def Apply(sym: Symbol,args: Tree*): Tree = Apply(EmptyTree, Nil) + def Bind(sym: Symbol,body: Tree): Bind = Bind(DummyName, EmptyTree) + def Block(stats: Tree*): Block = Block() + def CaseDef(pat: Tree,body: Tree): CaseDef = CaseDef(EmptyTree, EmptyTree, EmptyTree) + def ClassDef(sym: Symbol,impl: Template): ClassDef = ClassDef(DummyModifiers, DummyName, Nil, Template(Nil, emptyValDef, Nil)) + def DefDef(sym: Symbol,rhs: List[List[Symbol]] => Tree): DefDef = DefDef(DummyModifiers, DummyName, Nil, Nil, EmptyTree, EmptyTree) + def DefDef(sym: Symbol,rhs: Tree): DefDef = DefDef(DummyModifiers, DummyName, Nil, Nil, EmptyTree, EmptyTree) + def DefDef(sym: Symbol,mods: Modifiers,rhs: Tree): DefDef = DefDef(DummyModifiers, DummyName, Nil, Nil, EmptyTree, EmptyTree) + def DefDef(sym: Symbol,vparamss: List[List[ValDef]],rhs: Tree): DefDef = DefDef(DummyModifiers, DummyName, Nil, Nil, EmptyTree, EmptyTree) + def DefDef(sym: Symbol,mods: Modifiers,vparamss: List[List[ValDef]],rhs: Tree): DefDef = DefDef(DummyModifiers, DummyName, Nil, Nil, EmptyTree, EmptyTree) + def Ident(sym: Symbol): Ident = Ident(DummyName) + def Ident(name: String): Ident = Ident(DummyName) + def LabelDef(sym: Symbol,params: List[Symbol],rhs: Tree): LabelDef = LabelDef(DummyName, Nil, EmptyTree) + type Modifiers = DummyModifiers.type + val NoMods: Modifiers = DummyModifiers + object DummyModifiers extends AbsModifiers { + def modifiers: Set[Modifier] = notSupported() + def hasModifier(mod: Modifier): Boolean = notSupported() + def privateWithin: Name = notSupported() + def annotations: List[Tree] = notSupported() + def mapAnnotations(f: List[Tree] => List[Tree]): Modifiers = notSupported() + } + def Modifiers(mods: Set[scala.reflect.api.Modifier],privateWithin: Name,annotations: List[Tree]): Modifiers = DummyModifiers + def ModuleDef(sym: Symbol,impl: Template): ModuleDef = ModuleDef(DummyModifiers, DummyName, Template(Nil, emptyValDef, Nil)) + def New(sym: Symbol,args: Tree*): Tree = New(EmptyTree) + def New(tpe: Type,args: Tree*): Tree = New(EmptyTree) + def New(tpt: Tree,argss: List[List[Tree]]): Tree = New(EmptyTree) + def Select(qualifier: Tree,sym: Symbol): Select = Select(EmptyTree, DummyName) + def Select(qualifier: Tree,name: String): Select = Select(EmptyTree, DummyName) + def Super(sym: Symbol,mix: TypeName): Tree = Super(EmptyTree, DummyName) + def This(sym: Symbol): Tree = This(DummyName) + def Throw(tpe: Type,args: Tree*): Throw = Throw(EmptyTree) + def Try(body: Tree,cases: (Tree, Tree)*): Try = Try(EmptyTree) + def TypeDef(sym: Symbol): TypeDef = TypeDef(DummyModifiers, DummyName, Nil, EmptyTree) + def TypeDef(sym: Symbol,rhs: Tree): TypeDef = TypeDef(DummyModifiers, DummyName, Nil, EmptyTree) + def ValDef(sym: Symbol): ValDef = ValDef(DummyModifiers, DummyName, EmptyTree, EmptyTree) + def ValDef(sym: Symbol,rhs: Tree): ValDef = ValDef(DummyModifiers, DummyName, EmptyTree, EmptyTree) + protected def duplicateTree(tree: Tree): Tree = notSupported() + object emptyValDef extends ValDef(DummyModifiers, DummyName, EmptyTree, EmptyTree) { override def isEmpty = true } + type TreeCopier = DummyTreeCopier.type + def newStrictTreeCopier: TreeCopier = DummyTreeCopier + def newLazyTreeCopier: TreeCopier = DummyTreeCopier + object DummyTreeCopier extends TreeCopierOps { + def ClassDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[TypeDef], impl: Template): ClassDef = notSupported() + def PackageDef(tree: Tree, pid: RefTree, stats: List[Tree]): PackageDef = notSupported() + def ModuleDef(tree: Tree, mods: Modifiers, name: Name, impl: Template): ModuleDef = notSupported() + def ValDef(tree: Tree, mods: Modifiers, name: Name, tpt: Tree, rhs: Tree): ValDef = notSupported() + def DefDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[TypeDef], vparamss: List[List[ValDef]], tpt: Tree, rhs: Tree): DefDef = notSupported() + def TypeDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[TypeDef], rhs: Tree): TypeDef = notSupported() + def LabelDef(tree: Tree, name: Name, params: List[Ident], rhs: Tree): LabelDef = notSupported() + def Import(tree: Tree, expr: Tree, selectors: List[ImportSelector]): Import = notSupported() + def Template(tree: Tree, parents: List[Tree], self: ValDef, body: List[Tree]): Template = notSupported() + def Block(tree: Tree, stats: List[Tree], expr: Tree): Block = notSupported() + def CaseDef(tree: Tree, pat: Tree, guard: Tree, body: Tree): CaseDef = notSupported() + def Alternative(tree: Tree, trees: List[Tree]): Alternative = notSupported() + def Star(tree: Tree, elem: Tree): Star = notSupported() + def Bind(tree: Tree, name: Name, body: Tree): Bind = notSupported() + def UnApply(tree: Tree, fun: Tree, args: List[Tree]): UnApply = notSupported() + def ArrayValue(tree: Tree, elemtpt: Tree, trees: List[Tree]): ArrayValue = notSupported() + def Function(tree: Tree, vparams: List[ValDef], body: Tree): Function = notSupported() + def Assign(tree: Tree, lhs: Tree, rhs: Tree): Assign = notSupported() + def AssignOrNamedArg(tree: Tree, lhs: Tree, rhs: Tree): AssignOrNamedArg = notSupported() + def If(tree: Tree, cond: Tree, thenp: Tree, elsep: Tree): If = notSupported() + def Match(tree: Tree, selector: Tree, cases: List[CaseDef]): Match = notSupported() + def Return(tree: Tree, expr: Tree): Return = notSupported() + def Try(tree: Tree, block: Tree, catches: List[CaseDef], finalizer: Tree): Try = notSupported() + def Throw(tree: Tree, expr: Tree): Throw = notSupported() + def New(tree: Tree, tpt: Tree): New = notSupported() + def Typed(tree: Tree, expr: Tree, tpt: Tree): Typed = notSupported() + def TypeApply(tree: Tree, fun: Tree, args: List[Tree]): TypeApply = notSupported() + def Apply(tree: Tree, fun: Tree, args: List[Tree]): Apply = notSupported() + def ApplyDynamic(tree: Tree, qual: Tree, args: List[Tree]): ApplyDynamic = notSupported() + def Super(tree: Tree, qual: Tree, mix: TypeName): Super = notSupported() + def This(tree: Tree, qual: Name): This = notSupported() + def Select(tree: Tree, qualifier: Tree, selector: Name): Select = notSupported() + def Ident(tree: Tree, name: Name): Ident = notSupported() + def ReferenceToBoxed(tree: Tree, idt: Ident): ReferenceToBoxed = notSupported() + def Literal(tree: Tree, value: Constant): Literal = notSupported() + def TypeTree(tree: Tree): TypeTree = notSupported() + def Annotated(tree: Tree, annot: Tree, arg: Tree): Annotated = notSupported() + def SingletonTypeTree(tree: Tree, ref: Tree): SingletonTypeTree = notSupported() + def SelectFromTypeTree(tree: Tree, qualifier: Tree, selector: Name): SelectFromTypeTree = notSupported() + def CompoundTypeTree(tree: Tree, templ: Template): CompoundTypeTree = notSupported() + def AppliedTypeTree(tree: Tree, tpt: Tree, args: List[Tree]): AppliedTypeTree = notSupported() + def TypeBoundsTree(tree: Tree, lo: Tree, hi: Tree): TypeBoundsTree = notSupported() + def ExistentialTypeTree(tree: Tree, tpt: Tree, whereClauses: List[Tree]): ExistentialTypeTree = notSupported() + } + + // Members declared in scala.reflect.api.Types + type Type = DummyType.type + type SingletonType = DummyType.type + type CompoundType = DummyType.type + type AnnotatedType = DummyType.type + val AnnotatedType: AnnotatedTypeExtractor = DummyAnnotatedTypeExtractor + type BoundedWildcardType = DummyType.type + val BoundedWildcardType: BoundedWildcardTypeExtractor = DummyBoundedWildcardTypeExtractor + type ClassInfoType = DummyType.type + val ClassInfoType: ClassInfoTypeExtractor = DummyClassInfoTypeExtractor + type ConstantType = DummyType.type + val ConstantType: ConstantTypeExtractor = DummyConstantTypeExtractor + type ExistentialType = DummyType.type + val ExistentialType: ExistentialTypeExtractor = DummyExistentialTypeExtractor + type MethodType = DummyType.type + val MethodType: MethodTypeExtractor = DummyMethodTypeExtractor + val NoPrefix: Type = DummyType + val NoType: Type = DummyType + type NullaryMethodType = DummyType.type + val NullaryMethodType: NullaryMethodTypeExtractor = DummyNullaryMethodTypeExtractor + type PolyType = DummyType.type + val PolyType: PolyTypeExtractor = DummyPolyTypeExtractor + type RefinedType = DummyType.type + val RefinedType: RefinedTypeExtractor = DummyRefinedTypeExtractor + type SingleType = DummyType.type + val SingleType: SingleTypeExtractor = DummySingleTypeExtractor + type SuperType = DummyType.type + val SuperType: SuperTypeExtractor = DummySuperTypeExtractor + type ThisType = DummyType.type + val ThisType: ThisTypeExtractor = DummyThisTypeExtractor + type TypeBounds = DummyType.type + val TypeBounds: TypeBoundsExtractor = DummyTypeBoundsExtractor + type TypeRef = DummyType.type + val TypeRef: TypeRefExtractor = DummyTypeRefExtractor + val WildcardType: Type = DummyType + def appliedType(tycon: Type,args: List[Type]): Type = DummyType + def existentialAbstraction(tparams: List[Symbol],tpe0: Type): Type = DummyType + def glb(ts: List[Type]): Type = DummyType + def intersectionType(tps: List[Type],owner: Symbol): Type = DummyType + def intersectionType(tps: List[Type]): Type = DummyType + def lub(xs: List[Type]): Type = DummyType + def polyType(tparams: List[Symbol],tpe: Type): Type = DummyType + def refinedType(parents: List[Type],owner: Symbol): Type = DummyType + def refinedType(parents: List[Type],owner: Symbol,decls: Scope,pos: Position): Type = DummyType + def singleType(pre: Type,sym: Symbol): Type = DummyType + def typeRef(pre: Type,sym: Symbol,args: List[Type]): Type = DummyType + object DummyType extends AbsType { + def =:=(that: Type): Boolean = notSupported() + def <:<(that: Type): Boolean = notSupported() + def asSeenFrom(pre: Type,clazz: Symbol): Type = notSupported() + def baseClasses: List[Symbol] = notSupported() + def baseType(clazz: Symbol): Type = notSupported() + def contains(sym: Symbol): Boolean = notSupported() + def declaration(name: Name): Symbol = notSupported() + def declarations: Iterable[Symbol] = notSupported() + def erasure: Type = notSupported() + def exists(p: Type => Boolean): Boolean = notSupported() + def find(p: Type => Boolean): Option[Type] = notSupported() + def foreach(f: Type => Unit): Unit = notSupported() + def isConcrete: Boolean = notSupported() + def isHigherKinded: Boolean = notSupported() + def isSpliceable: Boolean = notSupported() + def kind: String = notSupported() + def map(f: Type => Type): Type = notSupported() + def member(name: Name): Symbol = notSupported() + def members: Iterable[Symbol] = notSupported() + def nonPrivateMember(name: Name): Symbol = notSupported() + def nonPrivateMembers: Iterable[Symbol] = notSupported() + def normalize: Type = notSupported() + def parents: List[Type] = notSupported() + def substituteTypes(from: List[Symbol],to: List[Type]): Type = notSupported() + def typeArguments: List[Type] = notSupported() + def typeConstructor: Type = notSupported() + def typeParams: List[Symbol] = notSupported() + def typeSymbol: Symbol = notSupported() + def underlying: Type = notSupported() + def widen: Type = notSupported() + } + object DummyAnnotatedTypeExtractor extends AnnotatedTypeExtractor { + def apply(annotations: List[AnnotationInfo], underlying: Type, selfsym: Symbol): AnnotatedType = DummyType + def unapply(tpe: AnnotatedType): Option[(List[AnnotationInfo], Type, Symbol)] = notSupported() + } + object DummyBoundedWildcardTypeExtractor extends BoundedWildcardTypeExtractor { + def apply(bounds: TypeBounds): BoundedWildcardType = DummyType + def unapply(tpe: BoundedWildcardType): Option[TypeBounds] = notSupported() + } + object DummyClassInfoTypeExtractor extends ClassInfoTypeExtractor { + def apply(parents: List[Type], decls: Scope, clazz: Symbol): ClassInfoType = DummyType + def unapply(tpe: ClassInfoType): Option[(List[Type], Scope, Symbol)] = notSupported() + } + object DummyConstantTypeExtractor extends ConstantTypeExtractor { + def apply(value: Constant): ConstantType = DummyType + def unapply(tpe: ConstantType): Option[Constant] = notSupported() + } + object DummyExistentialTypeExtractor extends ExistentialTypeExtractor { + def apply(quantified: List[Symbol], underlying: Type): ExistentialType = DummyType + def unapply(tpe: ExistentialType): Option[(List[Symbol], Type)] = notSupported() + } + object DummyMethodTypeExtractor extends MethodTypeExtractor { + def apply(params: List[Symbol], resultType: Type): MethodType = DummyType + def unapply(tpe: MethodType): Option[(List[Symbol], Type)] = notSupported() + } + object DummyNullaryMethodTypeExtractor extends NullaryMethodTypeExtractor { + def apply(resultType: Type): NullaryMethodType = DummyType + def unapply(tpe: NullaryMethodType): Option[(Type)] = notSupported() + } + object DummyPolyTypeExtractor extends PolyTypeExtractor { + def apply(typeParams: List[Symbol], resultType: Type): PolyType = DummyType + def unapply(tpe: PolyType): Option[(List[Symbol], Type)] = notSupported() + } + object DummyRefinedTypeExtractor extends RefinedTypeExtractor { + def apply(parents: List[Type], decls: Scope): RefinedType = DummyType + def apply(parents: List[Type], decls: Scope, clazz: Symbol): RefinedType = DummyType + def unapply(tpe: RefinedType): Option[(List[Type], Scope)] = notSupported() + } + object DummySingleTypeExtractor extends SingleTypeExtractor { + def apply(pre: Type, sym: Symbol): Type = DummyType + def unapply(tpe: SingleType): Option[(Type, Symbol)] = notSupported() + } + object DummySuperTypeExtractor extends SuperTypeExtractor { + def apply(thistpe: Type, supertpe: Type): Type = DummyType + def unapply(tpe: SuperType): Option[(Type, Type)] = notSupported() + } + object DummyThisTypeExtractor extends ThisTypeExtractor { + def apply(sym: Symbol): Type = DummyType + def unapply(tpe: ThisType): Option[Symbol] = notSupported() + } + object DummyTypeBoundsExtractor extends TypeBoundsExtractor { + def apply(lo: Type, hi: Type): TypeBounds = DummyType + def unapply(tpe: TypeBounds): Option[(Type, Type)] = notSupported() + } + object DummyTypeRefExtractor extends TypeRefExtractor { + def apply(pre: Type, sym: Symbol, args: List[Type]): Type = DummyType + def unapply(tpe: TypeRef): Option[(Type, Symbol, List[Type])] = notSupported() + } + + // Utils + def notSupported() = { + throw new UnsupportedOperationException("Scala reflection not available on this platform." + mirrorDiagnostics(cl)) + } +}
\ No newline at end of file diff --git a/src/library/scala/reflect/DynamicProxy.scala b/src/library/scala/reflect/DynamicProxy.scala index ffd1e7a39f..02872977f5 100644 --- a/src/library/scala/reflect/DynamicProxy.scala +++ b/src/library/scala/reflect/DynamicProxy.scala @@ -2,13 +2,13 @@ package scala.reflect /** * A dynamic proxy which redirects method calls and attribute access to a given * target object at runtime using reflection. - * + * * Usage example: - * + * * object x{ def hello = "hello world" } * val d = new DynamicProxy{ val dynamicProxyTarget = x } * assert( d.hello == "hello world" ) - * + * * Not supported (yet): * - implicit conversions and parameters * - multiple arguments lists @@ -26,7 +26,7 @@ trait DynamicProxy extends Dynamic{ object DynamicReflectBoxed{ implicit def box[@specialized T]( v:T ) = DynamicReflectBoxed( v.getClass, v ) } - + def selectDynamic( method:String ) = { val symbol = classToType( dynamicProxyTarget.getClass ).member( newTermName(method).encodedName ) invoke( dynamicProxyTarget, symbol )() @@ -38,7 +38,7 @@ trait DynamicProxy extends Dynamic{ } def applyDynamic( method:String )( args:DynamicReflectBoxed* ) : Any - = applyDynamicNamed( method )( args.map( value => ("",value) ) :_* ) + = applyDynamicNamed( method )( args.map( value => ("",value) ) :_* ) def applyDynamicNamed( method:String )( args:(String,DynamicReflectBoxed)* ) : Any = { val class_ = dynamicProxyTarget.getClass @@ -48,27 +48,27 @@ trait DynamicProxy extends Dynamic{ if(args.size == 0){ invoke( dynamicProxyTarget, symbol )() } else { - val call = + val call = Apply( Select( TypeApply( Select( Select( - Ident(newFreeTerm("__this", symbolForName("scala.reflect.DynamicProxy").asType, this, null)) + Ident(newFreeTerm("__this", symbolForName("scala.reflect.DynamicProxy").asType, this)) , newTermName("dynamicProxyTarget") - ), + ), newTermName("asInstanceOf") ) , List(TypeTree().setType(classToType(class_))) ) ,newTermName(method).encodedName ) ,args.map{ case(name,box) => - val value = Ident(newFreeTerm("__arg"+({i+=1;i}.toString), classToType(box.class_), box.value, null)) + val value = Ident(newFreeTerm("__arg"+({i+=1;i}.toString), classToType(box.class_), box.value)) if( name == "" ) value else AssignOrNamedArg( Ident(name), value ) }.toList ) toolbox.runExpr( call ) - } + } } } diff --git a/src/library/scala/reflect/TagMaterialization.scala b/src/library/scala/reflect/TagMaterialization.scala index aede00020f..a7237223f1 100644 --- a/src/library/scala/reflect/TagMaterialization.scala +++ b/src/library/scala/reflect/TagMaterialization.scala @@ -65,59 +65,22 @@ object TagMaterialization { val ConcreteTypeTagClass = selectType(TypeTagsClass, "ConcreteTypeTag") val ConcreteTypeTagModule = selectTerm(TypeTagsClass, "ConcreteTypeTag") - def materializeClassTag(tpe: Type): Tree = { - val prefix = gen.mkAttributedRef(Reflect_mirror) setType singleType(Reflect_mirror.owner.thisPrefix, Reflect_mirror) - materializeClassTag(prefix, tpe) - } - - def materializeClassTag(prefix: Tree, tpe: Type): Tree = { - val typetagInScope = c.inferImplicitValue(appliedType(typeRef(prefix.tpe, ConcreteTypeTagClass, Nil), List(tpe))) - def typetagIsSynthetic(tree: Tree) = tree.isInstanceOf[Block] || (tree exists (sub => sub.symbol == TypeTagModule || sub.symbol == ConcreteTypeTagModule)) - typetagInScope match { - case success if !success.isEmpty && !typetagIsSynthetic(success) => - val factory = TypeApply(Select(Ident(ClassTagModule), newTermName("apply")), List(TypeTree(tpe))) - Apply(factory, List(Select(typetagInScope, newTermName("tpe")))) - case _ => - val result = - tpe match { - case coreTpe if coreTags contains coreTpe => - Select(Ident(ClassTagModule), coreTags(coreTpe)) - case _ => - if (tpe.typeSymbol == ArrayClass) { - val componentTpe = tpe.typeArguments(0) - val classtagInScope = c.inferImplicitValue(appliedType(typeRef(NoPrefix, ClassTagClass, Nil), List(componentTpe))) - val componentTag = classtagInScope orElse materializeClassTag(prefix, componentTpe) - Select(componentTag, newTermName("wrap")) - } else { - // [Eugene] what's the intended behavior? there's no spec on ClassManifests - // for example, should we ban Array[T] or should we tag them with Array[AnyRef]? - // if its the latter, what should be the result of tagging Array[T] where T <: Int? - if (tpe.typeSymbol.isAbstractType) fail("tpe is an abstract type") - val erasure = - if (tpe.typeSymbol.isDerivedValueClass) tpe // [Eugene to Martin] is this correct? - else tpe.erasure.normalize // necessary to deal with erasures of HK types - val factory = TypeApply(Select(Ident(ClassTagModule), newTermName("apply")), List(TypeTree(tpe))) - Apply(factory, List(TypeApply(Ident(newTermName("classOf")), List(TypeTree(erasure))))) - } - } - try c.typeCheck(result) - catch { case terr @ c.TypeError(pos, msg) => fail(terr) } - } - } + def materializeClassTag(tpe: Type): Tree = + materializeTag(c.reflectMirrorPrefix, tpe, ClassTagModule, c.reifyErasure(tpe)) def materializeTypeTag(tpe: Type, requireConcreteTypeTag: Boolean): Tree = { def prefix: Tree = ??? // todo. needs to be synthesized from c.prefix - materializeTypeTag(prefix, tpe, requireConcreteTypeTag) + val tagModule = if (requireConcreteTypeTag) ConcreteTypeTagModule else TypeTagModule + materializeTag(prefix, tpe, tagModule, c.reifyType(prefix, tpe, dontSpliceAtTopLevel = true, requireConcreteTypeTag = requireConcreteTypeTag)) } - def materializeTypeTag(prefix: Tree, tpe: Type, requireConcreteTypeTag: Boolean): Tree = { - val tagModule = if (requireConcreteTypeTag) ConcreteTypeTagModule else TypeTagModule + private def materializeTag(prefix: Tree, tpe: Type, tagModule: Symbol, materializer: => Tree): Tree = { val result = tpe match { case coreTpe if coreTags contains coreTpe => Select(Select(prefix, tagModule.name), coreTags(coreTpe)) case _ => - try c.reifyType(prefix, tpe, dontSpliceAtTopLevel = true, requireConcreteTypeTag = requireConcreteTypeTag) + try materializer catch { case ex: Throwable => // [Eugene] cannot pattern match on an abstract type, so had to do this diff --git a/src/library/scala/reflect/api/Attachment.scala b/src/library/scala/reflect/api/Attachment.scala index 9fa5ceb0fb..50f55b4aa5 100644 --- a/src/library/scala/reflect/api/Attachment.scala +++ b/src/library/scala/reflect/api/Attachment.scala @@ -7,8 +7,6 @@ package api * Attachments have to carry positions, because we don't want to introduce even a single additional field in Tree * imposing an unnecessary memory tax because of something that will not be used in most cases. */ -// [Eugene] with the introduction of `attach` and `payload[T]` users don't need to create custom attachments anymore -// however, we cannot move attachments to scala.reflect.internal, because they are used in Trees, which are implemented completely in scala.reflect.api trait Attachment { /** Gets the underlying position */ def pos: Position @@ -22,3 +20,10 @@ trait Attachment { /** Creates a copy of this attachment with its payload updated */ def withPayload(newPayload: Any): Attachment } + +// [Eugene] with the introduction of `attach` and `attachment[T]` users don't need to create custom attachments anymore +// however, we cannot move attachments to scala.reflect.internal, because they are used in Trees, which are implemented completely in scala.reflect.api +private[scala] case class NontrivialAttachment(pos: api.Position, payload: collection.mutable.ListBuffer[Any]) extends Attachment { + def withPos(newPos: api.Position) = copy(pos = newPos, payload = payload) + def withPayload(newPayload: Any) = copy(pos = pos, payload = newPayload.asInstanceOf[collection.mutable.ListBuffer[Any]]) +}
\ No newline at end of file diff --git a/src/library/scala/reflect/api/Symbols.scala b/src/library/scala/reflect/api/Symbols.scala index e47bc7216e..d9293888d9 100755 --- a/src/library/scala/reflect/api/Symbols.scala +++ b/src/library/scala/reflect/api/Symbols.scala @@ -120,6 +120,11 @@ trait Symbols { self: Universe => */ def isTerm : Boolean + /** Does this symbol represent a package? + * If yes, `isTerm` is also guaranteed to be true. + */ + def isPackage : Boolean + /** Does this symbol represent the definition of method? * If yes, `isTerm` is also guaranteed to be true. */ @@ -146,6 +151,11 @@ trait Symbols { self: Universe => */ def isClass : Boolean + /** Does this symbol represent a package class? + * If yes, `isClass` is also guaranteed to be true. + */ + def isPackageClass : Boolean + /** Does this symbol represent the definition of a primitive class? * Namely, is it one of [[scala.Double]], [[scala.Float]], [[scala.Long]], [[scala.Int]], [[scala.Char]], * [[scala.Short]], [[scala.Byte]], [[scala.Unit]] or [[scala.Boolean]]? diff --git a/src/library/scala/reflect/api/TreeBuildUtil.scala b/src/library/scala/reflect/api/TreeBuildUtil.scala index 32d7eefa5b..4f510337c2 100644 --- a/src/library/scala/reflect/api/TreeBuildUtil.scala +++ b/src/library/scala/reflect/api/TreeBuildUtil.scala @@ -62,20 +62,34 @@ trait TreeBuildUtil { self: Universe => * @param name the name of the free variable * @param info the type signature of the free variable * @param value the value of the free variable at runtime + * @param flags (optional) flags of the free variable * @param origin debug information that tells where this symbol comes from */ - def newFreeTerm(name: String, info: Type, value: => Any, origin: String): Symbol + def newFreeTerm(name: String, info: Type, value: => Any, flags: Long = 0L, origin: String = null): Symbol - /** Create a fresh free type symbol. + /** Create a fresh free non-existential type symbol. * @param name the name of the free variable * @param info the type signature of the free variable * @param value a type tag that captures the value of the free variable * is completely phantom, since the captured type cannot be propagated to the runtime * if it could be, we wouldn't be creating a free type to begin with * the only usage for it is preserving the captured symbol for compile-time analysis + * @param flags (optional) flags of the free variable * @param origin debug information that tells where this symbol comes from */ - def newFreeType(name: String, info: Type, value: => Any, origin: String): Symbol + def newFreeType(name: String, info: Type, value: => Any, flags: Long = 0L, origin: String = null): Symbol + + /** Create a fresh free existential type symbol. + * @param name the name of the free variable + * @param info the type signature of the free variable + * @param value a type tag that captures the value of the free variable + * is completely phantom, since the captured type cannot be propagated to the runtime + * if it could be, we wouldn't be creating a free type to begin with + * the only usage for it is preserving the captured symbol for compile-time analysis + * @param flags (optional) flags of the free variable + * @param origin (optional) debug information that tells where this symbol comes from + */ + def newFreeExistential(name: String, info: Type, value: => Any, flags: Long = 0L, origin: String = null): Symbol /** Create a Modiiers structure given internal flags, qualifier, annotations */ def modifiersFromInternalFlags(flags: Long, privateWithin: Name, annotations: List[Tree]): Modifiers diff --git a/src/library/scala/reflect/api/Trees.scala b/src/library/scala/reflect/api/Trees.scala index 7548a6bdc0..6e2e8261e7 100644 --- a/src/library/scala/reflect/api/Trees.scala +++ b/src/library/scala/reflect/api/Trees.scala @@ -85,18 +85,39 @@ trait Trees { self: Universe => def pos_=(pos: Position): Unit = rawatt = (rawatt withPos pos) // the "withPos" part is crucial to robustness def setPos(newpos: Position): this.type = { pos = newpos; this } + // [Eugene] can we make this more type-safe private var rawatt: Attachment = NoPosition - private case class NontrivialAttachment(pos: api.Position, payload: Any) extends Attachment { - def withPos(newPos: api.Position) = copy(pos = newPos, payload = payload) - def withPayload(newPayload: Any) = copy(pos = pos, payload = newPayload) - } - // todo. annotate T with ClassTag and make pattern matcher use it - // todo. support multiple attachments, and remove the assignment. only leave attach/detach -// def attachment[T]: T = rawatt.payload.asInstanceOf[T] -// def attachmentOpt[T]: Option[T] = try { Some(rawatt.payload.asInstanceOf[T]) } catch { case _: Throwable => None } - def attachment: Any = rawatt.payload - def attachment_=(att: Any): Unit = rawatt = NontrivialAttachment(pos, att) - def setAttachment(att: Any): this.type = { attachment = att; this } + def attach(att: Any): Unit = + rawatt match { + case NontrivialAttachment(pos, payload) => + val index = payload.indexWhere(p => p.getClass == att.getClass) + if (index == -1) payload += att + else payload(index) = att + case _ => + rawatt = NontrivialAttachment(pos, collection.mutable.ListBuffer[Any](att)) + } + def withAttachment(att: Any): this.type = { attach(att); this } + def detach(att: Any): Unit = + detach(att.getClass) + def detach(clazz: java.lang.Class[_]): Unit = + rawatt match { + case NontrivialAttachment(pos, payload) => + val index = payload.indexWhere(p => p.getClass == clazz) + if (index != -1) payload.remove(index) + case _ => + // do nothing + } + def withoutAttachment(att: Any): this.type = { detach(att); this } + def attachment[T: ClassTag]: T = attachmentOpt[T] getOrElse { throw new Error("no attachment of type %s".format(classTag[T].erasure)) } + def attachmentOpt[T: ClassTag]: Option[T] = + rawatt match { + case NontrivialAttachment(pos, payload) => + val index = payload.indexWhere(p => p.getClass == classTag[T].erasure) + if (index != -1) Some(payload(index).asInstanceOf[T]) + else None + case _ => + None + } private[this] var rawtpe: Type = _ diff --git a/src/library/scala/reflect/api/TypeTags.scala b/src/library/scala/reflect/api/TypeTags.scala index 59a7c87f44..b90475b15a 100644 --- a/src/library/scala/reflect/api/TypeTags.scala +++ b/src/library/scala/reflect/api/TypeTags.scala @@ -7,6 +7,7 @@ package scala.reflect package api import scala.reflect.{ mirror => rm } +import java.lang.{ Class => jClass } import language.implicitConversions /** @@ -66,9 +67,13 @@ trait TypeTags { self: Universe => def toConcrete: ConcreteTypeTag[T] = ConcreteTypeTag[T](tpe) override def toString = { - var prefix = if (isConcrete) "ConcreteTypeTag" else "TypeTag" - if (prefix != this.productPrefix) prefix = "*" + prefix - prefix + "[" + tpe + "]" + if (!self.isInstanceOf[DummyMirror]) { + var prefix = if (isConcrete) "ConcreteTypeTag" else "TypeTag" + if (prefix != this.productPrefix) prefix = "*" + prefix + prefix + "[" + tpe + "]" + } else { + this.productPrefix + "[?]" + } } } @@ -119,33 +124,35 @@ trait TypeTags { self: Universe => * @see [[scala.reflect.api.TypeTags]] */ @annotation.implicitNotFound(msg = "No ConcreteTypeTag available for ${T}") - class ConcreteTypeTag[T](tpe: Type) extends TypeTag[T](tpe) { - // it's unsafe to use assert here, because we might run into deadlocks with Predef - // also see comments in ClassTags.scala - //assert(isConcrete, tpe) - if (notConcrete) throw new Error("%s (%s) is not concrete and cannot be used to construct a concrete type tag".format(tpe, tpe.kind)) + abstract class ConcreteTypeTag[T](tpe: Type, val erasure: jClass[_]) extends TypeTag[T](tpe) { + if (!self.isInstanceOf[DummyMirror]) { +// it's unsafe to use assert here, because we might run into deadlocks with Predef +// also see comments in ClassTags.scala +// assert(isConcrete, tpe) + if (notConcrete) throw new Error("%s (%s) is not concrete and cannot be used to construct a concrete type tag".format(tpe, tpe.kind)) + } override def productPrefix = "ConcreteTypeTag" } object ConcreteTypeTag { - val Byte : ConcreteTypeTag[scala.Byte] = new ConcreteTypeTag[scala.Byte](ByteTpe) { private def readResolve() = ConcreteTypeTag.Byte } - val Short : ConcreteTypeTag[scala.Short] = new ConcreteTypeTag[scala.Short](ShortTpe) { private def readResolve() = ConcreteTypeTag.Short } - val Char : ConcreteTypeTag[scala.Char] = new ConcreteTypeTag[scala.Char](CharTpe) { private def readResolve() = ConcreteTypeTag.Char } - val Int : ConcreteTypeTag[scala.Int] = new ConcreteTypeTag[scala.Int](IntTpe) { private def readResolve() = ConcreteTypeTag.Int } - val Long : ConcreteTypeTag[scala.Long] = new ConcreteTypeTag[scala.Long](LongTpe) { private def readResolve() = ConcreteTypeTag.Long } - val Float : ConcreteTypeTag[scala.Float] = new ConcreteTypeTag[scala.Float](FloatTpe) { private def readResolve() = ConcreteTypeTag.Float } - val Double : ConcreteTypeTag[scala.Double] = new ConcreteTypeTag[scala.Double](DoubleTpe) { private def readResolve() = ConcreteTypeTag.Double } - val Boolean : ConcreteTypeTag[scala.Boolean] = new ConcreteTypeTag[scala.Boolean](BooleanTpe) { private def readResolve() = ConcreteTypeTag.Boolean } - val Unit : ConcreteTypeTag[scala.Unit] = new ConcreteTypeTag[scala.Unit](UnitTpe) { private def readResolve() = ConcreteTypeTag.Unit } - val Any : ConcreteTypeTag[scala.Any] = new ConcreteTypeTag[scala.Any](AnyTpe) { private def readResolve() = ConcreteTypeTag.Any } - val Object : ConcreteTypeTag[java.lang.Object] = new ConcreteTypeTag[java.lang.Object](ObjectTpe) { private def readResolve() = ConcreteTypeTag.Object } - val AnyVal : ConcreteTypeTag[scala.AnyVal] = new ConcreteTypeTag[scala.AnyVal](AnyValTpe) { private def readResolve() = ConcreteTypeTag.AnyVal } - val AnyRef : ConcreteTypeTag[scala.AnyRef] = new ConcreteTypeTag[scala.AnyRef](AnyRefTpe) { private def readResolve() = ConcreteTypeTag.AnyRef } - val Nothing : ConcreteTypeTag[scala.Nothing] = new ConcreteTypeTag[scala.Nothing](NothingTpe) { private def readResolve() = ConcreteTypeTag.Nothing } - val Null : ConcreteTypeTag[scala.Null] = new ConcreteTypeTag[scala.Null](NullTpe) { private def readResolve() = ConcreteTypeTag.Null } - val String : ConcreteTypeTag[java.lang.String] = new ConcreteTypeTag[java.lang.String](StringTpe) { private def readResolve() = ConcreteTypeTag.String } - - def apply[T](tpe: Type): ConcreteTypeTag[T] = + val Byte : ConcreteTypeTag[scala.Byte] = new ConcreteTypeTag[scala.Byte](ByteTpe, ClassTag.Byte.erasure) { private def readResolve() = ConcreteTypeTag.Byte } + val Short : ConcreteTypeTag[scala.Short] = new ConcreteTypeTag[scala.Short](ShortTpe, ClassTag.Short.erasure) { private def readResolve() = ConcreteTypeTag.Short } + val Char : ConcreteTypeTag[scala.Char] = new ConcreteTypeTag[scala.Char](CharTpe, ClassTag.Char.erasure) { private def readResolve() = ConcreteTypeTag.Char } + val Int : ConcreteTypeTag[scala.Int] = new ConcreteTypeTag[scala.Int](IntTpe, ClassTag.Int.erasure) { private def readResolve() = ConcreteTypeTag.Int } + val Long : ConcreteTypeTag[scala.Long] = new ConcreteTypeTag[scala.Long](LongTpe, ClassTag.Long.erasure) { private def readResolve() = ConcreteTypeTag.Long } + val Float : ConcreteTypeTag[scala.Float] = new ConcreteTypeTag[scala.Float](FloatTpe, ClassTag.Float.erasure) { private def readResolve() = ConcreteTypeTag.Float } + val Double : ConcreteTypeTag[scala.Double] = new ConcreteTypeTag[scala.Double](DoubleTpe, ClassTag.Double.erasure) { private def readResolve() = ConcreteTypeTag.Double } + val Boolean : ConcreteTypeTag[scala.Boolean] = new ConcreteTypeTag[scala.Boolean](BooleanTpe, ClassTag.Boolean.erasure) { private def readResolve() = ConcreteTypeTag.Boolean } + val Unit : ConcreteTypeTag[scala.Unit] = new ConcreteTypeTag[scala.Unit](UnitTpe, ClassTag.Unit.erasure) { private def readResolve() = ConcreteTypeTag.Unit } + val Any : ConcreteTypeTag[scala.Any] = new ConcreteTypeTag[scala.Any](AnyTpe, ClassTag.Any.erasure) { private def readResolve() = ConcreteTypeTag.Any } + val Object : ConcreteTypeTag[java.lang.Object] = new ConcreteTypeTag[java.lang.Object](ObjectTpe, ClassTag.Object.erasure) { private def readResolve() = ConcreteTypeTag.Object } + val AnyVal : ConcreteTypeTag[scala.AnyVal] = new ConcreteTypeTag[scala.AnyVal](AnyValTpe, ClassTag.AnyVal.erasure) { private def readResolve() = ConcreteTypeTag.AnyVal } + val AnyRef : ConcreteTypeTag[scala.AnyRef] = new ConcreteTypeTag[scala.AnyRef](AnyRefTpe, ClassTag.AnyRef.erasure) { private def readResolve() = ConcreteTypeTag.AnyRef } + val Nothing : ConcreteTypeTag[scala.Nothing] = new ConcreteTypeTag[scala.Nothing](NothingTpe, ClassTag.Nothing.erasure) { private def readResolve() = ConcreteTypeTag.Nothing } + val Null : ConcreteTypeTag[scala.Null] = new ConcreteTypeTag[scala.Null](NullTpe, ClassTag.Null.erasure) { private def readResolve() = ConcreteTypeTag.Null } + val String : ConcreteTypeTag[java.lang.String] = new ConcreteTypeTag[java.lang.String](StringTpe, ClassTag.String.erasure) { private def readResolve() = ConcreteTypeTag.String } + + def apply[T](tpe: Type, erasure: jClass[_] = null): ConcreteTypeTag[T] = tpe match { case ByteTpe => ConcreteTypeTag.Byte.asInstanceOf[ConcreteTypeTag[T]] case ShortTpe => ConcreteTypeTag.Short.asInstanceOf[ConcreteTypeTag[T]] @@ -163,17 +170,17 @@ trait TypeTags { self: Universe => case NothingTpe => ConcreteTypeTag.Nothing.asInstanceOf[ConcreteTypeTag[T]] case NullTpe => ConcreteTypeTag.Null.asInstanceOf[ConcreteTypeTag[T]] case StringTpe => ConcreteTypeTag.String.asInstanceOf[ConcreteTypeTag[T]] - case _ => new ConcreteTypeTag[T](tpe) {} + case _ => new ConcreteTypeTag[T](tpe, erasure) {} } def unapply[T](ttag: TypeTag[T]): Option[Type] = if (ttag.isConcrete) Some(ttag.tpe) else None - implicit def toClassTag[T](ttag: rm.ConcreteTypeTag[T]): ClassTag[T] = ClassTag[T](rm.typeToClass(ttag.tpe.erasure)) + implicit def toClassTag[T](ttag: rm.ConcreteTypeTag[T]): ClassTag[T] = ClassTag[T](ttag) implicit def toDeprecatedManifestApis[T](ttag: rm.ConcreteTypeTag[T]): DeprecatedManifestApis[T] = new DeprecatedManifestApis[T](ttag) // this class should not be used directly in client code - class DeprecatedManifestApis[T](ttag: rm.ConcreteTypeTag[T]) extends DeprecatedClassManifestApis[T](toClassTag(ttag)) { + class DeprecatedManifestApis[T](ttag: rm.ConcreteTypeTag[T]) extends ClassTag.DeprecatedClassManifestApis[T](toClassTag(ttag)) { @deprecated("Use `tpe` to analyze the underlying type", "2.10.0") def <:<(that: Manifest[_]): Boolean = ttag.tpe <:< that.tpe @@ -183,6 +190,49 @@ trait TypeTags { self: Universe => @deprecated("Use `tpe` to analyze the type arguments", "2.10.0") override def typeArguments: List[Manifest[_]] = ttag.tpe.typeArguments map (targ => rm.ConcreteTypeTag(targ)) } + + /** Manifest for the singleton type `value.type'. */ + @deprecated("Manifests aka type tags now support arbitrary types. Build a manifest directly from the type instead", "2.10.0") + def singleType[T <: AnyRef](value: AnyRef): Manifest[T] = Manifest[T](???, value.getClass) + + /** Manifest for the class type `clazz[args]', where `clazz' is + * a top-level or static class. + * @note This no-prefix, no-arguments case is separate because we + * it's called from ScalaRunTime.boxArray itself. If we + * pass varargs as arrays into this, we get an infinitely recursive call + * to boxArray. (Besides, having a separate case is more efficient) + */ + @deprecated("Manifests aka type tags now support arbitrary types. Build a manifest directly from the type instead", "2.10.0") + def classType[T](clazz: Predef.Class[_]): Manifest[T] = Manifest[T](???, clazz) + + /** Manifest for the class type `clazz', where `clazz' is + * a top-level or static class and args are its type arguments. */ + @deprecated("Manifests aka type tags now support arbitrary types. Build a manifest directly from the type instead", "2.10.0") + def classType[T](clazz: Predef.Class[T], arg1: Manifest[_], args: Manifest[_]*): Manifest[T] = Manifest[T](???, clazz) + + /** Manifest for the class type `clazz[args]', where `clazz' is + * a class with non-package prefix type `prefix` and type arguments `args`. + */ + @deprecated("Manifests aka type tags now support arbitrary types. Build a manifest directly from the type instead", "2.10.0") + def classType[T](prefix: Manifest[_], clazz: Predef.Class[_], args: Manifest[_]*): Manifest[T] = Manifest[T](???, clazz) + + @deprecated("Manifests aka type tags now support arbitrary types. Build a manifest directly from the type instead", "2.10.0") + def arrayType[T](arg: Manifest[_]): Manifest[Array[T]] = Manifest[Array[T]](???, arg.asInstanceOf[Manifest[T]].arrayManifest.erasure) + + /** Manifest for the abstract type `prefix # name'. `upperBound' is not + * strictly necessary as it could be obtained by reflection. It was + * added so that erasure can be calculated without reflection. */ + @deprecated("Manifests aka type tags now support arbitrary types. Build a manifest directly from the type instead", "2.10.0") + def abstractType[T](prefix: Manifest[_], name: String, clazz: Predef.Class[_], args: Manifest[_]*): Manifest[T] = Manifest[T](???, clazz) + + /** Manifest for the unknown type `_ >: L <: U' in an existential. + */ + @deprecated("Manifests aka type tags now support arbitrary types. Build a manifest directly from the type instead", "2.10.0") + def wildcardType[T](lowerBound: Manifest[_], upperBound: Manifest[_]): Manifest[T] = Manifest[T](???, upperBound.erasure) + + /** Manifest for the intersection type `parents_0 with ... with parents_n'. */ + @deprecated("Manifests aka type tags now support arbitrary types. Build a manifest directly from the type instead", "2.10.0") + def intersectionType[T](parents: Manifest[_]*): Manifest[T] = Manifest[T](???, parents.head.erasure) } // incantations for summoning diff --git a/src/library/scala/reflect/api/Types.scala b/src/library/scala/reflect/api/Types.scala index 5e1c1af2fe..4cb5609166 100755 --- a/src/library/scala/reflect/api/Types.scala +++ b/src/library/scala/reflect/api/Types.scala @@ -53,14 +53,26 @@ trait Types { self: Universe => */ def typeArguments: List[Type] + /** For a (potentially wrapped) poly type, its type parameters, + * the empty list for all other types */ + def typeParams: List[Symbol] + /** Is this type a type constructor that is missing its type arguments? */ def isHigherKinded: Boolean // !!! This should be called "isTypeConstructor", no? - /** Does this type refer to abstract types or is an abstract type? + /** Returns the corresponding type constructor (e.g. List for List[T] or List[String]) + */ + def typeConstructor: Type + + /** Does this type refer to spliceable types or is a spliceable type? */ def isConcrete: Boolean + /** Is this type an abstract type that needs to be resolved? + */ + def isSpliceable: Boolean + /** * Expands type aliases and converts higher-kinded TypeRefs to PolyTypes. * Functions on types are also implemented as PolyTypes. diff --git a/src/library/scala/reflect/makro/Reifiers.scala b/src/library/scala/reflect/makro/Reifiers.scala index d690df6aee..b9e82e0387 100644 --- a/src/library/scala/reflect/makro/Reifiers.scala +++ b/src/library/scala/reflect/makro/Reifiers.scala @@ -48,6 +48,10 @@ trait Reifiers { */ def reifyType(prefix: Tree, tpe: Type, dontSpliceAtTopLevel: Boolean = false, requireConcreteTypeTag: Boolean = false): Tree + /** Given a type, generate a tree that when compiled and executed produces the erasure of the original type. + */ + def reifyErasure(tpe: Type): Tree + /** Undoes reification of a tree. * * This reversion doesn't simply restore the original tree (that would lose the context of reification), diff --git a/src/library/scala/reflect/makro/internal/Utils.scala b/src/library/scala/reflect/makro/internal/Utils.scala index db658fd637..604bba10b6 100644 --- a/src/library/scala/reflect/makro/internal/Utils.scala +++ b/src/library/scala/reflect/makro/internal/Utils.scala @@ -55,49 +55,22 @@ package internal { NothingClass.asType -> newTermName("Nothing"), NullClass.asType -> newTermName("Null")) - def materializeClassTag(prefix: Tree, tpe: Type): Tree = { - val typetagInScope = c.inferImplicitValue(appliedType(typeRef(prefix.tpe, ConcreteTypeTagClass, Nil), List(tpe))) - def typetagIsSynthetic(tree: Tree) = tree.isInstanceOf[Block] || (tree exists (sub => sub.symbol == TypeTagModule || sub.symbol == ConcreteTypeTagModule)) - typetagInScope match { - case success if !success.isEmpty && !typetagIsSynthetic(success) => - val factory = TypeApply(Select(Ident(ClassTagModule), newTermName("apply")), List(TypeTree(tpe))) - Apply(factory, List(Select(typetagInScope, newTermName("tpe")))) - case _ => - val result = - tpe match { - case coreTpe if coreTags contains coreTpe => - Select(Ident(ClassTagModule), coreTags(coreTpe)) - case _ => - if (tpe.typeSymbol == ArrayClass) { - val componentTpe = tpe.typeArguments(0) - val classtagInScope = c.inferImplicitValue(appliedType(typeRef(NoPrefix, ClassTagClass, Nil), List(componentTpe))) - val componentTag = classtagInScope orElse materializeClassTag(prefix, componentTpe) - Select(componentTag, newTermName("wrap")) - } else { - // [Eugene] what's the intended behavior? there's no spec on ClassManifests - // for example, should we ban Array[T] or should we tag them with Array[AnyRef]? - // if its the latter, what should be the result of tagging Array[T] where T <: Int? - if (tpe.typeSymbol.isAbstractType) fail("tpe is an abstract type") - val erasure = - if (tpe.typeSymbol.isDerivedValueClass) tpe // [Eugene to Martin] is this correct? - else tpe.erasure.normalize // necessary to deal with erasures of HK types - val factory = TypeApply(Select(Ident(ClassTagModule), newTermName("apply")), List(TypeTree(tpe))) - Apply(factory, List(TypeApply(Ident(newTermName("classOf")), List(TypeTree(erasure))))) - } - } - try c.typeCheck(result) - catch { case terr @ c.TypeError(pos, msg) => fail(terr) } - } - } + def materializeClassTag(prefix: Tree, tpe: Type): Tree = + materializeTag(prefix, tpe, ClassTagModule, c.reifyErasure(tpe)) def materializeTypeTag(prefix: Tree, tpe: Type, requireConcreteTypeTag: Boolean): Tree = { val tagModule = if (requireConcreteTypeTag) ConcreteTypeTagModule else TypeTagModule + materializeTag(prefix, tpe, tagModule, c.reifyType(prefix, tpe, dontSpliceAtTopLevel = true, requireConcreteTypeTag = requireConcreteTypeTag)) + } + + private def materializeTag(prefix: Tree, tpe: Type, tagModule: Symbol, materializer: => Tree): Tree = { val result = tpe match { case coreTpe if coreTags contains coreTpe => - Select(Select(prefix, tagModule.name), coreTags(coreTpe)) + val ref = if (tagModule.owner.isPackageClass) Ident(tagModule) else Select(prefix, tagModule.name) + Select(ref, coreTags(coreTpe)) case _ => - try c.reifyType(prefix, tpe, dontSpliceAtTopLevel = true, requireConcreteTypeTag = requireConcreteTypeTag) + try materializer catch { case ex: Throwable => // [Eugene] cannot pattern match on an abstract type, so had to do this diff --git a/src/library/scala/reflect/package.scala b/src/library/scala/reflect/package.scala index 6f40a3ac3e..0958f2ce9a 100644 --- a/src/library/scala/reflect/package.scala +++ b/src/library/scala/reflect/package.scala @@ -11,62 +11,21 @@ package object reflect { // initialization, but in response to a doomed attempt to utilize it. // todo. default mirror (a static object) might become a source for memory leaks (because it holds a strong reference to a classloader)! - lazy val mirror: api.Mirror = mkMirror(defaultReflectionClassLoader) + lazy val mirror: api.Mirror = + try mkMirror(defaultReflectionClassLoader) + catch { + case ex: UnsupportedOperationException => + new DummyMirror(defaultReflectionClassLoader) + } - private def mirrorDiagnostics(cl: ClassLoader): String = """ + private[scala] def mirrorDiagnostics(cl: ClassLoader): String = """ | | This error has happened because `scala.reflect.runtime.package` located in | scala-compiler.jar cannot be loaded. Classloader you are using is: | %s. | - | In Scala 2.10.0 M3, scala-compiler.jar is required to be on the classpath - | for manifests and type tags to function. This will change in the final release, - | but for now you need to adjust your scripts or build system to proceed. - | Here are the instructions for some of the situations that might be relevant. - | - | If you compile your application directly from the command line - | or a hand-rolled script, this is a bug. Please, report it. - | - | If you compile your application with Maven using the maven-scala plugin, - | set its "fork" configuration entry to "false: - | - | <plugin> - | <groupId>org.scala-tools</groupId> - | <artifactId>maven-scala-plugin</artifactId> - | <version>2.15.0</version> - | <executions> - | <execution> - | <goals> - | ... - | </goals> - | <configuration> - | <fork>false</fork> - | ... - | </configuration> - | </execution> - | </executions> - | </plugin> - | - | If you compile your application with SBT, - | <to be implemented: release SBT for 2.10.0 M3> - | - | If you compile your application in Scala IDE, - | <to be implemented: release Scala IDE for 2.10.0 M3>. - | - | If you launch your application directly from the command line - | or a hand-rolled script, add `scala-compiler.jar` to the classpath: - | - | scalac HelloWorld.scala - | scala HelloWorld -cp path/to/scala-compiler.jar - | - | If you launch your application with Maven using the maven-scala plugin, - | set its "fork" configuration entry to "false as shown above. - | - | If you launch your application with SBT, make sure that you use - | <to be implemented: release SBT for 2.10.0 M3> - | - | If you launch your application in Scala IDE, make sure that both scala-library.jar and scala-compiler.jar - | are in bootstrap entries on the classpath of your launch configuration. + | For the instructions for some of the situations that might be relevant + | visit our knowledge base at https://gist.github.com/2391081. """.stripMargin('|').format(show(cl)) def mkMirror(classLoader: ClassLoader): api.Mirror = { @@ -106,7 +65,7 @@ package object reflect { @deprecated("Use `@scala.reflect.ConcreteTypeTag` instead", "2.10.0") lazy val Manifest = ConcreteTypeTag @deprecated("NoManifest is no longer supported, and using it may lead to incorrect results, Use `@scala.reflect.TypeTag` instead", "2.10.0") - object NoManifest extends OptManifest[Nothing](scala.reflect.mirror.definitions.NothingClass.asType) with Serializable + object NoManifest extends OptManifest[Nothing](scala.reflect.mirror.TypeTag.Nothing.tpe) // ClassTag class is defined separately from the mirror type TypeTag[T] = scala.reflect.mirror.TypeTag[T] |