summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/settings/Warnings.scala
diff options
context:
space:
mode:
authorSom Snytt <som.snytt@gmail.com>2014-08-25 10:15:04 -0700
committerLukas Rytz <lukas.rytz@gmail.com>2014-09-05 20:27:59 +0200
commit7655a70489f565a5a7a165f893b4a1e44c3cb2b8 (patch)
tree9a2a54ae5802211c5444006ffea06aef497bbe3b /src/compiler/scala/tools/nsc/settings/Warnings.scala
parentb562d965dc30bb1fdd9433a6675bfe8e38b8c667 (diff)
downloadscala-7655a70489f565a5a7a165f893b4a1e44c3cb2b8.tar.gz
scala-7655a70489f565a5a7a165f893b4a1e44c3cb2b8.tar.bz2
scala-7655a70489f565a5a7a165f893b4a1e44c3cb2b8.zip
Use Enumeration for MultiChoiceSetting
This is pretty easy, since a ValueSet is a BitSet. When the setting is updated, recompute the current set of values, which is cheap and succinct. Checking a flag is also easy and fast. Choices in MultiChoiceSettings may enable other choices.
Diffstat (limited to 'src/compiler/scala/tools/nsc/settings/Warnings.scala')
-rw-r--r--src/compiler/scala/tools/nsc/settings/Warnings.scala100
1 files changed, 53 insertions, 47 deletions
diff --git a/src/compiler/scala/tools/nsc/settings/Warnings.scala b/src/compiler/scala/tools/nsc/settings/Warnings.scala
index 771543ec77..574825874d 100644
--- a/src/compiler/scala/tools/nsc/settings/Warnings.scala
+++ b/src/compiler/scala/tools/nsc/settings/Warnings.scala
@@ -38,21 +38,45 @@ trait Warnings {
// Lint warnings
- def warnAdaptedArgs = lint contains "adapted-args"
- def warnNullaryUnit = lint contains "nullary-unit"
- def warnInaccessible = lint contains "inaccessible"
- def warnNullaryOverride = lint contains "nullary-override"
- def warnInferAny = lint contains "infer-any"
- def warnMissingInterpolator = lint contains "missing-interpolator"
- def warnDocDetached = lint contains "doc-detached"
- def warnPrivateShadow = lint contains "private-shadow"
- def warnTypeParameterShadow = lint contains "type-parameter-shadow"
- def warnPolyImplicitOverload = lint contains "poly-implicit-overload"
- def warnOptionImplicit = lint contains "option-implicit"
- def warnDelayedInit = lint contains "delayedinit-select"
- def warnByNameRightAssociative = lint contains "by-name-right-associative"
- def warnPackageObjectClasses = lint contains "package-object-classes"
- def warnUnsoundMatch = lint contains "unsound-match"
+ object LintWarnings extends MultiChoiceEnumeration {
+ class LintWarning(name: String, help: String, val yAliased: Boolean) extends Choice(name, help)
+ def LintWarning(name: String, help: String, yAliased: Boolean = false) = new LintWarning(name, help, yAliased)
+
+ val AdaptedArgs = LintWarning("adapted-args", "Warn if an argument list is modified to match the receiver.", true)
+ val NullaryUnit = LintWarning("nullary-unit", "Warn when nullary methods return Unit.", true)
+ val Inaccessible = LintWarning("inaccessible", "Warn about inaccessible types in method signatures.", true)
+ val NullaryOverride = LintWarning("nullary-override", "Warn when non-nullary `def f()' overrides nullary `def f'.", true)
+ val InferAny = LintWarning("infer-any", "Warn when a type argument is inferred to be `Any`.", true)
+ val MissingInterpolator = LintWarning("missing-interpolator", "A string literal appears to be missing an interpolator id.")
+ val DocDetached = LintWarning("doc-detached", "A ScalaDoc comment appears to be detached from its element.")
+ val PrivateShadow = LintWarning("private-shadow", "A private field (or class parameter) shadows a superclass field.")
+ val TypeParameterShadow = LintWarning("type-parameter-shadow", "A local type parameter shadows a type already in scope.")
+ val PolyImplicitOverload = LintWarning("poly-implicit-overload", "Parameterized overloaded implicit methods are not visible as view bounds.")
+ val OptionImplicit = LintWarning("option-implicit", "Option.apply used implicit view.")
+ val DelayedInitSelect = LintWarning("delayedinit-select", "Selecting member of DelayedInit")
+ val ByNameRightAssociative = LintWarning("by-name-right-associative", "By-name parameter of right associative operator.")
+ val PackageObjectClasses = LintWarning("package-object-classes", "Class or object defined in package object.")
+ val UnsoundMatch = LintWarning("unsound-match", "Pattern match may not be typesafe.")
+
+ def allWarnings = values.toSeq.asInstanceOf[Seq[LintWarning]]
+ }
+ import LintWarnings._
+
+ def warnAdaptedArgs = lint contains AdaptedArgs
+ def warnNullaryUnit = lint contains NullaryUnit
+ def warnInaccessible = lint contains Inaccessible
+ def warnNullaryOverride = lint contains NullaryOverride
+ def warnInferAny = lint contains InferAny
+ def warnMissingInterpolator = lint contains MissingInterpolator
+ def warnDocDetached = lint contains DocDetached
+ def warnPrivateShadow = lint contains PrivateShadow
+ def warnTypeParameterShadow = lint contains TypeParameterShadow
+ def warnPolyImplicitOverload = lint contains PolyImplicitOverload
+ def warnOptionImplicit = lint contains OptionImplicit
+ def warnDelayedInit = lint contains DelayedInitSelect
+ def warnByNameRightAssociative = lint contains ByNameRightAssociative
+ def warnPackageObjectClasses = lint contains PackageObjectClasses
+ def warnUnsoundMatch = lint contains UnsoundMatch
// Lint warnings that are currently -Y, but deprecated in that usage
@deprecated("Use warnAdaptedArgs", since="2.11.2")
@@ -67,41 +91,23 @@ trait Warnings {
def YwarnInferAny = warnInferAny
// The Xlint warning group.
- val lint: MultiChoiceSetting = {
- val description = "Enable or disable specific warnings"
-
- val choices = List(
- ("adapted-args", "Warn if an argument list is modified to match the receiver.", true),
- ("nullary-unit", "Warn when nullary methods return Unit.", true),
- ("inaccessible", "Warn about inaccessible types in method signatures.", true),
- ("nullary-override", "Warn when non-nullary `def f()' overrides nullary `def f'.", true),
- ("infer-any", "Warn when a type argument is inferred to be `Any`.", true),
- ("missing-interpolator", "A string literal appears to be missing an interpolator id.", false),
- ("doc-detached", "A ScalaDoc comment appears to be detached from its element.", false),
- ("private-shadow", "A private field (or class parameter) shadows a superclass field.", false),
- ("type-parameter-shadow", "A local type parameter shadows a type already in scope.", false),
- ("poly-implicit-overload", "Parameterized overloaded implicit methods are not visible as view bounds.", false),
- ("option-implicit", "Option.apply used implicit view.", false),
- ("delayedinit-select", "Selecting member of DelayedInit", false),
- ("by-name-right-associative", "By-name parameter of right associative operator.", false),
- ("package-object-classes", "Class or object defined in package object.", false),
- ("unsound-match", "Pattern match may not be typesafe.", false)
- ).sorted
-
- for (c <- choices.filter(_._3)) {
- BooleanSetting("-Ywarn-"+ c._1, c._2) withPostSetHook { s =>
- if (s) lint.add(c._1)
- else lint.add("-" + c._1)
- } // withDeprecationMessage s"Enable -Xlint:${c._1}"
+ val lint: MultiChoiceSetting[LintWarnings.type] = {
+ import LintWarnings._
+
+ allWarnings.sortBy(_.name) foreach {
+ case l: LintWarning if l.yAliased =>
+ BooleanSetting(s"-Ywarn-${l.name}", {l.help}) withPostSetHook { s =>
+ lint.add(if (s) l.name else s"-${l.name}")
+ } // withDeprecationMessage s"Enable -Xlint:${c._1}"
+ case _ =>
}
MultiChoiceSetting(
- name = "-Xlint",
- helpArg = "warning",
- descr = description,
- choices = choices map (_._1),
- descriptions = choices map (_._2),
- default = Some(List("_"))
+ name = "-Xlint",
+ helpArg = "warning",
+ descr = "Enable or disable specific warnings",
+ domain = LintWarnings,
+ default = Some(List("_"))
)
}