File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed
core/src/main/scala/magnolia1
examples/src/main/scala/magnolia1/examples Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -127,6 +127,20 @@ object Magnolia {
127127 val SubtypeTpe = typeOf[Subtype [Any , Any ]].typeConstructor
128128 val TypeNameObj = reify(magnolia1.TypeName ).tree
129129
130+ def assertFieldsLimits (caseClassParameters : List [TermSymbol ]): Unit = {
131+ val minLimit = config.map(_.minFields).getOrElse(- 1 )
132+ val maxLimit = config.map(_.maxFields).getOrElse(- 1 )
133+ val fieldsNumber = caseClassParameters.size
134+
135+ if (minLimit > - 1 && fieldsNumber < minLimit) {
136+ error(s " Case class ${genericSymbol.name} has $fieldsNumber fields which is less than required minimum: $minLimit" )
137+ }
138+
139+ if (maxLimit > - 1 && fieldsNumber > maxLimit) {
140+ error(s " Case class ${genericSymbol.name} has $fieldsNumber fields which is above the required maximum: $maxLimit" )
141+ }
142+ }
143+
130144 val debug = c.macroApplication.symbol.annotations
131145 .find(_.tree.tpe <:< DebugTpe )
132146 .flatMap(_.tree.children.tail.collectFirst {
@@ -426,6 +440,8 @@ object Magnolia {
426440 }
427441 )
428442
443+ assertFieldsLimits(caseClassParameters)
444+
429445 val (factoryObject, factoryMethod) = {
430446 if (isReadOnly && isValueClass) ReadOnlyParamObj -> TermName (" valueParam" )
431447 else if (isReadOnly) ReadOnlyParamObj -> TermName (" apply" )
Original file line number Diff line number Diff line change 11package magnolia1 .examples
22
3- import magnolia1 .{ CaseClass , Config , Magnolia , SealedTrait }
3+ import magnolia1 ._
44
55import scala .language .experimental .macros
66
@@ -12,9 +12,9 @@ object CsvConfig extends Config {
1212 type Proxy = Csv .type
1313 type Ignore = transient
1414 final val readOnly = true
15- final val minFields = 0
15+ final val minFields = - 1
1616 final val maxFields = - 1
17- final val minCases = 0
17+ final val minCases = - 1
1818 final val maxCases = - 1
1919}
2020
You can’t perform that action at this time.
0 commit comments