xsbt

Compat

abstract class Compat extends AnyRef

Collection of hacks that make it possible for the compiler interface to stay source compatible with Scala compiler 2.9, 2.10 and 2.11.

One common technique used in Compat class is use of implicit conversions to deal with methods that got renamed or moved between different Scala compiler versions.

Let's pick a specific example. In Scala 2.9 and 2.10 there was a method called toplevelClass defined on Symbol. In 2.10 that method has been deprecated and enclosingTopLevelClass method has been introduce as a replacement. In Scala 2.11 the old toplevelClass method has been removed. How can we pick the right version based on availability of those two methods?

We define an implicit conversion from Symbol to a class that contains both method definitions:

implicit def symbolCompat(sym: Symbol): SymbolCompat = new SymbolCompat(sym) class SymbolCompat(sym: Symbol) { def enclosingTopLevelClass: Symbol = sym.toplevelClass def toplevelClass: Symbol = throw new RuntimeException("For source compatibility only: should not get here.") }

We assume that client code (code in compiler interface) should always call enclosingTopLevelClass method. If we compile that code against 2.11 it will just directly link against method provided by Symbol. However, if we compile against 2.9 or 2.10 enclosingTopLevelClass won't be found so the implicit conversion defined above will kick in. That conversion will provide enclosingTopLevelClass that simply forwards to the old toplevelClass method that is available in 2.9 and 2.10 so that method will be called in the end. There's one twist: since enclosingTopLevelClass forwards to toplevelClass which doesn't exist in 2.11! Therefore, we need to also define toplevelClass that will be provided by an implicit conversion as well. However, we should never reach that method at runtime if either enclosingTopLevelClass or toplevelClass is available on Symbol so this is purely source compatibility stub.

The technique described above is used in several places below.

Linear Supertypes
AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Compat
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Compat()

Type Members

  1. final class SymbolCompat extends AnyRef

    Attributes
    protected

Abstract Value Members

  1. abstract val global: Global

Concrete Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. val DummyValue: Int

  7. val LocalChild: scala.reflect.internal.StdNames.tpnme.NameType

  8. object MacroExpansionOf

  9. object MirrorHelper

  10. val Nullary: scala.tools.nsc.Global.NullaryMethodType.type

  11. object NullaryMethodTpe

  12. val ScalaObjectClass: scala.tools.nsc.Global.ClassSymbol

  13. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  14. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  15. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  16. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  17. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  18. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  19. def hasMacro(s: scala.tools.nsc.Global.Symbol): Boolean

  20. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  21. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  22. def moduleSuffix(s: scala.tools.nsc.Global.Symbol): String

  23. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  24. final def notify(): Unit

    Definition Classes
    AnyRef
  25. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  26. implicit def symbolCompat(sym: scala.tools.nsc.Global.Symbol): SymbolCompat

    Attributes
    protected
  27. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  28. def toString(): String

    Definition Classes
    AnyRef → Any
  29. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  30. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  31. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped