File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
core/src/main/scala/magnolia1 Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -127,6 +127,22 @@ object Magnolia {
127127 val SubtypeTpe = typeOf[Subtype [Any , Any ]].typeConstructor
128128 val TypeNameObj = reify(magnolia1.TypeName ).tree
129129
130+ def assertFieldsLimits (caseClassSym : TypeSymbol ): Unit = {
131+ val minLimit = config.map(_.minFields).getOrElse(- 1 )
132+ val maxLimit = config.map(_.maxFields).getOrElse(Int .MaxValue )
133+ val fieldsNumber = caseClassSym.info.members.size
134+
135+ if (minLimit > - 1 && fieldsNumber < minLimit) {
136+ error(s " Case class ${caseClassSym.name} has $fieldsNumber fields which is less than required minimum: $minLimit" )
137+ }
138+
139+ if (fieldsNumber > maxLimit) {
140+ error(s " Case class ${caseClassSym.name} has $fieldsNumber fields which is above the required maximum: $maxLimit" )
141+ }
142+ }
143+
144+ assertFieldsLimits(CaseClassSym )
145+
130146 val debug = c.macroApplication.symbol.annotations
131147 .find(_.tree.tpe <:< DebugTpe )
132148 .flatMap(_.tree.children.tail.collectFirst {
You can’t perform that action at this time.
0 commit comments