aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc
diff options
context:
space:
mode:
Diffstat (limited to 'src/dotty/tools/dotc')
-rw-r--r--src/dotty/tools/dotc/core/Definitions.scala1
-rw-r--r--src/dotty/tools/dotc/core/StdNames.scala3
-rw-r--r--src/dotty/tools/dotc/core/SymDenotations.scala14
-rw-r--r--src/dotty/tools/dotc/core/TypeOps.scala34
4 files changed, 51 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/core/Definitions.scala b/src/dotty/tools/dotc/core/Definitions.scala
index 5f6698b33..5c2890f29 100644
--- a/src/dotty/tools/dotc/core/Definitions.scala
+++ b/src/dotty/tools/dotc/core/Definitions.scala
@@ -215,6 +215,7 @@ class Definitions {
lazy val JavaSerializableClass = ctx.requiredClass("java.lang.Serializable")
lazy val ComparableClass = ctx.requiredClass("java.lang.Comparable")
lazy val ProductClass = ctx.requiredClass("scala.Product")
+ lazy val LanguageModuleClass = ctx.requiredModule("dotty.language").moduleClass
// Annotation base classes
lazy val AnnotationClass = ctx.requiredClass("scala.annotation.Annotation")
diff --git a/src/dotty/tools/dotc/core/StdNames.scala b/src/dotty/tools/dotc/core/StdNames.scala
index 0cbcfa5a7..6cd9da4b5 100644
--- a/src/dotty/tools/dotc/core/StdNames.scala
+++ b/src/dotty/tools/dotc/core/StdNames.scala
@@ -375,6 +375,7 @@ object StdNames {
val hashCode_ : N = "hashCode"
val hash_ : N = "hash"
val head: N = "head"
+ val higherKinds: N = "higherKinds"
val identity: N = "identity"
val implicitly: N = "implicitly"
val in: N = "in"
@@ -387,6 +388,7 @@ object StdNames {
val isInstanceOf_ : N = "isInstanceOf"
val isInstanceOf_Ob : N = "$isInstanceOf"
val java: N = "java"
+ val keepUnions: N = "keepUnions"
val key: N = "key"
val lang: N = "lang"
val length: N = "length"
@@ -415,6 +417,7 @@ object StdNames {
val next: N = "next"
val nmeNewTermName: N = "newTermName"
val nmeNewTypeName: N = "newTypeName"
+ val noAutoTupling: N = "noAutoTupling"
val normalize: N = "normalize"
val notifyAll_ : N = "notifyAll"
val notify_ : N = "notify"
diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala
index 08566e3db..362738caf 100644
--- a/src/dotty/tools/dotc/core/SymDenotations.scala
+++ b/src/dotty/tools/dotc/core/SymDenotations.scala
@@ -9,7 +9,7 @@ import collection.mutable
import collection.immutable.BitSet
import scala.reflect.io.AbstractFile
import Decorators.SymbolIteratorDecorator
-import ast.tpd
+import ast._
import annotation.tailrec
import util.SimpleMap
import util.Stats
@@ -195,6 +195,18 @@ object SymDenotations {
final def hasAnnotation(cls: Symbol)(implicit ctx: Context) =
dropOtherAnnotations(annotations, cls).nonEmpty
+ /** Optionally, the arguments of the first annotation matching the given class symbol */
+ final def getAnnotationArgs(cls: Symbol)(implicit ctx: Context): Option[List[tpd.Tree]] =
+ dropOtherAnnotations(annotations, cls) match {
+ case annot :: _ =>
+ Some(
+ annot.tree match {
+ case Trees.Apply(_, args) => args
+ case _ => Nil
+ })
+ case nil => None
+ }
+
/** Add given annotation to the annotations of this denotation */
final def addAnnotation(annot: Annotation): Unit =
annotations = annot :: myAnnotations
diff --git a/src/dotty/tools/dotc/core/TypeOps.scala b/src/dotty/tools/dotc/core/TypeOps.scala
index 152f8d1b7..4ace0bebe 100644
--- a/src/dotty/tools/dotc/core/TypeOps.scala
+++ b/src/dotty/tools/dotc/core/TypeOps.scala
@@ -266,6 +266,40 @@ trait TypeOps { this: Context =>
}
parentRefs
}
+
+ /** Is `feature` enabled in class `owner`?
+ * This is the case if one of the following two alternatives holds:
+ *
+ * 1. The feature is imported by a named import
+ *
+ * import owner.feature
+ *
+ * (the feature may be bunched with others, or renamed, but wildcard imports
+ * don't count).
+ *
+ * 2. The feature is enabled by a compiler option
+ *
+ * - language:<prefix>feature
+ *
+ * where <prefix> is the full name of the owner followed by a "." minus
+ * the prefix "dotty.language.".
+ */
+ def featureEnabled(owner: ClassSymbol, feature: TermName): Boolean = {
+ def toPrefix(sym: Symbol): String =
+ if (sym eq defn.LanguageModuleClass) "" else toPrefix(sym.owner) + sym.name + "."
+ def featureName = toPrefix(owner) + feature
+ def hasImport(implicit ctx: Context): Boolean = (
+ ctx.importInfo != null
+ && ( (ctx.importInfo.site.widen.typeSymbol eq owner)
+ && ctx.importInfo.originals.contains(feature)
+ ||
+ { var c = ctx.outer
+ while (c.importInfo eq ctx.importInfo) c = c.outer
+ hasImport(c)
+ }))
+ def hasOption = ctx.base.settings.language.value exists (s => s == featureName || s == "_")
+ hasImport || hasOption
+ }
}
object TypeOps {