@@ -8,7 +8,7 @@ class ConstantDeclarations(g: Global) extends AnalyzerRule(g, "constantDeclarati
88 import global ._
99
1010 def analyze (unit : CompilationUnit ): Unit = unit.body.foreach {
11- case t@ ValDef (mods , name, tpt, rhs)
11+ case t@ ValDef (_ , name, tpt, rhs)
1212 if t.symbol.hasGetter && t.symbol.owner.isEffectivelyFinal =>
1313
1414 val getter = t.symbol.getterIn(t.symbol.owner)
@@ -18,15 +18,18 @@ class ConstantDeclarations(g: Global) extends AnalyzerRule(g, "constantDeclarati
1818 case _ => false
1919 }
2020
21+ def doReport (msg : String ): Unit =
22+ report(t.pos, msg, site = t.symbol)
23+
2124 val firstChar = name.toString.charAt(0 )
2225 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" )
2427 }
2528 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`" )
2730 }
2831 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" )
3033 }
3134 }
3235 case _ =>
0 commit comments