Skip to content

Validators

sciwhiz12 edited this page Jun 9, 2021 · 1 revision

A validator is an object implementing the Validator interface, which allows validation of data at will through the validateData and validateStagingData tasks. The AbstractValidator abstract class is provided for ease of implementation. A validator must have an attached name, which is used to identify the validator in memory and to the user in console logging.

A validator is called for each package data, class data, field data, method data, and parameter data within a mapping data container. Upon each call, a validator may return an empty list to indicate no issues were found, or a non-empty list of validation issues. A validator should return as much issues as it can in one pass, instead of returning immediately for each issue. This allows users to fix all listed issues in one pass, instead of going back-and-forth with fixing then validating.

Validation issues are issues or problems found by a validator for a given data. There are two types: a validation warning only informs the user that the warnings exist, while a validation error causes an exception to be thrown and the build to fail. This build failure is useful for a CI task which runs on user-supplied input data, to ensure that no validation errors occur by checking for a build failure.

As of the time of writing (in the development branch), there are 7 current validator implementations shipped within Compass:

  • BridgeValidator - validates that bridge methods are not documented, nor are their parameters named or documented, otherwise raises a validation error.
  • ClassInitValidator - validates that the class or interface initialization method (with the name <init>) is not documented, nor are any parameters named or documented, otherwise raises a validation error.
  • EnumValuesValidator - validates that the $VALUES field of enum classes is not documented, otherwise raises a validation error.
  • LambdaValidator - validates that lambda methods nor their parameters are documented, otherwise raises a validator error.
  • MethodStandardsValidator - validates that method javadocs do not contain the text @param, otherwise raises a validation error
  • ParameterStandardsValidator - validates that parameter names follow the Parchment mapping standards, otherwise raises a validation error.
  • SyntheticValidator - validates that synthetic fields, methods, and their parameters are not documented nor named (in the case of parameters), otherwise raises a validation error.
Clone this wiki locally