Repository navigation
fix: keep generic owners of inner classes and drop redundant enclosing check - #438
Merged
AndreasIgel merged 25 commits intoDec 1, 2026
Conversation
The enclosing TypeName was resolved but only read by a condition whose both outcomes produced the same wrapInCollectionTypeIfApplicable(List.of()) result. Removing it reduces cognitive complexity below the Sonar limit (17 -> <15) with no behavior change.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
AndreasIgel
reviewed
Nov 23, 2026
…cognitive-complexity
…plexity' into fix/javalangmapper-cognitive-complexity
…cognitive-complexity
…and member/static checks
AndreasIgel
reviewed
Nov 23, 2026
This was referenced Nov 23, 2026
…cognitive-complexity # Conflicts: # codegen-roaster/src/test/java/org/javahelpers/codegen/roaster/RoasterCodeGeneratorTest.java
This was referenced Nov 30, 2026
AndreasIgel
reviewed
Nov 30, 2026
…ruction, docs and formatting fixes
…plexity' into fix/javalangmapper-cognitive-complexity # Conflicts: # codegen-roaster/src/test/java/org/javahelpers/codegen/roaster/RoasterCodeGeneratorTest.java
…block test for generic With interface The unresolved merge-conflict marker block in RoasterCodeGeneratorTest broke test compilation and with it the CI pipeline. Also adds a textblock comparison verifying the full generated shape of the generic With<T> interface for generic DTOs (type parameter declaration, SuppressWarnings annotations, typed builder references).
…DtoBuilder NestedTypeDtoBuilder gains the full variant set for genericParameters: singular element-add, consumer-based construction, varargs of both, plus flattened shortcuts genericParameter(String), genericParameter(String, TypeName...) and genericParameterWithUpperBound(String, Class...). BuilderMethodDtoBuilder gains the flattened shortcuts to match its codegen-core sibling MethodDtoBuilder.
AndreasIgel
reviewed
Dec 1, 2026
…meter helpers - NestedTypeDto/Builder: javadoc on genericParameters field restored/placed, wholesale setters moved down grouped with the field's other functions, varargs-consumer overload renamed to plural genericParameters - BuilderNestedTypeDtoBuilder: full genericParameter helper set (singular, consumer, varargs, flattened shortcuts) grouped below the fields - BuilderProcessorTest: single-line text blocks converted to plain strings, multi-line source concatenations converted to text blocks, indent of test sources aligned with delimiters
…ders Varargs consumers assign multiple elements in one call, so the plural name fits the semantics: annotation->annotations, method->methods, parameter->parameters, classField->classFields, constructor->constructors, nestedType->nestedTypes, generic->generics, genericParameter->genericParameters. Multi-lambda call sites in tests and main code swept and renamed.
Covers singular/consumer/varargs/flattened-shortcut variants in NestedTypeDtoBuilder, BuilderNestedTypeDtoBuilder and BuilderMethodDtoBuilder including wholesale replacement and copy-constructor preservation.
…-manager.devin.ai/proxy/github.com/igel-devin-ai/simple-builders-devin-fork into fix/javalangmapper-cognitive-complexity
…meters Covers TypeNameWildcard mapping (unbounded, extends, super) in field types and nested interface/class type-variable rendering incl. upper bounds.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Resolves Sonar's cognitive-complexity finding on
JavaLangMapper.extractType(17 > 15) and fixes generation for parameterized inner classes, building on the inner-class groundwork merged in #439. Branch is current with main (including the merged #429 DTO builders).1. Redundant enclosing-type check removed (
visitDeclared)The resolved
enclosingTypeName was only read byt.getTypeArguments().isEmpty() && !(enclosing instanceof TypeNameGeneric). Both outcomes produced the samewrapInCollectionTypeIfApplicable(rawType, List.of(), ...), so the check never had an effect. It and the redundant secondisEmptyguard are collapsed into onetypeArguments.isEmpty()branch.2. Generic owners of non-static inner classes are kept
Previously
Outer<String>.Innerwas generated as the rawOuter.Inner, andOuter<String>.Inner2<Integer>asOuter.Inner2<Integer>, which does not compile.JavaLangMapper: for non-static member types, the actual enclosingDeclaredTypeis mapped into theTypeNameNestedowner. Static nested types keep their raw owner as before.TypeNameNested/TypeNameGeneric:getFullQualifiedName()andgetSimpleNameWithGenerics()render the owner's type arguments;getClassName()stays raw. NewTypeName.getRawQualifiedName()gives the erased declaration name.BuilderProcessingContext,AnnotationProcessingContext) usegetRawQualifiedName(), so owners likeOuter<? extends Number>.Innerno longer produceimport other.Outer<? extends java.lang.Number>.Inner;. Owner type arguments (incl. wildcard bounds) are still imported.RoasterMapper: type-use annotations on owner arguments are kept (Outer<@Nullable String>.Inner), like on ordinary generic arguments.RoasterCodeGenerator: Roaster'saddParametercannot parse a type with generics on both owner and member (Outer<String>.Inner2<Integer>), so for types containing>.the parameter list is set viasetParameters. All other parameters useaddParameteras before.3. Generic DTOs keep their type variables in owners
For
Dto<T>withOuter<T>.Inner, the copy constructor, conditional helpers andWith<T>now use the parameterized DTO/builder types instead of raw ones. The nestedWithinterface declares the DTO's type parameters;with()casts(Dto<T>) Dto.class.cast(this)under a local@SuppressWarnings("unchecked").4. No instantiation of non-static inner classes
setEmptyConstructorInfono longer marks non-static member classes as constructible, sincenew Outer.Inner()needs an enclosing instance. This removes the invalid consumer helper and thenew X()/X::newJavadoc examples for these types.Tests
-Xlint:rawtypes -Xlint:unchecked, strict):Outer<String>.Inner,Inner2<Integer>, wildcard owners,Outer<T>.Innerin generic DTOs (unbounded and intersection bounds) and annotated owner arguments compile without warnings and without an instance consumer.List<Outer<String>.Inner>, alsoList<Set<String>>on main) still emit the existing heap-pollution warning; simple-name collisions between a nested and a top-level type of the same name are out of scope.