Skip to content

Commit

Permalink
Made synthetic classes extending java.lang.Object. Fix lightbend-labs#74
Browse files Browse the repository at this point in the history


All classes extends `java.lang.Object`, synthetic (i.e., compiler generated)
classes being no exception.

Furthermore, implemented typesafe equality (`===`) for comparing `ClassInfo`
instances, since the existing calls to `==` where only comparing references
(since `ClassInfo` does not implement `equals`).
  • Loading branch information
dotta committed May 29, 2015
1 parent b23d4a3 commit 0318283
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
17 changes: 12 additions & 5 deletions core/src/main/scala/com/typesafe/tools/mima/core/ClassInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ object ClassInfo {
* class path.
*/
lazy val ObjectClass = Config.baseDefinitions.fromName("java.lang.Object")

implicit class EqualClassInfo(c1: ClassInfo) {
def ===(c2: ClassInfo): Boolean = {
if(c1 == null & c2 == null) true
else c1 != null && c2 != null && c1.fullName == c2.fullName
}
}
}

import com.typesafe.tools.mima.core.util.log.{ConsoleLogging, Logging}
Expand All @@ -20,9 +27,9 @@ import com.typesafe.tools.mima.core.util.log.{ConsoleLogging, Logging}
class SyntheticClassInfo(owner: PackageInfo, override val bytecodeName: String) extends ClassInfo(owner) {
loaded = true
def file: AbstractFile = throw new UnsupportedOperationException
override lazy val superClasses = Nil
override lazy val allTraits = Set.empty[ClassInfo]
override lazy val allInterfaces: Set[ClassInfo] = Set.empty[ClassInfo]
override lazy val superClasses = Set(ClassInfo.ObjectClass)

This comment has been minimized.

Copy link
@dotta

dotta May 30, 2015

Author Owner

Actually, I don't like this. Would make a lot more sense to override superClass. I'll have another look at it.

}

/** As the name implies. */
Expand Down Expand Up @@ -97,8 +104,8 @@ abstract class ClassInfo(val owner: PackageInfo) extends HasDeclarationName with
def flags_=(x: Int) = _flags = x
def isScala_=(x: Boolean) = _isScala = x

lazy val superClasses: List[ClassInfo] =
(if (this == ClassInfo.ObjectClass) Nil else superClass :: superClass.superClasses)
lazy val superClasses: Set[ClassInfo] =
(if (this === ClassInfo.ObjectClass) Set.empty else (superClass.superClasses + superClass))

def lookupClassFields(name: String): Iterator[MemberInfo] =
(Iterator.single(this) ++ superClasses.iterator) flatMap (_.fields.get(name))
Expand Down Expand Up @@ -169,12 +176,12 @@ abstract class ClassInfo(val owner: PackageInfo) extends HasDeclarationName with

/** All traits inherited directly or indirectly by this class */
lazy val allTraits: Set[ClassInfo] =
if (this == ClassInfo.ObjectClass) Set.empty
if (this === ClassInfo.ObjectClass) Set.empty
else superClass.allTraits ++ directTraits

/** All interfaces inherited directly or indirectly by this class */
lazy val allInterfaces: Set[ClassInfo] =
if (this == ClassInfo.ObjectClass) Set.empty
if (this === ClassInfo.ObjectClass) Set.empty
else superClass.allInterfaces ++ interfaces ++ (interfaces flatMap (_.allInterfaces))

private def unimplemented(sel: ClassInfo => Traversable[MemberInfo]): List[MemberInfo] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,8 @@ import com.typesafe.tools.mima.lib.analyze.Rule
}

private[TemplateRules] trait ClassTypesHelper {
def diff(thisTypes: Iterable[ClassInfo], thatTypes: Iterable[ClassInfo]) = {
val thisSuperclasses = thisTypes.map(_.fullName).toSet
val thatSuperclasses = thisTypes.map(_.fullName).toSet

thisTypes.filter(sc => !thatTypes.exists(_.fullName == sc.fullName))
}
def diff(thisTypes: Set[ClassInfo], thatTypes: Set[ClassInfo]) =
thisTypes.filter(sc => !thatTypes.exists(_ === sc))
}

object Superclasses extends TemplateRule with ClassTypesHelper {
Expand Down

0 comments on commit 0318283

Please sign in to comment.