[
https://issues.apache.org/jira/browse/WW-5817?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Lukasz Lenart updated WW-5817:
------------------------------
Fix Version/s: 7.6.0
> Reduce duplication across the range validator annotations and their
> configuration builder methods
> -------------------------------------------------------------------------------------------------
>
> Key: WW-5817
> URL: https://issues.apache.org/jira/browse/WW-5817
> Project: Struts 2
> Issue Type: Improvement
> Components: Annotations
> Reporter: Lukasz Lenart
> Priority: Major
> Fix For: 7.6.0
>
>
> SonarCloud flags duplicated code in the range validators (8.7% duplicated
> lines on new code in apache/struts#2060, WW-5816).
> h2. What is duplicated
> * *{{AnnotationValidationConfigurationBuilder}}:*
> {{processIntRangeFieldValidatorAnnotation}},
> {{processLongRangeFieldValidatorAnnotation}},
> {{processShortRangeFieldValidatorAnnotation}},
> {{processDateRangeFieldValidatorAnnotation}} and
> {{processLocalDateRangeFieldValidatorAnnotation}} repeat the same steps:
> {{fieldName}} resolution, {{min}}/{{max}}/{{minExpression}}/{{maxExpression}}
> params, and the {{ValidatorConfig.Builder}} chain with {{methodName}},
> {{shortCircuit}}, {{message}}, {{key}} and {{messageParams}}. Only the
> validator type and how {{min}}/{{max}} are parsed differ. The per-annotation
> loops over {{@Validations}} members also repeat the same null checks.
> * *The annotations:* {{@IntRangeFieldValidator}},
> {{@LongRangeFieldValidator}}, {{@ShortRangeFieldValidator}} and
> {{@LocalDateRangeFieldValidator}} declare the same members with the same
> javadoc. Java annotations cannot inherit members, so this part can only be
> reduced in the javadoc, not in the declarations.
> h2. Proposal
> * Extract a shared helper in {{AnnotationValidationConfigurationBuilder}} for
> the common range params and the builder chain, taking the validator type and
> a bound parser.
> * Leave the annotation declarations as they are, since they cannot be shared.
> Consider whether Sonar should exclude annotation definitions from the
> duplication check.
> This is a refactoring only, with no behaviour change. The existing
> {{AnnotationValidationConfigurationBuilderTest}} covers it.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)