diff options
Diffstat (limited to 'src/dotty/tools/dotc/core')
-rw-r--r-- | src/dotty/tools/dotc/core/Flags.scala | 3 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/NameOps.scala | 9 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/SymDenotations.scala | 42 |
3 files changed, 32 insertions, 22 deletions
diff --git a/src/dotty/tools/dotc/core/Flags.scala b/src/dotty/tools/dotc/core/Flags.scala index c467a553f..c67768861 100644 --- a/src/dotty/tools/dotc/core/Flags.scala +++ b/src/dotty/tools/dotc/core/Flags.scala @@ -521,6 +521,9 @@ object Flags { /** A Java companion object */ final val JavaModule = allOf(JavaDefined, Module) + /** A Java companion object */ + final val JavaProtected = allOf(JavaDefined, Protected) + /** Labeled private[this] */ final val PrivateLocal = allOf(Private, Local) diff --git a/src/dotty/tools/dotc/core/NameOps.scala b/src/dotty/tools/dotc/core/NameOps.scala index 404a0844a..d32fd1913 100644 --- a/src/dotty/tools/dotc/core/NameOps.scala +++ b/src/dotty/tools/dotc/core/NameOps.scala @@ -251,9 +251,12 @@ object NameOps { /** If this is a default getter, its index (starting from 0), else -1 */ def defaultGetterIndex: Int = { - val p = name.indexOfSlice(DEFAULT_GETTER) - if (p >= 0) name.drop(p + DEFAULT_GETTER.length).toString.toInt - 1 - else -1 + var i = name.length + while (i > 0 && name(i - 1).isDigit) i -= 1 + if (i > 0 && i < name.length && name.take(i).endsWith(DEFAULT_GETTER)) + name.drop(i).toString.toInt - 1 + else + -1 } /** The name of an accessor for protected symbols. */ diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index b0a09baf0..00c3d7666 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -589,10 +589,13 @@ object SymDenotations { NoSymbol } - /** The field accessed by this getter or setter */ - def accessedField(implicit ctx: Context): Symbol = { + /** The field accessed by this getter or setter, or if it does not exist, the getter */ + def accessedFieldOrGetter(implicit ctx: Context): Symbol = { val fieldName = if (isSetter) name.asTermName.setterToGetter else name - owner.info.decl(fieldName).suchThat(d => !(d is Method)).symbol + val d = owner.info.decl(fieldName) + val field = d.suchThat(!_.is(Method)).symbol + def getter = d.suchThat(_.info.isParameterless).symbol + field orElse getter } /** The chain of owners of this denotation, starting with the denoting symbol itself */ @@ -723,17 +726,29 @@ object SymDenotations { denot.symbol } + /** If false, this symbol cannot possibly participate in an override, + * either as overrider or overridee. + */ + final def canMatchInheritedSymbols(implicit ctx: Context): Boolean = + maybeOwner.isClass && !isConstructor && !is(Private) + /** The symbol, in class `inClass`, that is overridden by this denotation. */ final def overriddenSymbol(inClass: ClassSymbol)(implicit ctx: Context): Symbol = - if ((this is Private) && (owner ne inClass)) NoSymbol + if (!canMatchInheritedSymbols && (owner ne inClass)) NoSymbol else matchingSymbol(inClass, owner.thisType) /** All symbols overriden by this denotation. */ final def allOverriddenSymbols(implicit ctx: Context): Iterator[Symbol] = - if (exists && owner.isClass) - owner.info.baseClasses.tail.iterator map overriddenSymbol filter (_.exists) - else - Iterator.empty + if (!canMatchInheritedSymbols) Iterator.empty + else overriddenFromType(owner.info) + + /** Returns all all matching symbols defined in parents of the selftype. */ + final def extendedOverriddenSymbols(implicit ctx: Context): Iterator[Symbol] = + if (!canMatchInheritedSymbols) Iterator.empty + else overriddenFromType(owner.asClass.classInfo.selfType) + + private def overriddenFromType(tp: Type)(implicit ctx: Context): Iterator[Symbol] = + tp.baseClasses.tail.iterator map overriddenSymbol filter (_.exists) /** The symbol overriding this symbol in given subclass `ofclazz`. * @@ -743,17 +758,6 @@ object SymDenotations { if (canMatchInheritedSymbols) matchingSymbol(inClass, inClass.thisType) else NoSymbol - /** If false, this symbol cannot possibly participate in an override, - * either as overrider or overridee. For internal use; you should consult - * with isOverridingSymbol. This is used by isOverridingSymbol to escape - * the recursive knot. - */ - private def canMatchInheritedSymbols = ( - owner.isClass - && !this.isClass - && !this.isConstructor - ) - /** The symbol accessed by a super in the definition of this symbol when * seen from class `base`. This symbol is always concrete. * pre: `this.owner` is in the base class sequence of `base`. |