Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
9297269
Adding tests for Helpers should support special collections
AndreasIgel Dec 22, 2025
cefa3e0
Refactoring in BuilderDefinitionCreator to use FieldDto instead of in…
AndreasIgel Dec 22, 2025
3f28683
Adding new functionality to detect lists, sets and maps
AndreasIgel Dec 23, 2025
7905046
Refactoring code to support wrapping of special collectiontypes
AndreasIgel Dec 25, 2025
6edd3b4
Refactoring createFieldSetterForCollectionType to support simple list…
AndreasIgel Dec 25, 2025
d9c4301
Removing unused parameter fillsSet / isSet
AndreasIgel Dec 25, 2025
ecc06f1
Refactoring code to have Lists/Maps/Sets in a specific TypeName
AndreasIgel Dec 25, 2025
4cd8ed7
Extracting the elementTypes of collections from interface-implementat…
AndreasIgel Dec 25, 2025
e77607a
Adding a test for a class, where the number of generics is just 1 for…
AndreasIgel Dec 25, 2025
cda0aff
Extending tests for having tests on raw CollectionTypes too
AndreasIgel Dec 25, 2025
ed222e4
Renaming functions for improving readability
AndreasIgel Dec 25, 2025
191d38f
Trying to fix codesmell issues
AndreasIgel Dec 25, 2025
4b8462c
Removing unused function
AndreasIgel Dec 25, 2025
a446c0f
Fixing codestyle
AndreasIgel Dec 25, 2025
62e0b89
Fixing codesmell in TypeNameGeneric, because the collection is alread…
AndreasIgel Dec 28, 2025
05f3ed2
Adding a test for unmodifiable Lists
AndreasIgel Dec 28, 2025
4b1c410
Removing unused constructors
AndreasIgel Dec 28, 2025
510e68d
Extracting functionality into hasConstructorWithParameterOfType to re…
AndreasIgel Dec 28, 2025
8487e76
Refactoring CustomCollectionTypeTest to use helperfunctions
AndreasIgel Dec 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,26 @@
/** TypeName is a specific array type. Holding name of class and package of inner type. */
public class TypeNameArray extends TypeName {
private final TypeName typeOfArray;
private final boolean fillsSet;

/**
* Constructor for simple classes.
*
* @param packageName name of package
* @param className name of class, could not be null
* @param isSet {@code true} if this array represents a set
*/
public TypeNameArray(String packageName, String className, boolean isSet) {
public TypeNameArray(String packageName, String className) {
super(packageName, className);
this.typeOfArray = new TypeName(packageName, className);
this.fillsSet = isSet;
}

/**
* Constructor with innerType.
*
* @param innerType name of package
* @param isSet {@code true} if this array represents a set
*/
public TypeNameArray(TypeName innerType, boolean isSet) {
public TypeNameArray(TypeName innerType) {
super(innerType.getPackageName(), innerType.getClassName());
this.typeOfArray = innerType;
this.fillsSet = isSet;
}

/**
Expand All @@ -76,13 +71,4 @@ public Optional<TypeName> getInnerType() {
public TypeName getTypeOfArray() {
return typeOfArray;
}

/**
* Getter for fillsSet.
*
* @return {@code true}, if this is array that should fill a set
*/
public boolean isFillingSet() {
return fillsSet;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
package org.javahelpers.simple.builders.processor.dtos;

import java.util.Collections;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -99,7 +98,7 @@ public TypeNameGeneric(String packageName, String className, TypeName... innerTy
* @return an unmodifiable list of inner type arguments
*/
public List<TypeName> getInnerTypeArguments() {
return Collections.unmodifiableList(innerTypeArguments);
return innerTypeArguments;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
* MIT License
*
* Copyright (c) 2025 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.simple.builders.processor.dtos;

import java.util.List;
import org.apache.commons.lang3.Strings;

/**
* Represents a type that implements the {@code java.util.List} interface.
*
* <p>This includes the List interface itself as well as any concrete implementations like
* ArrayList, LinkedList, Vector, Stack, or custom List implementations.
*
* <p>The concrete class name (e.g., "ArrayList") is preserved in the package and class name fields,
* while this subclass indicates that the type implements the List interface.
*
* <p>Examples:
*
* <ul>
* <li>{@code List<String>} -&gt; TypeNameList with 1 inner type argument
* <li>{@code ArrayList<Person>} -&gt; TypeNameList with 1 inner type argument
* <li>{@code List} (raw type) -&gt; TypeNameList with 0 inner type arguments
* </ul>
*/
public class TypeNameList extends TypeNameGeneric {

private final boolean isConcreteImplementation;
private final TypeName elementType;

/**
* Checks if the given package and class name represent the {@code java.util.List} interface.
*
* @param packageName the package name
* @param className the class name
* @return {@code true} if this is {@code java.util.List}
*/
private static boolean isListInterface(String packageName, String className) {
return Strings.CI.equals(packageName, "java.util") && Strings.CI.equals(className, "List");
}

/**
* Creates a {@code TypeNameList} based on another {@code TypeName} as outer type and a list of
* inner type arguments.
*
* @param outerType the outer type to use for package and class name (the concrete List
* implementation)
* @param innerTypeArguments the list of generic type arguments (all class type parameters)
* @param elementType the actual List element type (extracted from List interface)
*/
public TypeNameList(TypeName outerType, List<TypeName> innerTypeArguments, TypeName elementType) {
super(outerType, innerTypeArguments);
this.isConcreteImplementation = !isListInterface(getPackageName(), getClassName());
this.elementType = elementType;
}

/**
* Checks if this is a concrete List implementation (not the interface itself).
*
* @return {@code true} for concrete implementations like ArrayList, LinkedList, etc., {@code
* false} if this is {@code java.util.List}
*/
public boolean isConcreteImplementation() {
return isConcreteImplementation;
}

/**
* Checks if this List type is properly parameterized (not a raw type).
*
* <p>A parameterized List has an element type extracted from the List interface. A raw List has
* no element type.
*
* <p>This works correctly for both standard Lists like {@code List<String>} and custom
* implementations like {@code CustomList<X,Y> extends ArrayList<Y>}.
*
* @return {@code true} if this List has an element type
*/
public boolean isParameterized() {
return elementType != null;
}

/**
* Gets the element type of this List.
*
* <p>For a parameterized List like {@code List<String>}, this returns the String type.
*
* <p>For custom implementations like {@code CustomList<X,Y> extends ArrayList<Y>}, this returns Y
* (the actual List element type), not X or both X and Y.
*
* @return the element type (extracted from the List interface)
* @throws IllegalStateException if this is a raw List with no type arguments
*/
public TypeName getElementType() {
if (elementType == null) {
throw new IllegalStateException(
"Cannot get element type from raw List type: " + getClassName());
}
return elementType;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* MIT License
*
* Copyright (c) 2025 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.simple.builders.processor.dtos;

import java.util.List;
import org.apache.commons.lang3.Strings;

/**
* Represents a type that implements the {@code java.util.Map} interface.
*
* <p>This includes the Map interface itself as well as any concrete implementations like HashMap,
* LinkedHashMap, TreeMap, Hashtable, or custom Map implementations.
*
* <p>The concrete class name (e.g., "HashMap") is preserved in the package and class name fields,
* while this subclass indicates that the type implements the Map interface.
*
* <p>Examples:
*
* <ul>
* <li>{@code Map<String, Integer>} -&gt; TypeNameMap with 2 inner type arguments
* <li>{@code HashMap<String, Person>} -&gt; TypeNameMap with 2 inner type arguments
* <li>{@code Map} (raw type) -&gt; TypeNameMap with 0 inner type arguments
* </ul>
*/
public class TypeNameMap extends TypeNameGeneric {

private final boolean isConcreteImplementation;
private final TypeName keyType;
private final TypeName valueType;

/**
* Checks if the given package and class name represent the {@code java.util.Map} interface.
*
* @param packageName the package name
* @param className the class name
* @return {@code true} if this is {@code java.util.Map}
*/
private static boolean isMapInterface(String packageName, String className) {
return Strings.CI.equals(packageName, "java.util") && Strings.CI.equals(className, "Map");
}

/**
* Creates a {@code TypeNameMap} based on another {@code TypeName} as outer type and a list of
* inner type arguments.
*
* @param outerType the outer type to use for package and class name (the concrete Map
* implementation)
* @param innerTypeArguments the list of generic type arguments (all class type parameters)
* @param keyType the actual Map key type (extracted from Map interface)
* @param valueType the actual Map value type (extracted from Map interface)
*/
public TypeNameMap(
TypeName outerType, List<TypeName> innerTypeArguments, TypeName keyType, TypeName valueType) {
super(outerType, innerTypeArguments);
this.isConcreteImplementation = !isMapInterface(getPackageName(), getClassName());
this.keyType = keyType;
this.valueType = valueType;
}

/**
* Checks if this is a concrete Map implementation (not the interface itself).
*
* @return {@code true} for concrete implementations like HashMap, TreeMap, etc., {@code false} if
* this is {@code java.util.Map}
*/
public boolean isConcreteImplementation() {
return isConcreteImplementation;
}

/**
* Checks if this Map type is properly parameterized (not a raw type).
*
* <p>A parameterized Map has exactly 2 type arguments (key and value types). A raw Map has 0 type
* arguments.
*
* @return {@code true} if this Map has exactly 2 type arguments
*/
public boolean isParameterized() {
return keyType != null && valueType != null;
}

/**
* Gets the key type of this Map.
*
* <p>For a parameterized Map like {@code Map<String, Integer>}, this returns the String type.
*
* @return the key type (first type argument)
* @throws IllegalStateException if this is a raw Map with no type arguments
*/
public TypeName getKeyType() {
if (keyType == null) {
throw new IllegalStateException("Cannot get key type from raw Map type: " + getClassName());
}
return keyType;
}

/**
* Gets the value type of this Map.
*
* <p>For a parameterized Map like {@code Map<String, Integer>}, this returns the Integer type.
*
* @return the value type (second type argument)
* @throws IllegalStateException if this is a raw Map with no type arguments
*/
public TypeName getValueType() {
if (valueType == null) {
throw new IllegalStateException("Cannot get value type from raw Map type: " + getClassName());
}
return valueType;
}
}
Loading
Loading