diff options
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/reflect/base/AnnotationInfos.scala | 44 | ||||
-rw-r--r-- | src/library/scala/reflect/base/Annotations.scala | 46 | ||||
-rw-r--r-- | src/library/scala/reflect/base/Attachments.scala | 11 | ||||
-rw-r--r-- | src/library/scala/reflect/base/Base.scala | 38 | ||||
-rw-r--r-- | src/library/scala/reflect/base/BuildUtils.scala | 2 | ||||
-rw-r--r-- | src/library/scala/reflect/base/Trees.scala | 56 | ||||
-rw-r--r-- | src/library/scala/reflect/base/Types.scala | 4 | ||||
-rw-r--r-- | src/library/scala/reflect/base/Universe.scala | 2 |
8 files changed, 97 insertions, 106 deletions
diff --git a/src/library/scala/reflect/base/AnnotationInfos.scala b/src/library/scala/reflect/base/AnnotationInfos.scala deleted file mode 100644 index f03644deef..0000000000 --- a/src/library/scala/reflect/base/AnnotationInfos.scala +++ /dev/null @@ -1,44 +0,0 @@ -package scala.reflect -package base - -trait AnnotationInfos { self: Universe => - - type AnnotationInfo >: Null <: AnyRef - implicit val AnnotationInfoTag: ClassTag[AnnotationInfo] - val AnnotationInfo: AnnotationInfoExtractor - - abstract class AnnotationInfoExtractor { - def apply(atp: Type, args: List[Tree], assocs: List[(Name, ClassfileAnnotArg)]): AnnotationInfo - def unapply(info: AnnotationInfo): Option[(Type, List[Tree], List[(Name, ClassfileAnnotArg)])] - } - - type ClassfileAnnotArg >: Null <: AnyRef - implicit val ClassfileAnnotArgTag: ClassTag[ClassfileAnnotArg] - - type LiteralAnnotArg >: Null <: AnyRef with ClassfileAnnotArg - implicit val LiteralAnnotArgTag: ClassTag[LiteralAnnotArg] - val LiteralAnnotArg: LiteralAnnotArgExtractor - - abstract class LiteralAnnotArgExtractor { - def apply(const: Constant): LiteralAnnotArg - def unapply(arg: LiteralAnnotArg): Option[Constant] - } - - type ArrayAnnotArg >: Null <: AnyRef with ClassfileAnnotArg - implicit val ArrayAnnotArgTag: ClassTag[ArrayAnnotArg] - val ArrayAnnotArg: ArrayAnnotArgExtractor - - abstract class ArrayAnnotArgExtractor { - def apply(args: Array[ClassfileAnnotArg]): ArrayAnnotArg - def unapply(arg: ArrayAnnotArg): Option[Array[ClassfileAnnotArg]] - } - - type NestedAnnotArg >: Null <: AnyRef with ClassfileAnnotArg - implicit val NestedAnnotArgTag: ClassTag[NestedAnnotArg] - val NestedAnnotArg: NestedAnnotArgExtractor - - abstract class NestedAnnotArgExtractor { - def apply(annInfo: AnnotationInfo): NestedAnnotArg - def unapply(arg: NestedAnnotArg): Option[AnnotationInfo] - } -}
\ No newline at end of file diff --git a/src/library/scala/reflect/base/Annotations.scala b/src/library/scala/reflect/base/Annotations.scala new file mode 100644 index 0000000000..e3453b1cdf --- /dev/null +++ b/src/library/scala/reflect/base/Annotations.scala @@ -0,0 +1,46 @@ +package scala.reflect +package base + +import scala.collection.immutable.ListMap + +trait Annotations { self: Universe => + + type Annotation >: Null <: AnyRef + implicit val AnnotationTag: ClassTag[Annotation] + val Annotation: AnnotationExtractor + + abstract class AnnotationExtractor { + def apply(tpe: Type, scalaArgs: List[Tree], javaArgs: ListMap[Name, JavaArgument]): Annotation + def unapply(ann: Annotation): Option[(Type, List[Tree], ListMap[Name, JavaArgument])] + } + + type JavaArgument >: Null <: AnyRef + implicit val JavaArgumentTag: ClassTag[JavaArgument] + + type LiteralArgument >: Null <: AnyRef with JavaArgument + implicit val LiteralArgumentTag: ClassTag[LiteralArgument] + val LiteralArgument: LiteralArgumentExtractor + + abstract class LiteralArgumentExtractor { + def apply(value: Constant): LiteralArgument + def unapply(arg: LiteralArgument): Option[Constant] + } + + type ArrayArgument >: Null <: AnyRef with JavaArgument + implicit val ArrayArgumentTag: ClassTag[ArrayArgument] + val ArrayArgument: ArrayArgumentExtractor + + abstract class ArrayArgumentExtractor { + def apply(args: Array[JavaArgument]): ArrayArgument + def unapply(arg: ArrayArgument): Option[Array[JavaArgument]] + } + + type NestedArgument >: Null <: AnyRef with JavaArgument + implicit val NestedArgumentTag: ClassTag[NestedArgument] + val NestedArgument: NestedArgumentExtractor + + abstract class NestedArgumentExtractor { + def apply(annotation: Annotation): NestedArgument + def unapply(arg: NestedArgument): Option[Annotation] + } +}
\ No newline at end of file diff --git a/src/library/scala/reflect/base/Attachments.scala b/src/library/scala/reflect/base/Attachments.scala index 43e870fc4f..889ac0ac14 100644 --- a/src/library/scala/reflect/base/Attachments.scala +++ b/src/library/scala/reflect/base/Attachments.scala @@ -20,15 +20,18 @@ abstract class Attachments { self => /** Gets the underlying payload */ def all: Set[Any] = Set.empty + private def matchesTag[T: ClassTag](datum: Any) = + classTag[T].runtimeClass == datum.getClass + def get[T: ClassTag]: Option[T] = - (all find (_.getClass == classTag[T].runtimeClass)).asInstanceOf[Option[T]] + (all filter matchesTag[T]).headOption.asInstanceOf[Option[T]] /** Creates a copy of this attachment with its payload updated */ - def add(attachment: Any): Attachments { type Pos = self.Pos } = - new NonemptyAttachments(this.pos, all + attachment) + def update[T: ClassTag](attachment: T): Attachments { type Pos = self.Pos } = + new NonemptyAttachments(this.pos, remove[T].all + attachment) def remove[T: ClassTag]: Attachments { type Pos = self.Pos } = { - val newAll = all filterNot (_.getClass == classTag[T].runtimeClass) + val newAll = all filterNot matchesTag[T] if (newAll.isEmpty) pos.asInstanceOf[Attachments { type Pos = self.Pos }] else new NonemptyAttachments(this.pos, newAll) } diff --git a/src/library/scala/reflect/base/Base.scala b/src/library/scala/reflect/base/Base.scala index 33582675bd..29bf2df656 100644 --- a/src/library/scala/reflect/base/Base.scala +++ b/src/library/scala/reflect/base/Base.scala @@ -5,6 +5,7 @@ import java.io.PrintWriter import scala.annotation.switch import scala.ref.WeakReference import scala.collection.mutable +import scala.collection.immutable.ListMap class Base extends Universe { self => @@ -157,7 +158,7 @@ class Base extends Universe { self => object ExistentialType extends ExistentialTypeExtractor implicit val ExistentialTypeTag = ClassTag[ExistentialType](classOf[ExistentialType]) - case class AnnotatedType(annotations: List[AnnotationInfo], underlying: Type, selfsym: Symbol) extends Type { override def typeSymbol = underlying.typeSymbol } + case class AnnotatedType(annotations: List[Annotation], underlying: Type, selfsym: Symbol) extends Type { override def typeSymbol = underlying.typeSymbol } object AnnotatedType extends AnnotatedTypeExtractor implicit val AnnotatedTypeTag = ClassTag[AnnotatedType](classOf[AnnotatedType]) @@ -249,24 +250,24 @@ class Base extends Universe { self => object Constant extends ConstantExtractor implicit val ConstantTag = ClassTag[Constant](classOf[Constant]) - case class AnnotationInfo(atp: Type, args: List[Tree], assocs: List[(Name, ClassfileAnnotArg)]) - object AnnotationInfo extends AnnotationInfoExtractor - implicit val AnnotationInfoTag = ClassTag[AnnotationInfo](classOf[AnnotationInfo]) + case class Annotation(tpe: Type, scalaArgs: List[Tree], javaArgs: ListMap[Name, JavaArgument]) + object Annotation extends AnnotationExtractor + implicit val AnnotationTag = ClassTag[Annotation](classOf[Annotation]) - abstract class ClassfileAnnotArg - implicit val ClassfileAnnotArgTag = ClassTag[ClassfileAnnotArg](classOf[ClassfileAnnotArg]) + abstract class JavaArgument + implicit val JavaArgumentTag = ClassTag[JavaArgument](classOf[JavaArgument]) - case class LiteralAnnotArg(const: Constant) extends ClassfileAnnotArg - object LiteralAnnotArg extends LiteralAnnotArgExtractor - implicit val LiteralAnnotArgTag = ClassTag[LiteralAnnotArg](classOf[LiteralAnnotArg]) + case class LiteralArgument(value: Constant) extends JavaArgument + object LiteralArgument extends LiteralArgumentExtractor + implicit val LiteralArgumentTag = ClassTag[LiteralArgument](classOf[LiteralArgument]) - case class ArrayAnnotArg(args: Array[ClassfileAnnotArg]) extends ClassfileAnnotArg - object ArrayAnnotArg extends ArrayAnnotArgExtractor - implicit val ArrayAnnotArgTag = ClassTag[ArrayAnnotArg](classOf[ArrayAnnotArg]) + case class ArrayArgument(args: Array[JavaArgument]) extends JavaArgument + object ArrayArgument extends ArrayArgumentExtractor + implicit val ArrayArgumentTag = ClassTag[ArrayArgument](classOf[ArrayArgument]) - case class NestedAnnotArg(annInfo: AnnotationInfo) extends ClassfileAnnotArg - object NestedAnnotArg extends NestedAnnotArgExtractor - implicit val NestedAnnotArgTag = ClassTag[NestedAnnotArg](classOf[NestedAnnotArg]) + case class NestedArgument(annotation: Annotation) extends JavaArgument + object NestedArgument extends NestedArgumentExtractor + implicit val NestedArgumentTag = ClassTag[NestedArgument](classOf[NestedArgument]) class Position extends Attachments { override type Pos = Position @@ -319,7 +320,7 @@ class Base extends Universe { self => def setTypeSignature[S <: Symbol](sym: S, tpe: Type): S = sym - def setAnnotations[S <: Symbol](sym: S, annots: List[AnnotationInfo]): S = sym + def setAnnotations[S <: Symbol](sym: S, annots: List[Annotation]): S = sym def flagsFromBits(bits: Long): FlagSet = bits @@ -623,10 +624,6 @@ class Base extends Universe { self => extends GenericApply object Apply extends ApplyExtractor - case class ApplyDynamic(qual: Tree, args: List[Tree]) - extends TermTree with SymTree - object ApplyDynamic extends ApplyDynamicExtractor - case class Super(qual: Tree, mix: TypeName) extends TermTree object Super extends SuperExtractor @@ -725,7 +722,6 @@ class Base extends Universe { self => implicit val GenericApplyTag = ClassTag[GenericApply](classOf[GenericApply]) implicit val TypeApplyTag = ClassTag[TypeApply](classOf[TypeApply]) implicit val ApplyTag = ClassTag[Apply](classOf[Apply]) - implicit val ApplyDynamicTag = ClassTag[ApplyDynamic](classOf[ApplyDynamic]) implicit val SuperTag = ClassTag[Super](classOf[Super]) implicit val ThisTag = ClassTag[This](classOf[This]) implicit val SelectTag = ClassTag[Select](classOf[Select]) diff --git a/src/library/scala/reflect/base/BuildUtils.scala b/src/library/scala/reflect/base/BuildUtils.scala index c4231dd515..e4710316e2 100644 --- a/src/library/scala/reflect/base/BuildUtils.scala +++ b/src/library/scala/reflect/base/BuildUtils.scala @@ -49,7 +49,7 @@ trait BuildUtils { self: Universe => /** Set symbol's annotations to given annotations `annots`. */ - def setAnnotations[S <: Symbol](sym: S, annots: List[AnnotationInfo]): S + def setAnnotations[S <: Symbol](sym: S, annots: List[Annotation]): S def flagsFromBits(bits: Long): FlagSet diff --git a/src/library/scala/reflect/base/Trees.scala b/src/library/scala/reflect/base/Trees.scala index 224965a2b7..78174f354c 100644 --- a/src/library/scala/reflect/base/Trees.scala +++ b/src/library/scala/reflect/base/Trees.scala @@ -605,10 +605,30 @@ trait Trees { self: Universe => def unapply(bind: Bind): Option[(Name, Tree)] } - /** Noone knows what this is. - * It is not idempotent w.r.t typechecking. - * Can we, please, remove it? + /** Used to represent `unapply` methods in pattern matching. * Introduced by typer, eliminated by patmat/explicitouter. + * + * For example: + * {{{ + * 2 match { case Foo(x) => x } + * }}} + * + * Is represented as: + * {{{ + * Match( + * Literal(Constant(2)), + * List( + * CaseDef( + * UnApply( + * // a dummy node that carries the type of unapplication to patmat + * // the <unapply-selector> here doesn't have an underlying symbol + * // it only has a type assigned, therefore after `resetAllAttrs` this tree is no longer typeable + * Apply(Select(Ident(Foo), newTermName("unapply")), List(Ident(newTermName("<unapply-selector>")))), + * // arguments of the unapply => nothing synthetic here + * List(Bind(newTermName("x"), Ident(nme.WILDCARD)))), + * EmptyTree, + * Ident(newTermName("x"))))) + * }}} */ type UnApply >: Null <: TermTree @@ -971,36 +991,6 @@ trait Trees { self: Universe => def unapply(apply: Apply): Option[(Tree, List[Tree])] } - /** Dynamic value application. - * In a dynamic application q.f(as) - * - q is stored in qual - * - as is stored in args - * - f is stored as the node's symbol field. - * [Eugene++] what is it used for? - * Introduced by erasure, eliminated by cleanup. - */ - type ApplyDynamic >: Null <: TermTree with SymTree - - /** A tag that preserves the identity of the `ApplyDynamic` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val ApplyDynamicTag: ClassTag[ApplyDynamic] - - /** The constructor/deconstructor for `ApplyDynamic` instances. */ - val ApplyDynamic: ApplyDynamicExtractor - - /** An extractor class to create and pattern match with syntax `ApplyDynamic(qual, args)`. - * This AST node corresponds to the following Scala code: - * - * fun(args) - * - * The symbol of an ApplyDynamic is the function symbol of `qual`, or NoSymbol, if there is none. - */ - abstract class ApplyDynamicExtractor { - def apply(qual: Tree, args: List[Tree]): ApplyDynamic - def unapply(applyDynamic: ApplyDynamic): Option[(Tree, List[Tree])] - } - /** Super reference, qual = corresponding this reference * A super reference C.super[M] is represented as Super(This(C), M). */ diff --git a/src/library/scala/reflect/base/Types.scala b/src/library/scala/reflect/base/Types.scala index b016b77f36..839c49805a 100644 --- a/src/library/scala/reflect/base/Types.scala +++ b/src/library/scala/reflect/base/Types.scala @@ -362,8 +362,8 @@ trait Types { self: Universe => * `selfSym` is a symbol representing the annotated type itself. */ abstract class AnnotatedTypeExtractor { - def apply(annotations: List[AnnotationInfo], underlying: Type, selfsym: Symbol): AnnotatedType - def unapply(tpe: AnnotatedType): Option[(List[AnnotationInfo], Type, Symbol)] + def apply(annotations: List[Annotation], underlying: Type, selfsym: Symbol): AnnotatedType + def unapply(tpe: AnnotatedType): Option[(List[Annotation], Type, Symbol)] } /** The `TypeBounds` type signature is used to indicate lower and upper type bounds diff --git a/src/library/scala/reflect/base/Universe.scala b/src/library/scala/reflect/base/Universe.scala index 18599ad092..11290401ec 100644 --- a/src/library/scala/reflect/base/Universe.scala +++ b/src/library/scala/reflect/base/Universe.scala @@ -8,7 +8,7 @@ abstract class Universe extends Symbols with Names with Trees with Constants - with AnnotationInfos + with Annotations with Positions with Exprs with TypeTags |