diff --git a/model/build-processor/src/main/java/org/keycloak/models/map/processor/GenerateEntityImplementationsProcessor.java b/model/build-processor/src/main/java/org/keycloak/models/map/processor/GenerateEntityImplementationsProcessor.java index 1c34156f80..d905ab50d3 100644 --- a/model/build-processor/src/main/java/org/keycloak/models/map/processor/GenerateEntityImplementationsProcessor.java +++ b/model/build-processor/src/main/java/org/keycloak/models/map/processor/GenerateEntityImplementationsProcessor.java @@ -177,15 +177,14 @@ public class GenerateEntityImplementationsProcessor extends AbstractGenerateEnti pw.println(" return FIELD_NAME_CAMEL_CASE;"); pw.println(" }"); - FieldAccessorType.getMethod(FieldAccessorType.COLLECTION_ADD, methods, fieldName, types, fieldType).ifPresent(method -> { - TypeMirror firstParameterType = method.getParameters().get(0).asType(); - pw.println(" @SuppressWarnings(\"unchecked\") @Override public Class getCollectionElementClass() {"); - pw.println(" return " + types.erasure(firstParameterType) + ".class;"); - pw.println(" }"); - }); - FieldAccessorType.getMethod(FieldAccessorType.GETTER, methods, fieldName, types, fieldType).ifPresent(method -> { - if (Util.isMapType((TypeElement) types.asElement(types.erasure(fieldType)))) { + if (Util.isCollectionType((TypeElement) types.asElement(types.erasure(fieldType)))) { + TypeMirror firstParameterType = Util.getGenericsDeclaration(method.getReturnType()).get(0); + pw.println(" @SuppressWarnings(\"unchecked\") @Override public Class getCollectionElementClass() {"); + pw.println(" return " + types.erasure(firstParameterType) + ".class;"); + pw.println(" }"); + + } else if (Util.isMapType((TypeElement) types.asElement(types.erasure(fieldType)))) { TypeMirror firstParameterType = Util.getGenericsDeclaration(method.getReturnType()).get(0); TypeMirror secondParameterType = Util.getGenericsDeclaration(method.getReturnType()).get(1); diff --git a/model/build-processor/src/main/java/org/keycloak/models/map/processor/Util.java b/model/build-processor/src/main/java/org/keycloak/models/map/processor/Util.java index a89a127bc7..0971edccfa 100644 --- a/model/build-processor/src/main/java/org/keycloak/models/map/processor/Util.java +++ b/model/build-processor/src/main/java/org/keycloak/models/map/processor/Util.java @@ -17,7 +17,7 @@ package org.keycloak.models.map.processor; import org.keycloak.models.map.annotations.IgnoreForEntityImplementationGenerator; -import java.util.Arrays; +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashSet; @@ -45,8 +45,9 @@ import javax.lang.model.util.SimpleTypeVisitor8; */ public class Util { - private static final HashSet SET_TYPES = new HashSet<>(Arrays.asList(Set.class.getCanonicalName(), TreeSet.class.getCanonicalName(), HashSet.class.getCanonicalName(), LinkedHashSet.class.getCanonicalName())); - private static final HashSet MAP_TYPES = new HashSet<>(Arrays.asList(Map.class.getCanonicalName(), HashMap.class.getCanonicalName())); + private static final Set LIST_TYPES = Set.of(List.class.getCanonicalName(), ArrayList.class.getCanonicalName(), LinkedList.class.getCanonicalName()); + private static final Set SET_TYPES = Set.of(Set.class.getCanonicalName(), TreeSet.class.getCanonicalName(), HashSet.class.getCanonicalName(), LinkedHashSet.class.getCanonicalName()); + private static final Set MAP_TYPES = Set.of(Map.class.getCanonicalName(), HashMap.class.getCanonicalName()); public static List getGenericsDeclaration(TypeMirror fieldType) { List res = new LinkedList<>(); @@ -69,6 +70,15 @@ public class Util { .collect(Collectors.joining(", ")); } + public static boolean isCollectionType(TypeElement typeElement) { + return isListType(typeElement) || isSetType(typeElement); + } + + public static boolean isListType(TypeElement typeElement) { + Name name = typeElement.getQualifiedName(); + return LIST_TYPES.contains(name.toString()); + } + public static boolean isSetType(TypeElement typeElement) { Name name = typeElement.getQualifiedName(); return SET_TYPES.contains(name.toString());