There is a method baseClasses
on Type
and ClassSymbol
in Scala reflection API which, according to its scaladoc, returns:
The list of all base classes of this type (including its own typeSymbol) in reverse linearization order, starting with the class itself and ending in class Any.
How to use this? Here's an example that prints all superclasses of scala.collection.immutable.List
in reverse linearization order:
import scala.reflect.runtime.universe._
val tpe = typeOf[scala.collection.immutable.List[_]]
tpe.baseClasses foreach { s => println(s.fullName) }
Output of this:
scala.collection.immutable.List
scala.collection.LinearSeqOptimized
scala.Product
scala.collection.immutable.LinearSeq
scala.collection.LinearSeq
scala.collection.LinearSeqLike
scala.collection.immutable.Seq
scala.collection.immutable.Iterable
scala.collection.immutable.Traversable
scala.Immutable
scala.collection.AbstractSeq
scala.collection.Seq
scala.collection.SeqLike
scala.collection.GenSeq
scala.collection.GenSeqLike
scala.PartialFunction
scala.Function1
scala.collection.AbstractIterable
scala.collection.Iterable
scala.collection.IterableLike
scala.Equals
scala.collection.GenIterable
scala.collection.GenIterableLike
scala.collection.AbstractTraversable
scala.collection.Traversable
scala.collection.GenTraversable
scala.collection.generic.GenericTraversableTemplate
scala.collection.TraversableLike
scala.collection.GenTraversableLike
scala.collection.Parallelizable
scala.collection.TraversableOnce
scala.collection.GenTraversableOnce
scala.collection.generic.FilterMonadic
scala.collection.generic.HasNewBuilder
java.lang.Object
scala.Any