@@ -142,12 +142,13 @@ trait Definitions extends reflect.api.StandardDefinitions {
142
142
lazy val EmptyPackage = RootClass .newPackage(NoPosition , nme.EMPTY_PACKAGE_NAME ).setFlag(FINAL )
143
143
lazy val EmptyPackageClass = EmptyPackage .moduleClass
144
144
145
- lazy val JavaLangPackage = getModule(sn.JavaLang )
146
- lazy val ScalaPackage = getModule(" scala" )
147
- lazy val ScalaPackageClass = ScalaPackage .tpe.typeSymbol
145
+ lazy val JavaLangPackage = getModule(sn.JavaLang )
146
+ lazy val JavaLangPackageClass = JavaLangPackage .moduleClass
147
+ lazy val ScalaPackage = getModule(nme.scala_)
148
+ lazy val ScalaPackageClass = ScalaPackage .moduleClass
148
149
149
150
lazy val RuntimePackage = getModule(" scala.runtime" )
150
- lazy val RuntimePackageClass = RuntimePackage .tpe.typeSymbol
151
+ lazy val RuntimePackageClass = RuntimePackage .moduleClass
151
152
152
153
// convenient one-argument parameter lists
153
154
lazy val anyparam = List (AnyClass .typeConstructor)
@@ -156,21 +157,7 @@ trait Definitions extends reflect.api.StandardDefinitions {
156
157
157
158
// private parameter conveniences
158
159
private def booltype = BooleanClass .typeConstructor
159
- private def boolparam = List (booltype)
160
- private def bytetype = ByteClass .typeConstructor
161
- private def byteparam = List (bytetype)
162
- private def shorttype = ShortClass .typeConstructor
163
- private def shortparam = List (shorttype)
164
160
private def inttype = IntClass .typeConstructor
165
- private def intparam = List (inttype)
166
- private def longtype = LongClass .typeConstructor
167
- private def longparam = List (longtype)
168
- private def floattype = FloatClass .typeConstructor
169
- private def floatparam = List (floattype)
170
- private def doubletype = DoubleClass .typeConstructor
171
- private def doubleparam = List (doubletype)
172
- private def chartype = CharClass .typeConstructor
173
- private def charparam = List (chartype)
174
161
private def stringtype = StringClass .typeConstructor
175
162
176
163
// top types
@@ -209,19 +196,19 @@ trait Definitions extends reflect.api.StandardDefinitions {
209
196
lazy val ElidableMethodClass = getClass(" scala.annotation.elidable" )
210
197
lazy val ImplicitNotFoundClass = getClass(" scala.annotation.implicitNotFound" )
211
198
lazy val VarargsClass = getClass(" scala.annotation.varargs" )
212
- lazy val FieldTargetClass = getClass(" scala.annotation.target .field" )
213
- lazy val GetterTargetClass = getClass(" scala.annotation.target .getter" )
214
- lazy val SetterTargetClass = getClass(" scala.annotation.target .setter" )
215
- lazy val BeanGetterTargetClass = getClass(" scala.annotation.target .beanGetter" )
216
- lazy val BeanSetterTargetClass = getClass(" scala.annotation.target .beanSetter" )
217
- lazy val ParamTargetClass = getClass(" scala.annotation.target .param" )
199
+ lazy val FieldTargetClass = getClass(" scala.beans.meta .field" )
200
+ lazy val GetterTargetClass = getClass(" scala.beans.meta .getter" )
201
+ lazy val SetterTargetClass = getClass(" scala.beans.meta .setter" )
202
+ lazy val BeanGetterTargetClass = getClass(" scala.beans.meta .beanGetter" )
203
+ lazy val BeanSetterTargetClass = getClass(" scala.beans.meta .beanSetter" )
204
+ lazy val ParamTargetClass = getClass(" scala.beans.meta .param" )
218
205
lazy val ScalaInlineClass = getClass(" scala.inline" )
219
206
lazy val ScalaNoInlineClass = getClass(" scala.noinline" )
220
207
lazy val SpecializedClass = getClass(" scala.specialized" )
221
208
lazy val BridgeClass = getClass(" scala.annotation.bridge" )
222
209
223
210
// fundamental reference classes
224
- lazy val ScalaObjectClass = getClass( " scala .ScalaObject" )
211
+ lazy val ScalaObjectClass = getMember( ScalaPackageClass , tpnme .ScalaObject )
225
212
lazy val PartialFunctionClass = getClass(" scala.PartialFunction" )
226
213
lazy val SymbolClass = getClass(" scala.Symbol" )
227
214
lazy val StringClass = getClass(sn.String )
@@ -233,9 +220,17 @@ trait Definitions extends reflect.api.StandardDefinitions {
233
220
// fundamental modules
234
221
lazy val SysPackage = getPackageObject(" scala.sys" )
235
222
def Sys_error = getMember(SysPackage , nme.error)
223
+
224
+ // Modules whose members are in the default namespace
225
+ lazy val UnqualifiedModules = List (PredefModule , ScalaPackage , JavaLangPackage )
226
+ // Those modules and their module classes
227
+ lazy val UnqualifiedOwners = UnqualifiedModules .toSet ++ UnqualifiedModules .map(_.moduleClass)
228
+
236
229
lazy val PredefModule : Symbol = getModule(" scala.Predef" )
237
- lazy val PredefModuleClass = PredefModule .tpe.typeSymbol
238
- def Predef_AnyRef = getMember(PredefModule , " AnyRef" ) // used by the specialization annotation
230
+ lazy val PredefModuleClass = PredefModule .moduleClass
231
+ // Note: this is not the type alias AnyRef, it's a val defined in Predef
232
+ // used by the @specialize annotation.
233
+ def Predef_AnyRef = getMember(PredefModule , nme.AnyRef )
239
234
def Predef_classOf = getMember(PredefModule , nme.classOf )
240
235
def Predef_identity = getMember(PredefModule , nme.identity)
241
236
def Predef_conforms = getMember(PredefModule , nme.conforms)
@@ -297,6 +292,12 @@ trait Definitions extends reflect.api.StandardDefinitions {
297
292
def isVarArgsList (params : List [Symbol ]) = params.nonEmpty && isRepeatedParamType(params.last.tpe)
298
293
def isVarArgTypes (formals : List [Type ]) = formals.nonEmpty && isRepeatedParamType(formals.last)
299
294
295
+ def hasRepeatedParam (tp : Type ): Boolean = tp match {
296
+ case MethodType (formals, restpe) => isScalaVarArgs(formals) || hasRepeatedParam(restpe)
297
+ case PolyType (_, restpe) => hasRepeatedParam(restpe)
298
+ case _ => false
299
+ }
300
+
300
301
def isPrimitiveArray (tp : Type ) = tp match {
301
302
case TypeRef (_, ArrayClass , arg :: Nil ) => isValueClass(arg.typeSymbol)
302
303
case _ => false
@@ -420,6 +421,7 @@ trait Definitions extends reflect.api.StandardDefinitions {
420
421
lazy val ProductClass = mkArityArray(" Product" , MaxProductArity )
421
422
lazy val FunctionClass = mkArityArray(" Function" , MaxFunctionArity , 0 )
422
423
lazy val AbstractFunctionClass = mkArityArray(" runtime.AbstractFunction" , MaxFunctionArity , 0 )
424
+ lazy val isProductNClass = ProductClass .toSet
423
425
424
426
def tupleField (n : Int , j : Int ) = getMember(TupleClass (n), " _" + j)
425
427
def isTupleType (tp : Type ): Boolean = isTupleType(tp, false )
@@ -454,11 +456,7 @@ trait Definitions extends reflect.api.StandardDefinitions {
454
456
def productProj (n : Int , j : Int ): Symbol = productProj(ProductClass (n), j)
455
457
456
458
/** returns true if this type is exactly ProductN[T1,...,Tn], not some subclass */
457
- def isExactProductType (tp : Type ): Boolean = cond(tp.normalize) {
458
- case TypeRef (_, sym, elems) =>
459
- val len = elems.length
460
- len <= MaxProductArity && sym == ProductClass (len)
461
- }
459
+ def isExactProductType (tp : Type ): Boolean = isProductNClass(tp.typeSymbol)
462
460
463
461
def productType (elems : List [Type ]) = {
464
462
if (elems.isEmpty) UnitClass .tpe
@@ -472,15 +470,16 @@ trait Definitions extends reflect.api.StandardDefinitions {
472
470
}
473
471
}
474
472
475
- /** if tpe <: ProductN[T1,...,TN], returns Some((T1,...,TN)) else None */
476
- def getProductArgs (tpe : Type ): Option [List [Type ]] =
477
- tpe.baseClasses collectFirst { case x if isExactProductType(x.tpe) => tpe.baseType(x).typeArgs }
473
+ /** if tpe <: ProductN[T1,...,TN], returns List(T1,...,TN) else Nil */
474
+ def getProductArgs (tpe : Type ): List [Type ] = tpe.baseClasses find isProductNClass match {
475
+ case Some (x) => tpe.baseType(x).typeArgs
476
+ case _ => Nil
477
+ }
478
478
479
- def unapplyUnwrap (tpe: Type ) = (tpe match {
480
- case PolyType (_,MethodType (_, res)) => res
481
- case MethodType (_, res) => res
482
- case tpe => tpe
483
- }).normalize
479
+ def unapplyUnwrap (tpe: Type ) = tpe.finalResultType.normalize match {
480
+ case RefinedType (p :: _, _) => p.normalize
481
+ case tp => tp
482
+ }
484
483
485
484
def functionApply (n : Int ) = getMember(FunctionClass (n), nme.apply)
486
485
def functionType (formals : List [Type ], restpe : Type ) = {
@@ -514,8 +513,8 @@ trait Definitions extends reflect.api.StandardDefinitions {
514
513
case _ => NoType
515
514
}
516
515
517
- def seqType (arg : Type ) = typeRef (SeqClass .typeConstructor.prefix, SeqClass , List (arg))
518
- def arrayType (arg : Type ) = typeRef (ArrayClass .typeConstructor.prefix, ArrayClass , List (arg))
516
+ def seqType (arg : Type ) = appliedType (SeqClass .typeConstructor, List (arg))
517
+ def arrayType (arg : Type ) = appliedType (ArrayClass .typeConstructor, List (arg))
519
518
def byNameType (arg : Type ) = appliedType(ByNameParamClass .typeConstructor, List (arg))
520
519
521
520
def ClassType (arg : Type ) =
@@ -635,7 +634,7 @@ trait Definitions extends reflect.api.StandardDefinitions {
635
634
getPackageObject(fullname).companionClass
636
635
637
636
def getPackageObject (fullname : Name ): Symbol =
638
- getModuleOrClass (fullname.toTermName ).info. member(newTermName( " package " ))
637
+ getModule (fullname).info member nme. PACKAGE
639
638
640
639
def getModule (fullname : Name ): Symbol =
641
640
getModuleOrClass(fullname.toTermName)
@@ -666,7 +665,9 @@ trait Definitions extends reflect.api.StandardDefinitions {
666
665
667
666
private def getModuleOrClass (path : Name , len : Int ): Symbol = {
668
667
val point = path lastPos('.' , len - 1 )
669
- val owner = if (point > 0 ) getModuleOrClass(path.toTermName, point) else RootClass
668
+ val owner =
669
+ if (point > 0 ) getModuleOrClass(path.toTermName, point)
670
+ else RootClass
670
671
val name = path subName (point + 1 , len)
671
672
val sym = owner.info member name
672
673
val result = if (path.isTermName) sym.suchThat(_ hasFlag MODULE ) else sym
@@ -750,6 +751,9 @@ trait Definitions extends reflect.api.StandardDefinitions {
750
751
/** Is symbol a phantom class for which no runtime representation exists? */
751
752
lazy val isPhantomClass = Set [Symbol ](AnyClass , AnyValClass , NullClass , NothingClass )
752
753
754
+ /** Is the symbol that of a parent which is added during parsing? */
755
+ lazy val isPossibleSyntheticParent = ProductClass .toSet[Symbol ] + ProductRootClass + SerializableClass
756
+
753
757
private lazy val scalaValueClassesSet = ScalaValueClasses .toSet
754
758
private lazy val boxedValueClassesSet = boxedClass.values.toSet + BoxedUnitClass
755
759
0 commit comments