From 458fe64d43a4c56e58c43d6714f0e94be4defab1 Mon Sep 17 00:00:00 2001 From: homedirectory Date: Tue, 17 Sep 2024 13:24:17 +0300 Subject: [PATCH] #2313 Modernise EntityUtils#findSyntheticModelFieldFor --- .../fielden/platform/utils/EntityUtils.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/platform-pojo-bl/src/main/java/ua/com/fielden/platform/utils/EntityUtils.java b/platform-pojo-bl/src/main/java/ua/com/fielden/platform/utils/EntityUtils.java index 01a16cdf29..90368f2c68 100644 --- a/platform-pojo-bl/src/main/java/ua/com/fielden/platform/utils/EntityUtils.java +++ b/platform-pojo-bl/src/main/java/ua/com/fielden/platform/utils/EntityUtils.java @@ -28,6 +28,7 @@ import ua.com.fielden.platform.types.try_wrapper.TryWrapper; import ua.com.fielden.platform.types.tuples.T2; +import javax.annotation.Nullable; import java.io.Serializable; import java.lang.reflect.Constructor; import java.lang.reflect.Field; @@ -731,21 +732,22 @@ public static boolean isSyntheticEntityType(final Class type) { } /** - * A helper method to determine if {@code entityType} contains either static field "mode_" or "models_" of the appropriate types, which indicates that {@code entityType} is a synthetic entity. + * If {@code entityType} contains either static field "model_" or "models_" of the appropriate types, indicating that + * it's a synthetic entity, returns that field. Otherwise, returns {@code null}. *

- * It became required to traverse the type hierarchy instead of relying on declared fields with the implementation of issue #1692, which started generating types as subclasses of the original ones. + * Since issue #1692, which started generating types as + * subclasses of the original ones, static fields from supertypes are considered as well. * - * @param - * @param entityType to be analysed. - * @return either a field corresponding to {@code model_} or {@code models_}, or {@code null}. + * @param entityType entity type to be analysed + * @return either a field corresponding to {@code model_} or {@code models_}, or {@code null} */ - public static > Field findSyntheticModelFieldFor(final Class entityType) { + public static > @Nullable Field findSyntheticModelFieldFor(final Class entityType) { Class klass = entityType; while (klass != AbstractEntity.class) { // iterated thought hierarchy for (final Field field : klass.getDeclaredFields()) { if (isStatic(field.getModifiers())) { - if ("model_".equals(field.getName()) && EntityResultQueryModel.class.equals(field.getType()) || - "models_".equals(field.getName()) && List.class.equals(field.getType())) { + if ("model_".equals(field.getName()) && EntityResultQueryModel.class == field.getType() || + "models_".equals(field.getName()) && List.class.isAssignableFrom(field.getType())) { return field; } }