From 82f69bea32a0548fa88ad1a1f6f225e1352fafd9 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 24 Nov 2026 23:23:24 +0000 Subject: [PATCH 1/4] feat(codegen-core): add RegularImport(Class) convenience constructor Allows new RegularImport(Instant.class) instead of new RegularImport(TypeName.of(Instant.class)), matching the TypeName.of(Class) shortcuts elsewhere. Related to #415. --- .../javahelpers/codegen/model/imports/RegularImport.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/codegen-core/src/main/java/org/javahelpers/codegen/model/imports/RegularImport.java b/codegen-core/src/main/java/org/javahelpers/codegen/model/imports/RegularImport.java index 2aa808f2..f3bd8f7d 100644 --- a/codegen-core/src/main/java/org/javahelpers/codegen/model/imports/RegularImport.java +++ b/codegen-core/src/main/java/org/javahelpers/codegen/model/imports/RegularImport.java @@ -41,6 +41,15 @@ public class RegularImport implements ImportStatement { private final TypeName type; + /** + * Creates a regular import from a class. + * + * @param clazz the class to import + */ + public RegularImport(Class clazz) { + this(TypeName.of(clazz)); + } + /** * Creates a regular import from a TypeName. * From a502f41f35b34186af6e22e080f711f2978d563d Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 24 Nov 2026 23:23:59 +0000 Subject: [PATCH 2/4] feat(codegen-core): add StaticImport(Class, memberName) convenience constructor --- .../codegen/model/imports/StaticImport.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/codegen-core/src/main/java/org/javahelpers/codegen/model/imports/StaticImport.java b/codegen-core/src/main/java/org/javahelpers/codegen/model/imports/StaticImport.java index dc989877..ee615834 100644 --- a/codegen-core/src/main/java/org/javahelpers/codegen/model/imports/StaticImport.java +++ b/codegen-core/src/main/java/org/javahelpers/codegen/model/imports/StaticImport.java @@ -40,6 +40,16 @@ public class StaticImport implements ImportStatement { private final TypeName type; private final String memberName; + /** + * Creates a static import from a class. + * + * @param clazz the class containing the static member + * @param memberName the name of the static member (method or field) + */ + public StaticImport(Class clazz, String memberName) { + this(TypeName.of(clazz), memberName); + } + /** * Creates a static import. * From 3e5d2a3e2880dee94f76c346f83f4bd43c4b038f Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 24 Nov 2026 23:26:06 +0000 Subject: [PATCH 3/4] fix(codegen-core): reject non-plain type kinds in AnnotationDto.setAnnotationType (#445) Annotations can never be generic, array, map, set, wildcard, primitive or type-variable typed; previously such invalid models were silently accepted and only surfaced as broken generated source. --- .../model/annotation/AnnotationDto.java | 18 +++++ .../model/annotation/AnnotationDtoTest.java | 66 +++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 codegen-core/src/test/java/org/javahelpers/codegen/model/annotation/AnnotationDtoTest.java diff --git a/codegen-core/src/main/java/org/javahelpers/codegen/model/annotation/AnnotationDto.java b/codegen-core/src/main/java/org/javahelpers/codegen/model/annotation/AnnotationDto.java index 73bfc2a8..4fada0b1 100644 --- a/codegen-core/src/main/java/org/javahelpers/codegen/model/annotation/AnnotationDto.java +++ b/codegen-core/src/main/java/org/javahelpers/codegen/model/annotation/AnnotationDto.java @@ -29,6 +29,13 @@ import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; import org.javahelpers.codegen.model.type.TypeName; +import org.javahelpers.codegen.model.type.TypeNameArray; +import org.javahelpers.codegen.model.type.TypeNameGeneric; +import org.javahelpers.codegen.model.type.TypeNameMap; +import org.javahelpers.codegen.model.type.TypeNamePrimitive; +import org.javahelpers.codegen.model.type.TypeNameSet; +import org.javahelpers.codegen.model.type.TypeNameVariable; +import org.javahelpers.codegen.model.type.TypeNameWildcard; /** * DTO representing an annotation to be generated in the output class. Contains the annotation type @@ -60,6 +67,17 @@ public TypeName getAnnotationType() { * @param annotationType the type of the annotation */ public void setAnnotationType(TypeName annotationType) { + if (annotationType instanceof TypeNameGeneric + || annotationType instanceof TypeNameArray + || annotationType instanceof TypeNameMap + || annotationType instanceof TypeNameSet + || annotationType instanceof TypeNameWildcard + || annotationType instanceof TypeNamePrimitive + || annotationType instanceof TypeNameVariable) { + throw new IllegalArgumentException( + "annotationType must be a plain class type; annotations can never be " + + annotationType.getClass().getSimpleName()); + } this.annotationType = annotationType; } diff --git a/codegen-core/src/test/java/org/javahelpers/codegen/model/annotation/AnnotationDtoTest.java b/codegen-core/src/test/java/org/javahelpers/codegen/model/annotation/AnnotationDtoTest.java new file mode 100644 index 00000000..63815eb6 --- /dev/null +++ b/codegen-core/src/test/java/org/javahelpers/codegen/model/annotation/AnnotationDtoTest.java @@ -0,0 +1,66 @@ +/* + * MIT License + * + * Copyright (c) 2025-2026 Andreas Igel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package org.javahelpers.codegen.model.annotation; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.javahelpers.codegen.model.type.TypeName; +import org.javahelpers.codegen.model.type.TypeNameArray; +import org.javahelpers.codegen.model.type.TypeNameGeneric; +import org.javahelpers.codegen.model.type.TypeNameMap; +import org.javahelpers.codegen.model.type.TypeNamePrimitive; +import org.javahelpers.codegen.model.type.TypeNameSet; +import org.javahelpers.codegen.model.type.TypeNameVariable; +import org.javahelpers.codegen.model.type.TypeNameWildcard; +import org.junit.jupiter.api.Test; + +/** Tests for {@link AnnotationDto#setAnnotationType(TypeName)} validation. */ +class AnnotationDtoTest { + + @Test + void acceptsPlainClassType() { + AnnotationDto dto = new AnnotationDto(); + assertDoesNotThrow(() -> dto.setAnnotationType(new TypeName("java.lang", "Deprecated"))); + assertDoesNotThrow(() -> dto.setAnnotationType(TypeName.of(Deprecated.class))); + } + + @Test + void rejectsNonPlainTypeKinds() { + TypeName plain = new TypeName("java.lang", "Deprecated"); + assertRejects(TypeNameGeneric.of(java.util.List.class, String.class)); + assertRejects(TypeNameArray.of(String.class)); + assertRejects(TypeNameMap.of(String.class, Integer.class)); + assertRejects(TypeNameSet.of(String.class)); + assertRejects(TypeNameWildcard.extendsBound(plain)); + assertRejects(TypeNamePrimitive.INT); + assertRejects(new TypeNameVariable("T")); + } + + private static void assertRejects(TypeName type) { + AnnotationDto dto = new AnnotationDto(); + assertThrows(IllegalArgumentException.class, () -> dto.setAnnotationType(type)); + } +} From dcf18764861d75004b1b86dde20028054030056f Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 24 Nov 2026 23:32:43 +0000 Subject: [PATCH 4/4] refactor: slim annotationType validation, use wildcard import TypeNameMap/TypeNameSet/TypeNameList all extend TypeNameGeneric, so the explicit checks were dead code (CodeQL 'contradictory type checks'). TypeNameGeneric alone covers them. --- .../codegen/model/annotation/AnnotationDto.java | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/codegen-core/src/main/java/org/javahelpers/codegen/model/annotation/AnnotationDto.java b/codegen-core/src/main/java/org/javahelpers/codegen/model/annotation/AnnotationDto.java index 4fada0b1..e91dbdd6 100644 --- a/codegen-core/src/main/java/org/javahelpers/codegen/model/annotation/AnnotationDto.java +++ b/codegen-core/src/main/java/org/javahelpers/codegen/model/annotation/AnnotationDto.java @@ -28,14 +28,7 @@ import java.util.Map; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.javahelpers.codegen.model.type.TypeName; -import org.javahelpers.codegen.model.type.TypeNameArray; -import org.javahelpers.codegen.model.type.TypeNameGeneric; -import org.javahelpers.codegen.model.type.TypeNameMap; -import org.javahelpers.codegen.model.type.TypeNamePrimitive; -import org.javahelpers.codegen.model.type.TypeNameSet; -import org.javahelpers.codegen.model.type.TypeNameVariable; -import org.javahelpers.codegen.model.type.TypeNameWildcard; +import org.javahelpers.codegen.model.type.*; /** * DTO representing an annotation to be generated in the output class. Contains the annotation type @@ -69,8 +62,6 @@ public TypeName getAnnotationType() { public void setAnnotationType(TypeName annotationType) { if (annotationType instanceof TypeNameGeneric || annotationType instanceof TypeNameArray - || annotationType instanceof TypeNameMap - || annotationType instanceof TypeNameSet || annotationType instanceof TypeNameWildcard || annotationType instanceof TypeNamePrimitive || annotationType instanceof TypeNameVariable) {