From 2e8c00fbacce43c436e6b5e89eb1a0860745f107 Mon Sep 17 00:00:00 2001 From: phlppchrtn Date: Fri, 31 May 2024 23:39:34 +0200 Subject: [PATCH] rem unused method --- .../java/io/vertigo/core/util/ClassUtil.java | 69 +++++++------------ .../io/vertigo/core/util/ClassUtilTest.java | 49 ------------- 2 files changed, 23 insertions(+), 95 deletions(-) diff --git a/vertigo-core/src/main/java/io/vertigo/core/util/ClassUtil.java b/vertigo-core/src/main/java/io/vertigo/core/util/ClassUtil.java index f67b6a65c..71c20c6ad 100644 --- a/vertigo-core/src/main/java/io/vertigo/core/util/ClassUtil.java +++ b/vertigo-core/src/main/java/io/vertigo/core/util/ClassUtil.java @@ -99,7 +99,7 @@ public static J newInstance(final Constructor constructor, final Object[] Assertion.check() .isNotNull(constructor) .isNotNull(args); - //----- + //--- try { return constructor.newInstance(args); } catch (final InvocationTargetException e) { @@ -111,12 +111,12 @@ public static J newInstance(final Constructor constructor, final Object[] } } - /** - * Retrieves the no-arg constructor for the given class. - * - * @param clazz The class to find the constructor for - * @return The no-arg constructor for the class - */ + /** + * Retrieves the no-arg constructor for the given class. + * + * @param clazz The class to find the constructor for + * @return The no-arg constructor for the class + */ private static Constructor findConstructor(final Class clazz) { return findConstructor(clazz, EMPTY_CLAZZ_ARRAY); } @@ -132,7 +132,7 @@ public static Constructor findConstructor(final Class clazz, final Cla Assertion.check() .isNotNull(clazz) .isNotNull(parameterTypes); - //----- + //--- try { return clazz.getConstructor(parameterTypes); } catch (final NoSuchMethodException e) { @@ -153,7 +153,7 @@ public static Constructor findConstructor(final Class clazz, final Cla public static Class classForName(final String javaClassName) { Assertion.check() .isNotBlank(javaClassName); - //----- + //--- try { return Class.forName(javaClassName); } catch (final ClassNotFoundException e) { @@ -173,7 +173,7 @@ public static Class classForName(final String javaClassName, fi Assertion.check() .isNotNull(javaClassName) .isNotNull(type); - //----- + //--- try { return Class.forName(javaClassName).asSubclass(type); } catch (final ClassNotFoundException e) { @@ -197,7 +197,7 @@ public static Object invoke(final Object instance, final Method method, final Ob Assertion.check() .isNotNull(instance) .isNotNull(method); - //----- + //--- try { return method.invoke(instance, args); } catch (final IllegalAccessException e) { @@ -218,7 +218,7 @@ public static void set(final Object instance, final Field field, final Object va Assertion.check() .isNotNull(instance) .isNotNull(field); - //----- + //--- try { field.setAccessible(true); field.set(instance, value); @@ -238,7 +238,7 @@ public static Object get(final Object instance, final Field field) { Assertion.check() .isNotNull(instance) .isNotNull(field); - //----- + //--- try { field.setAccessible(true); return field.get(instance); @@ -259,7 +259,7 @@ public static Method findMethod(final Class clazz, final String methodName, f .isNotNull(clazz) .isNotNull(methodName) .isNotNull(parameterTypes); - //----- + //--- try { return clazz.getMethod(methodName, parameterTypes); } catch (final NoSuchMethodException e) { @@ -277,7 +277,7 @@ public static Collection getAllFields(final Class clazz, final Class field.isAnnotationPresent(annotation)) @@ -294,7 +294,7 @@ public static Collection getAllMethods(final Class clazz, final Class Assertion.check() .isNotNull(clazz) .isNotNull(annotation); - //----- + //--- return ClassUtil.getAllMethods(clazz) .stream() .filter(method -> method.isAnnotationPresent(annotation)) @@ -309,7 +309,7 @@ public static Collection getAllMethods(final Class clazz, final Class public static Collection getAllFields(final Class clazz) { Assertion.check() .isNotNull(clazz); - //----- + //--- final List fields = new ArrayList<>(); final Field[] declaredFields = clazz.getDeclaredFields(); fields.addAll(Arrays.asList(declaredFields)); @@ -328,7 +328,7 @@ public static Collection getAllFields(final Class clazz) { public static Collection getAllMethods(final Class clazz) { Assertion.check() .isNotNull(clazz); - //----- + //--- final List methods = new ArrayList<>(); final Method[] declaredMethods = clazz.getDeclaredMethods(); methods.addAll(Arrays.asList(declaredMethods)); @@ -347,7 +347,7 @@ public static Collection getAllMethods(final Class clazz) { public static Set> getAllInterfaces(final Class clazz) { Assertion.check() .isNotNull(clazz); - //----- + //--- Class root = clazz; final Set> allInterfaces = new HashSet<>(); while (root != null) { @@ -375,7 +375,7 @@ public static Set> getAllInterfaces(final Class clazz) { public static Class getGeneric(final Constructor constructor, final int i) { Assertion.check() .isNotNull(constructor); - //----- + //--- return getGeneric( constructor.getGenericParameterTypes()[i], () -> new UnsupportedOperationException("La détection du générique n'a pas pu être effectuée sur le constructeur " + constructor)); @@ -394,7 +394,7 @@ public static Class getGeneric(final Constructor constructor, final int i) public static Class getGeneric(final Method method, final int i) { Assertion.check() .isNotNull(method); - //----- + //--- return getGeneric( method.getGenericParameterTypes()[i], () -> new UnsupportedOperationException("La détection du générique n'a pas pu être effectuée sur la methode " + method.getDeclaringClass() + "." + method.getName())); @@ -412,7 +412,7 @@ public static Class getGeneric(final Method method, final int i) { public static Class getGeneric(final Field field) { Assertion.check() .isNotNull(field); - //----- + //--- return getGeneric(field.getGenericType(), () -> new UnsupportedOperationException("La détection du générique n'a pas pu être effectuée sur le champ " + field.getName())); } @@ -424,7 +424,7 @@ public static Class getGeneric(final Field field) { * @param exceptionSupplier * @return first Generic of this class */ - public static Class getGeneric( + private static Class getGeneric( final Type type, final Supplier exceptionSupplier) { Assertion.check() @@ -445,27 +445,4 @@ public static Class getGeneric( } throw exceptionSupplier.get(); } - - /** - * Détermine le nom de la propriété associée à un getteur. - * @param method Méthode du getteur - * @return Nom de la propriété associée - */ - public static String getPropertyName(final Method method) { - Assertion.check() - .isNotNull(method); - //----- - final String property; - if (method.getName().startsWith("get")) { - property = method.getName().substring("get".length()); - } else if (method.getName().startsWith("is")) { - Assertion.check() - .isTrue(Boolean.class.equals(method.getReturnType()) || boolean.class.equals(method.getReturnType()), "une méthode is concerne un boolean : {0}", method); - property = method.getName().substring("is".length()); - } else { - throw new IllegalArgumentException("Method " + method + " must start with 'get' or 'is' to be considered as a property"); - } - //On abaisse la première lettre - return StringUtil.first2LowerCase(property); - } } diff --git a/vertigo-core/src/test/java/io/vertigo/core/util/ClassUtilTest.java b/vertigo-core/src/test/java/io/vertigo/core/util/ClassUtilTest.java index e7d51122c..23611b766 100644 --- a/vertigo-core/src/test/java/io/vertigo/core/util/ClassUtilTest.java +++ b/vertigo-core/src/test/java/io/vertigo/core/util/ClassUtilTest.java @@ -298,13 +298,6 @@ public List getWords() { return null; } - @Test - public void testGenericReturn() throws NoSuchMethodException, SecurityException { - assertEquals(String.class, ClassUtil.getGeneric( - this.getClass().getMethod("getWords").getGenericReturnType(), - () -> new IllegalStateException())); - } - @Test public void testGenericWithError() throws SecurityException { assertThrows(Exception.class, () -> { @@ -400,48 +393,6 @@ public void testGetAllInterfaces() throws SecurityException { assertEquals(inheritedInterfaces, interfaces); } - @Test - public void testGetPropertyName() throws NoSuchMethodException, SecurityException { - Method method; - //--- - method = MyPojo.class.getDeclaredMethod("getValue1"); - assertEquals("value1", ClassUtil.getPropertyName(method)); - //--- - method = MyPojo.class.getDeclaredMethod("getValueCamelCase"); - assertEquals("valueCamelCase", ClassUtil.getPropertyName(method)); - //--- - method = MyPojo.class.getDeclaredMethod("isValue2"); - assertEquals("value2", ClassUtil.getPropertyName(method)); - } - - @Test - public void testGetPropertyNameSetterWithError() throws NoSuchMethodException, SecurityException { - final Method method = MyPojo.class.getDeclaredMethod("setValue1", Long.class); - assertThrows(Exception.class, () -> { - final String name = ClassUtil.getPropertyName(method); - nop(name); - }); - } - - @Test - public void testGetPropertyNameIsWithError() throws NoSuchMethodException, SecurityException { - final Method method = MyPojo.class.getDeclaredMethod("isValueLong"); - - assertThrows(Exception.class, () -> { - final String name = ClassUtil.getPropertyName(method); - nop(name); - }); - } - - @Test - public void testGetPropertyNameHasWithError() throws SecurityException { - assertThrows(Exception.class, () -> { - final Method method = MyPojo.class.getDeclaredMethod("hasValue2"); - final String name = ClassUtil.getPropertyName(method); - nop(name); - }); - } - public static final class MyInjected { public Long myLong = 1L; private Long myPrivateLong = 2L;