makeStaticKind
Utility method for creating a concrete ReportKind out of a list of ReportUnit by reflection.
From a list this of a specific ReportUnit U, build up the specific kind K for it This is done statically, in which all fields are declared at compile time Also if K contains only null
fields, return null
instead to simplify the checking
Example: when U = PipelineErrorUnit and K = PipelineErrors, all PipelineErrorUnits (e.g. PipelineErrorUnit.NonFatalError, PipelineErrorUnit.FatalError) will be searched from this, and will be used to populate an instance of PipelineErrors, setting the units accordingly.
Works by creating an instance of K and getting all the mutable fields in it; For each subReportUnitType
under U (one of sealed subclass of U), filter this for elements of such subReportUnitType to subReportUnits. If there is any of these, further find the corresponding mutable field in the K instance for this subReportUnitType, check whether this field is of type subReportUnitType or List
Note that the contract between K and subReportUnitType
: U is that there is exactly one mutable field using subReportUnitType
in K, either of type subReportUnitType?
or List<subReportUnitType>?
. The contract between subReportUnitType
and U is that subReportUnitType
must be a sealed subclass of U