Skip to content

Commit

Permalink
rem unused method
Browse files Browse the repository at this point in the history
  • Loading branch information
phlppchrtn committed May 31, 2024
1 parent feca724 commit 2e8c00f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 95 deletions.
69 changes: 23 additions & 46 deletions vertigo-core/src/main/java/io/vertigo/core/util/ClassUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static <J> J newInstance(final Constructor<J> constructor, final Object[]
Assertion.check()
.isNotNull(constructor)
.isNotNull(args);
//-----
//---
try {
return constructor.newInstance(args);
} catch (final InvocationTargetException e) {
Expand All @@ -111,12 +111,12 @@ public static <J> J newInstance(final Constructor<J> 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 <J> Constructor<J> findConstructor(final Class<J> clazz) {
return findConstructor(clazz, EMPTY_CLAZZ_ARRAY);
}
Expand All @@ -132,7 +132,7 @@ public static <J> Constructor<J> findConstructor(final Class<J> clazz, final Cla
Assertion.check()
.isNotNull(clazz)
.isNotNull(parameterTypes);
//-----
//---
try {
return clazz.getConstructor(parameterTypes);
} catch (final NoSuchMethodException e) {
Expand All @@ -153,7 +153,7 @@ public static <J> Constructor<J> findConstructor(final Class<J> clazz, final Cla
public static Class<?> classForName(final String javaClassName) {
Assertion.check()
.isNotBlank(javaClassName);
//-----
//---
try {
return Class.forName(javaClassName);
} catch (final ClassNotFoundException e) {
Expand All @@ -173,7 +173,7 @@ public static <J> Class<? extends J> classForName(final String javaClassName, fi
Assertion.check()
.isNotNull(javaClassName)
.isNotNull(type);
//-----
//---
try {
return Class.forName(javaClassName).asSubclass(type);
} catch (final ClassNotFoundException e) {
Expand All @@ -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) {
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -277,7 +277,7 @@ public static Collection<Field> getAllFields(final Class<?> clazz, final Class<?
Assertion.check()
.isNotNull(clazz)
.isNotNull(annotation);
//-----
//---
return ClassUtil.getAllFields(clazz)
.stream()
.filter(field -> field.isAnnotationPresent(annotation))
Expand All @@ -294,7 +294,7 @@ public static Collection<Method> getAllMethods(final Class<?> clazz, final Class
Assertion.check()
.isNotNull(clazz)
.isNotNull(annotation);
//-----
//---
return ClassUtil.getAllMethods(clazz)
.stream()
.filter(method -> method.isAnnotationPresent(annotation))
Expand All @@ -309,7 +309,7 @@ public static Collection<Method> getAllMethods(final Class<?> clazz, final Class
public static Collection<Field> getAllFields(final Class<?> clazz) {
Assertion.check()
.isNotNull(clazz);
//-----
//---
final List<Field> fields = new ArrayList<>();
final Field[] declaredFields = clazz.getDeclaredFields();
fields.addAll(Arrays.asList(declaredFields));
Expand All @@ -328,7 +328,7 @@ public static Collection<Field> getAllFields(final Class<?> clazz) {
public static Collection<Method> getAllMethods(final Class<?> clazz) {
Assertion.check()
.isNotNull(clazz);
//-----
//---
final List<Method> methods = new ArrayList<>();
final Method[] declaredMethods = clazz.getDeclaredMethods();
methods.addAll(Arrays.asList(declaredMethods));
Expand All @@ -347,7 +347,7 @@ public static Collection<Method> getAllMethods(final Class<?> clazz) {
public static Set<Class<?>> getAllInterfaces(final Class<?> clazz) {
Assertion.check()
.isNotNull(clazz);
//-----
//---
Class<?> root = clazz;
final Set<Class<?>> allInterfaces = new HashSet<>();
while (root != null) {
Expand Down Expand Up @@ -375,7 +375,7 @@ public static Set<Class<?>> 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));
Expand All @@ -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()));
Expand All @@ -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()));
}
Expand All @@ -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<RuntimeException> exceptionSupplier) {
Assertion.check()
Expand All @@ -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);
}
}
49 changes: 0 additions & 49 deletions vertigo-core/src/test/java/io/vertigo/core/util/ClassUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,6 @@ public List<String> 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, () -> {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 2e8c00f

Please sign in to comment.