Skip to content

Commit c6f7fda

Browse files
committed
refactor ImplicitValueClasses rule: move message construction inside analyze method
1 parent 9964dd4 commit c6f7fda

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

analyzer/src/main/scala/com/avsystem/commons/analyzer/ImplicitValueClasses.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ class ImplicitValueClasses(g: Global) extends AnalyzerRule(g, "implicitValueClas
1515
case a => a.toBoolean
1616
}
1717

18-
private lazy val message = "Implicit classes should always extend AnyVal to become value classes" +
19-
(if (reportOnNestedClasses) ". Nested classes should be extracted to top-level objects" else "")
20-
2118
def analyze(unit: CompilationUnit): Unit = unit.body.foreach {
2219
case cd: ClassDef if cd.mods.hasFlag(Flag.IMPLICIT) =>
2320
val tpe = cd.symbol.typeSignature
@@ -34,10 +31,13 @@ class ImplicitValueClasses(g: Global) extends AnalyzerRule(g, "implicitValueClas
3431
def hasExactlyOneParam = paramLists.forall(lists => lists.size == 1 && lists.head.size == 1)
3532

3633
if (!inheritsAnyVal && !inheritsOtherClass && hasExactlyOneParam) {
37-
def isNestedClass =
34+
val isNestedClass =
3835
//implicit classes are always nested classes, so we want to check if the outer class's an object
3936
/*cd.symbol.isNestedClass &&*/ !cd.symbol.isStatic
4037

38+
val message = "Implicit classes should always extend AnyVal to become value classes" +
39+
(if (isNestedClass) ". Nested classes should be extracted to top-level objects" else "")
40+
4141
if (reportOnNestedClasses || !isNestedClass)
4242
report(cd.pos, message)
4343
else

0 commit comments

Comments
 (0)