1
1
/* __ *\
2
2
** ________ ___ / / ___ Scala API **
3
- ** / __/ __// _ | / / / _ | (c) 2007-2008 , LAMP/EPFL **
3
+ ** / __/ __// _ | / / / _ | (c) 2007-2009 , LAMP/EPFL **
4
4
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
5
5
** /____/\___/_/ |_/____/_/ | | **
6
6
** |/ **
@@ -22,7 +22,8 @@ package scala.reflect
22
22
* these operators should be on the unerased type.
23
23
* </p>
24
24
*/
25
- @ serializable trait Manifest [T ] {
25
+ @ serializable
26
+ trait Manifest [T ] {
26
27
27
28
/** A class representing the type U to which T would be erased. Note
28
29
* that there is no subtyping relationship between T and U. */
@@ -75,7 +76,7 @@ object Manifest {
75
76
76
77
/** Manifest for the singleton type `value.type'. */
77
78
def singleType [T ](value : Any ): Manifest [T ] =
78
- new Manifest [T ] with java.io. Serializable {
79
+ new ( Manifest [T ] @ serializable) {
79
80
lazy val erasure =
80
81
value match {
81
82
case anyRefValue : AnyRef => anyRefValue.getClass
@@ -87,55 +88,68 @@ object Manifest {
87
88
/** Manifest for the class type `clazz', where `clazz' is
88
89
* a top-level or static class. */
89
90
def classType [T ](clazz : Predef .Class [T ]): Manifest [T ] =
90
- new Manifest [T ] with java.io. Serializable {
91
+ new ( Manifest [T ] @ serializable) {
91
92
val erasure = clazz
92
93
override lazy val toString = erasure.getName
93
94
}
94
95
95
96
/** Manifest for the class type `clazz[args]', where `clazz' is
96
97
* a top-level or static class. */
97
98
def classType [T ](clazz : Predef .Class [_], args : Manifest [_]* ): Manifest [T ] =
98
- new Manifest [T ] with java.io. Serializable {
99
+ new ( Manifest [T ] @ serializable) {
99
100
val erasure = clazz
100
101
val typeArguments : Seq [Manifest [_]] = args
101
- override lazy val toString = erasure.getName + typeArguments.mkString(" [" , " , " , " ]" )
102
+ override def <:< (that : Manifest [_]): Boolean = {
103
+ try {
104
+ val meth = that.getClass().getMethod(" typeArguments" , null )
105
+ val args1 = meth.invoke(that, null ).asInstanceOf [Array [Manifest [_]]]
106
+ super .<:< (that) && args.equalsWith(args1)((x, y) => x <:< y)
107
+ } catch {
108
+ case _ => false
109
+ }
110
+ }
111
+ override lazy val toString =
112
+ (if (erasure.isArray) " Array" else erasure.getName) +
113
+ typeArguments.mkString(" [" , " , " , " ]" )
102
114
}
103
115
104
116
/** Manifest for the class type `prefix # clazz'. */
105
117
def classType [T ](prefix : Manifest [_], clazz : Predef .Class [_]): Manifest [T ] =
106
- new Manifest [T ] with java.io. Serializable {
118
+ new ( Manifest [T ] @ serializable) {
107
119
val erasure = clazz
108
120
override lazy val toString = prefix.toString + " #" + erasure.getName
109
121
}
110
122
111
123
/** Manifest for the class type `prefix # clazz[args]'. */
112
124
def classType [T ](prefix : Manifest [_], clazz : Predef .Class [_], args : Manifest [_]* ): Manifest [T ] =
113
- new Manifest [T ] with java.io. Serializable {
125
+ new ( Manifest [T ] @ serializable) {
114
126
val erasure = clazz
115
127
val typeArguments : Seq [Manifest [_]] = args
116
- override lazy val toString = prefix.toString + " #" + erasure.getName + typeArguments.mkString(" [" , " , " , " ]" )
128
+ override lazy val toString =
129
+ prefix.toString + " #" + erasure.getName + typeArguments.mkString(" [" , " , " , " ]" )
117
130
}
118
131
119
132
/** Manifest for the abstract type `prefix # name'. `upperBound' is not
120
133
* strictly necessary as it could be obtained by reflection. It was
121
134
* added so that erasure can be calculated without reflection. */
122
135
def abstractType [T ](prefix : Manifest [_], name : String , upperBound : Manifest [_]): Manifest [T ] =
123
- new Manifest [T ] with java.io. Serializable {
136
+ new ( Manifest [T ] @ serializable) {
124
137
lazy val erasure = upperBound.erasure
125
138
override lazy val toString = prefix.toString + " #" + name
126
139
}
127
140
128
141
/** Manifest for the abstract type `prefix # name[args]'. */
129
142
def abstractType [T ](prefix : Manifest [_], name : String , upperBound : Manifest [_], args : Manifest [_]* ): Manifest [T ] =
130
- new Manifest [T ] with java.io. Serializable {
143
+ new ( Manifest [T ] @ serializable) {
131
144
lazy val erasure = upperBound.erasure
132
145
val typeArguments : Seq [Manifest [_]] = args
133
- override lazy val toString = prefix.toString + " #" + name + typeArguments.mkString(" [" , " , " , " ]" )
146
+ override lazy val toString =
147
+ prefix.toString + " #" + name + typeArguments.mkString(" [" , " , " , " ]" )
134
148
}
135
149
136
150
/** Manifest for the intersection type `parents_0 with ... with parents_n'. */
137
151
def intersectionType [T ](parents : Manifest [_]* ): Manifest [T ] =
138
- new Manifest [T ] with java.io. Serializable {
152
+ new ( Manifest [T ] @ serializable) {
139
153
lazy val erasure = parents.first.erasure
140
154
override lazy val toString = parents.mkString(" with " )
141
155
}
0 commit comments