1
1
package dotty .tools .dotc
2
2
package config
3
3
4
- import collection .mutable .ArrayBuffer
5
- import scala .util .{ Success , Failure }
6
- import reflect .ClassTag
7
4
import core .Contexts ._
8
- import scala .annotation .tailrec
9
- import dotty .tools .io .{ AbstractFile , Directory , JarArchive , PlainDirectory }
10
5
11
- // import annotation.unchecked
12
- // Dotty deviation: Imports take precedence over definitions in enclosing package
13
- // (Note that @unchecked is in scala, not annotation, so annotation.unchecked gives
14
- // us a package, which is not what was intended anyway).
6
+ import dotty . tools . io .{ AbstractFile , Directory , JarArchive , PlainDirectory }
7
+
8
+ import annotation . tailrec
9
+ import collection . mutable . ArrayBuffer
15
10
import language .existentials
11
+ import reflect .ClassTag
12
+ import scala .util .{Success , Failure }
16
13
17
14
object Settings {
18
15
@@ -25,7 +22,7 @@ object Settings {
25
22
val OutputTag : ClassTag [AbstractFile ] = ClassTag (classOf [AbstractFile ])
26
23
27
24
class SettingsState (initialValues : Seq [Any ]) {
28
- private var values = ArrayBuffer (initialValues : _* )
25
+ private val values = ArrayBuffer (initialValues : _* )
29
26
private var _wasRead : Boolean = false
30
27
31
28
override def toString : String = s " SettingsState(values: ${values.toList}) "
@@ -91,38 +88,46 @@ object Settings {
91
88
92
89
def isDefaultIn (state : SettingsState ): Boolean = valueIn(state) == default
93
90
91
+ def isMultivalue : Boolean = implicitly[ClassTag [T ]] == ListTag
92
+
94
93
def legalChoices : String =
95
- if ( choices.isEmpty) " "
96
- else choices match {
97
- case r : Range => s " ${r.head}.. ${r.last}"
98
- case xs : List [? ] => xs.mkString( " , " )
94
+ choices match {
95
+ case xs if xs.isEmpty => " "
96
+ case r : Range => s " ${r.head}.. ${r.last}"
97
+ case xs : List [? ] => xs.toString
99
98
}
100
99
101
100
def isLegal (arg : Any ): Boolean =
102
- if ( choices.isEmpty)
103
- arg match {
104
- case _ : T => true
105
- case _ => false
106
- }
107
- else choices match {
101
+ choices match {
102
+ case xs if xs.isEmpty =>
103
+ arg match {
104
+ case _ : T => true
105
+ case _ => false
106
+ }
108
107
case r : Range =>
109
108
arg match {
110
109
case x : Int => r.head <= x && x <= r.last
111
110
case _ => false
112
111
}
113
112
case xs : List [? ] =>
114
- xs contains arg
113
+ xs. contains( arg)
115
114
}
116
115
117
116
def tryToSet (state : ArgsSummary ): ArgsSummary = {
118
117
val ArgsSummary (sstate, arg :: args, errors, warnings) = state
119
118
def update (value : Any , args : List [String ]) =
120
- if (changed)
121
- ArgsSummary (updateIn(sstate, value), args, errors, warnings :+ s " Flag $name set repeatedly " )
122
- else {
123
- changed = true
124
- ArgsSummary (updateIn(sstate, value), args, errors, warnings)
125
- }
119
+ var dangers = warnings
120
+ val value1 =
121
+ if changed && isMultivalue then
122
+ val value0 = value.asInstanceOf [List [String ]]
123
+ val current = valueIn(sstate).asInstanceOf [List [String ]]
124
+ value0.filter(current.contains).foreach(s => dangers :+= s " Setting $name set to $s redundantly " )
125
+ current ++ value0
126
+ else
127
+ if changed then dangers :+= s " Flag $name set repeatedly "
128
+ value
129
+ changed = true
130
+ ArgsSummary (updateIn(sstate, value1), args, errors, dangers)
126
131
def fail (msg : String , args : List [String ]) =
127
132
ArgsSummary (sstate, args, errors :+ msg, warnings)
128
133
def missingArg =
@@ -229,7 +234,7 @@ object Settings {
229
234
*
230
235
* to get their arguments.
231
236
*/
232
- protected def processArguments (state : ArgsSummary , processAll : Boolean , skipped : List [String ]): ArgsSummary = {
237
+ protected [config] def processArguments (state : ArgsSummary , processAll : Boolean , skipped : List [String ]): ArgsSummary = {
233
238
def stateWithArgs (args : List [String ]) = ArgsSummary (state.sstate, args, state.errors, state.warnings)
234
239
state.arguments match {
235
240
case Nil =>
0 commit comments