diff options
author | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2015-03-25 18:21:14 +0100 |
---|---|---|
committer | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2015-03-25 18:21:14 +0100 |
commit | 13a05d5119e33333000f969817434629443d6bb2 (patch) | |
tree | 7b5ea2dc8c2aef8ddff825a0824c8c4045f7ce0d /src/dotty/tools/dotc/core/SymDenotations.scala | |
parent | c6792189ff2075ac8b90efc7fad42aafd6a7b67e (diff) | |
download | dotty-13a05d5119e33333000f969817434629443d6bb2.tar.gz dotty-13a05d5119e33333000f969817434629443d6bb2.tar.bz2 dotty-13a05d5119e33333000f969817434629443d6bb2.zip |
#353 use methods to find companion class
Diffstat (limited to 'src/dotty/tools/dotc/core/SymDenotations.scala')
-rw-r--r-- | src/dotty/tools/dotc/core/SymDenotations.scala | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index 44629c036..658af4a4e 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -773,11 +773,31 @@ object SymDenotations { companionNamed(effectiveName.moduleClassName).sourceModule /** The class with the same (type-) name as this module or module class, - * and which is also defined in the same scope and compilation unit. - * NoSymbol if this class does not exist. - */ - final def companionClass(implicit ctx: Context): Symbol = - companionNamed(effectiveName.toTypeName) + * and which is also defined in the same scope and compilation unit. + * NoSymbol if this class does not exist. + */ + final def companionClass(implicit ctx: Context): Symbol = { + val companionMethod = info.decls.denotsNamed(nme.COMPANION_CLASS_METHOD, selectPrivate).first + + if (companionMethod.exists) + companionMethod.info.resultType.classSymbol + else { + /* + val scalac = companionNamed(effectiveName.toTypeName) + + if (scalac.exists) { + println(s"scalac returned companion class for $this to be $scalac") + } + */ + NoSymbol + } + } + + final def scalacLinkedClass(implicit ctx: Context): Symbol = + if (this is ModuleClass) companionNamed(effectiveName.toTypeName) + else if (this.isClass) companionModule.moduleClass + else NoSymbol + /** Find companion class symbol with given name, or NoSymbol if none exists. * Three alternative strategies: |