@@ -3,6 +3,7 @@ package core
3
3
4
4
import Periods ._ , Contexts ._ , Symbols ._ , Denotations ._ , Names ._ , Annotations ._
5
5
import Types ._ , Flags ._ , Decorators ._ , Transformers ._ , StdNames ._ , Scopes ._
6
+ import NameOps ._
6
7
import Scopes .Scope
7
8
import collection .mutable
8
9
import collection .immutable .BitSet
@@ -217,6 +218,28 @@ object SymDenotations {
217
218
/** Is this a subclass of the given class `base`? */
218
219
def isSubClass (base : Symbol )(implicit ctx : Context ) = false
219
220
221
+ /** Is this a setter? */
222
+ def isGetter = (this is Accessor ) && ! originalName.isSetterName
223
+
224
+ /** Is this a user defined "def" method? Excluded are accessors and stable values */
225
+ def isSourceMethod = this is (Method , butNot = Accessor | Stable )
226
+
227
+ /** Is this a setter? */
228
+ def isSetter = (this is Accessor ) && originalName.isSetterName
229
+
230
+ /** is this the constructor of a class? */
231
+ def isClassConstructor = name == nme.CONSTRUCTOR
232
+
233
+ /** Is this the constructor of a trait? */
234
+ def isTraitConstructor = name == nme.TRAIT_CONSTRUCTOR
235
+
236
+ /** Is this the constructor of a trait or a class */
237
+ def isConstructor = name.isConstructorName
238
+
239
+ /** Does this symbol denote the primary constructor of its enclosing class? */
240
+ final def isPrimaryConstructor (implicit ctx : Context ) =
241
+ isConstructor && owner.primaryConstructor == this
242
+
220
243
/** Is this a subclass of `base`,
221
244
* and is the denoting symbol also different from `Null` or `Nothing`?
222
245
*/
@@ -433,6 +456,9 @@ object SymDenotations {
433
456
else defn.RootClass
434
457
}
435
458
459
+ /** The primary constructor of a class or trait, NoSymbol if not applicable. */
460
+ def primaryConstructor (implicit ctx : Context ): Symbol = NoSymbol
461
+
436
462
// ----- type-related ------------------------------------------------
437
463
438
464
/** The type parameters of a class symbol, Nil for all other symbols */
@@ -441,13 +467,19 @@ object SymDenotations {
441
467
/** The type This(cls), where cls is this class, NoPrefix for all other symbols */
442
468
def thisType (implicit ctx : Context ): Type = NoPrefix
443
469
444
- /** The type representing the type constructor for this type.
470
+ /** The named typeref representing the type constructor for this type.
445
471
* @throws ClassCastException is this is not a type
446
472
*/
447
473
def typeConstructor (implicit ctx : Context ): TypeRef =
448
- if (isPackageClass) TypeRef (owner.thisType, symbol.asType)
474
+ if (isPackageClass) symbolicRef
449
475
else TypeRef (owner.thisType, name.asTypeName)
450
476
477
+ /** The symbolic typeref representing the type constructor for this type.
478
+ * @throws ClassCastException is this is not a type
479
+ */
480
+ def symbolicRef (implicit ctx : Context ): TypeRef =
481
+ TypeRef (owner.thisType, symbol.asType)
482
+
451
483
/** The variance of this type parameter as an Int, with
452
484
* +1 = Covariant, -1 = Contravariant, 0 = Nonvariant, or not a type parameter
453
485
*/
@@ -468,7 +500,7 @@ object SymDenotations {
468
500
initFlags : FlagSet = this .flags,
469
501
privateWithin : Symbol = this .privateWithin,
470
502
info : Type = this .info) =
471
- new CompleteSymDenotation (sym, owner, name, initFlags, privateWithin, info )
503
+ CompleteSymDenotation (sym, owner, name, initFlags, info, privateWithin )
472
504
}
473
505
474
506
/** The contents of a class definition during a period
@@ -495,6 +527,8 @@ object SymDenotations {
495
527
/** The symbols defined directly in this class */
496
528
def decls : Scope
497
529
530
+ def name : TypeName
531
+
498
532
override val info = {
499
533
implicit val ctx = initctx
500
534
ClassInfo (owner.thisType, this )
@@ -752,17 +786,23 @@ object SymDenotations {
752
786
fn
753
787
}
754
788
789
+ override def primaryConstructor (implicit ctx : Context ): Symbol = {
790
+ val cname =
791
+ if (this is Trait | ImplClass ) nme.TRAIT_CONSTRUCTOR else nme.CONSTRUCTOR
792
+ decls.denotsNamed(cname).first.symbol
793
+ }
794
+
755
795
def copyClass (
756
796
sym : ClassSymbol ,
757
797
owner : Symbol = this .owner,
758
- name : Name = this .name,
798
+ name : TypeName = this .name,
759
799
initFlags : FlagSet = this .flags,
760
800
privateWithin : Symbol = this .privateWithin,
761
801
parents : List [TypeRef ] = this .parents,
762
802
selfType : Type = this .selfType,
763
803
decls : Scope = this .decls,
764
804
assocFile : AbstractFile = this .assocFile)(implicit ctx : Context ) =
765
- new CompleteClassDenotation (sym, owner, name, initFlags, privateWithin, parents , selfType, decls, assocFile)(ctx)
805
+ new CompleteClassDenotation (sym, owner, name, initFlags, parents, privateWithin , selfType, decls, assocFile)(ctx)
766
806
}
767
807
768
808
// -------- Concrete classes for instantiating denotations --------------------------
@@ -772,10 +812,14 @@ object SymDenotations {
772
812
val owner : Symbol ,
773
813
val name : Name ,
774
814
initFlags : FlagSet ,
775
- val privateWithin : Symbol ,
776
- val info : Type
815
+ val info : Type ,
816
+ val privateWithin : Symbol
777
817
) extends SymDenotation (initFlags)
778
818
819
+ def CompleteSymDenotation (symbol : Symbol , owner : Symbol , name : Name , initFlags : FlagSet ,
820
+ info : Type , privateWithin : Symbol = NoSymbol ) =
821
+ new CompleteSymDenotation (symbol, owner, name, initFlags, info, privateWithin)
822
+
779
823
class LazySymDenotation (
780
824
val symbol : Symbol ,
781
825
val owner : Symbol ,
@@ -792,28 +836,41 @@ object SymDenotations {
792
836
override def info = { if (info == null ) tryComplete(); _info }
793
837
}
794
838
839
+ def LazySymDenotation (symbol : Symbol , owner : Symbol , name : Name , initFlags : FlagSet ,
840
+ completer : SymCompleter ) =
841
+ new LazySymDenotation (symbol, owner, name, initFlags, completer)
842
+
795
843
class CompleteClassDenotation (
796
844
val symbol : ClassSymbol ,
797
845
val owner : Symbol ,
798
- val name : Name ,
846
+ val name : TypeName ,
799
847
initFlags : FlagSet ,
800
- val privateWithin : Symbol ,
801
848
val parents : List [TypeRef ],
849
+ val privateWithin : Symbol ,
802
850
optSelfType : Type ,
803
851
val decls : Scope ,
804
- assocFile : AbstractFile = null
805
- )( initctx : Context ) extends ClassDenotation (initFlags, assocFile)(initctx) {
806
- val selfType = if (optSelfType == NoType ) thisType (initctx) else optSelfType
852
+ assocFile : AbstractFile )( initctx : Context )
853
+ extends ClassDenotation (initFlags, assocFile)(initctx) {
854
+ val selfType = if (optSelfType == NoType ) typeConstructor (initctx) else optSelfType
807
855
final def preCompleteDecls = decls
808
856
}
809
857
858
+ def CompleteClassDenotation (
859
+ symbol : ClassSymbol , owner : Symbol , name : TypeName , initFlags : FlagSet , parents : List [TypeRef ],
860
+ privateWithin : Symbol = NoSymbol ,
861
+ optSelfType : Type = NoType ,
862
+ decls : Scope = newScope,
863
+ assocFile : AbstractFile = null )(implicit ctx : Context ) =
864
+ new CompleteClassDenotation (symbol, owner, name, initFlags, parents,
865
+ privateWithin, optSelfType, decls, assocFile)(ctx)
866
+
810
867
class LazyClassDenotation (
811
868
val symbol : ClassSymbol ,
812
869
val owner : Symbol ,
813
- val name : Name ,
870
+ val name : TypeName ,
814
871
initFlags : FlagSet ,
815
872
var completer : ClassCompleter ,
816
- assocFile : AbstractFile = null
873
+ assocFile : AbstractFile
817
874
)(initctx : Context ) extends ClassDenotation (initFlags, assocFile)(initctx) with isLazy[LazyClassDenotation ] {
818
875
819
876
private [this ] var _parents : List [TypeRef ] = null
@@ -832,6 +889,11 @@ object SymDenotations {
832
889
final override def exists (implicit ctx : Context ) = { ensureCompleted(); _parents != null }
833
890
}
834
891
892
+ def LazyClassDenotation (
893
+ symbol : ClassSymbol , owner : Symbol , name : TypeName , initFlags : FlagSet ,
894
+ completer : ClassCompleter , assocFile : AbstractFile = null )(implicit ctx : Context ) =
895
+ new LazyClassDenotation (symbol, owner, name, initFlags, completer, assocFile)(ctx)
896
+
835
897
object NoDenotation extends SymDenotation (EmptyFlags ) {
836
898
override def isTerm = false
837
899
override def isType = false
@@ -923,7 +985,7 @@ object SymDenotations {
923
985
case denot : LazyClassDenotation =>
924
986
denot.privateWithin = NoSymbol
925
987
denot.parents = Nil
926
- denot.selfType = denot.thisType
988
+ denot.selfType = denot.typeConstructor
927
989
denot.decls = EmptyScope
928
990
}
929
991
0 commit comments