@@ -8,7 +8,7 @@ class ConstantDeclarations(g: Global) extends AnalyzerRule(g, "constantDeclarati
8
8
import global ._
9
9
10
10
def analyze (unit : CompilationUnit ): Unit = unit.body.foreach {
11
- case t@ ValDef (mods , name, tpt, rhs)
11
+ case t@ ValDef (_ , name, tpt, rhs)
12
12
if t.symbol.hasGetter && t.symbol.owner.isEffectivelyFinal =>
13
13
14
14
val getter = t.symbol.getterIn(t.symbol.owner)
@@ -18,15 +18,18 @@ class ConstantDeclarations(g: Global) extends AnalyzerRule(g, "constantDeclarati
18
18
case _ => false
19
19
}
20
20
21
+ def doReport (msg : String ): Unit =
22
+ report(t.pos, msg, site = t.symbol)
23
+
21
24
val firstChar = name.toString.charAt(0 )
22
25
if (constantValue && (firstChar.isLower || ! getter.isFinal)) {
23
- report(t.pos, " a literal-valued constant should be declared as a `final val` with an UpperCamelCase name" )
26
+ doReport( " a literal-valued constant should be declared as a `final val` with an UpperCamelCase name" )
24
27
}
25
28
if (! constantValue && firstChar.isUpper && ! getter.isFinal) {
26
- report(t.pos, " a constant with UpperCamelCase name should be declared as a `final val`" )
29
+ doReport( " a constant with UpperCamelCase name should be declared as a `final val`" )
27
30
}
28
31
if (getter.isFinal && constantValue && ! (tpt.tpe =:= rhs.tpe)) {
29
- report(t.pos, " a constant with a literal value should not have an explicit type annotation" )
32
+ doReport( " a constant with a literal value should not have an explicit type annotation" )
30
33
}
31
34
}
32
35
case _ =>
0 commit comments