Repository navigation
fix: do not abort generation on reserved-word property names (#418) - #426
AndreasIgel merged 21 commits into
Conversation
…rd-property-names
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
- findSetterForProperty in JavaLangAnalyser: JavaBeans convention first, then a scan over setters whose derived property name (including the getter-based reserved-name fallback) matches; used to fill BuilderFieldDto.setterName and for deprecation propagation - skip setters already covered by a constructor field once the getter-derived name is resolved (avoids duplicate renamed fields) - replace deprecated StringUtils.removeStart with Strings.CI.removeStart - simplify the setter lookup for deprecation detection and fix a broken comment wrap
…elds (java-helpers#418) - extract the setter's property-name derivation into public JavaLangAnalyser.resolveSetterPropertyName and reuse it in createFieldFromSetter (removes the duplicated getter-fallback block) - setter-discovered fields take the name from the already-iterated setter element; findSetterForProperty only runs for constructor-parameter fields and the deprecation lookup
… setter-name assignment
|
Check coverage in SonarQube, looks like the case of non getter found is never reached!? Why is this the case? Shouldn't we have already a test, where a setter without getter is defined? Ahhh, but that then would not have multiple candidates for getters? Maybe having a test with getters with different cases? But then the exact same case should be winning and this is currently not the case!? |
|
Addressed in
The processor-level paths (skip-warning and strict-mode error for |
|



Summary
Closes #418.
setX-> propertyxcan produce a reserved keyword (setStatic->static). Before this change, that aborted generation for the whole target class.BuilderDefinitionCreatortakes the property name from a matching getter (isStatic()->isStatic). Generated methods:isStatic(boolean), orwithIsStatic(boolean)with a setter prefix.build()still callssetStatic(...).JavaLangAnalyser.findGettersForFieldorders candidatesis*->get*-> accessor-style, so declaration order no longer decides. The builder-sideresolveBuilderPropertyNamereturnsOptionaland only yields names backed by a real, non-ignored getter.BuilderFieldDto.getSetterName()returnsOptional<String>. Setter-based fields keep the name of the setter that discovered them. Constructor fields get the setter found by the builder-sidefindBuilderSetterForProperty, or stay empty when no setter exists; noset<Cap>name is invented.CoreMethodsEnhancerthrows a descriptiveIllegalStateException(field + DTO) if a setter-based field ever has no setter name; that is an internal invariant.buildSetterSourceDescriptionuses the same guard;BuilderProcessor.analyserethrows anyIllegalStateExceptionfrom builder extraction as aBuilderExceptionon the annotated element (warning, or error in strict mode). Setter/getter property names come from one helper,propertyNameFromAccessor, which strips only a lowercaseset/getfollowed by an uppercase letter.set+ uppercase shape and one parameter, and prefix-free methods are never setters. On top of the genericJavaLangAnalyserlookups,BuilderDefinitionCreatorapplies the same eligibility as setter discovery:void, non-static, accessible, not@IgnoreInBuilder. An ignored getter therefore cannot supply a reserved name, and an ignored or ineligible setter is not used for constructor-field setter or deprecation lookup.@IgnoreInBuildertargets: now{METHOD, CONSTRUCTOR};PARAMETERwas dropped because the processor never read it there. Automatic constructor selection skips ignored constructors.@IgnoreInBuildertogether with@SimpleBuilderConstructoron one constructor skips generation with one diagnostic: a warning, or an error in strict mode. If every accessible constructor is ignored, the existing "no accessible constructor" diagnostic applies: a warning, or an error in strict mode. The performance-test generator no longer annotates record components.docs/CONFIGURATION.mdhas a new section, "Property Detection and Ignoring Members", covering setter detection,@IgnoreInBuilderand reserved-word names. README links to it.Tests
ReservedPropertyNameTest: parameterized over all Java keywords plustrue/false/null; exact generated declarations for plain and prefixed naming, unusable and ignored getters, getter priority, strict mode (failed()with message and source location), and a constructor property not duplicated by a setter with a different name.JavaLangAnalyserTest: getter ordering and setter shape rules.BuilderProcessorTest: exact error/warning counts for the constructor conflict, and the all-constructors-ignored case in both normal and strict mode.CoreMethodsEnhancerTest: resolved setter, missing setter name (exception), constructor-only fields, and no fields.BuilderProcessorTest: an ignored larger constructor makes the builder use the smaller one, both annotations together (exact counts per mode, message and location), all constructors ignored, an ignored only-parameterized constructor, and the annotation on a parameter no longer compiles.BuilderDefinitionCreatorTest: accessor name derivation (settings(),getaway(),isStatic, ...) and the setter source description.AnnotationCopyTest: ignored or ineligible@Deprecatedsetters do not mark constructor fields as deprecated.Known limitations (not changed here)
@IgnoreInBuilder. This was already the case onmainand is tracked in Copy constructor calls getters annotated with @IgnoreInBuilder #437.Verified:
mvn clean verifypasses (processor: 624 tests). Generated examples are unchanged.