Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
wonwoo committed Oct 16, 2018
1 parent 9b1d06b commit 17e2f80
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions mpple-core/src/main/java/ml/wonwoo/util/ClassUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ml.wonwoo.util;

import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -100,27 +101,18 @@ public static boolean isJoda() {
return isPresent("org.joda.time.DateTime");
}

public static boolean isWrapperType(Class<?> type) {
return wrapperType.containsKey(type) || wrapperType.containsValue(type);
}

public static boolean isDefaultJavaType(Class<?> type) {
return defaultJavaType.containsKey(type) || defaultJavaType.containsValue(type);
}

public static <T> T instantiateClass(Class<T> clazz, Object... args) {
public static <T> T instantiateClass(Class<T> clazz) {
try {
Constructor<T> declaredConstructor = clazz.getDeclaredConstructor();
if (!declaredConstructor.isAccessible()) {
declaredConstructor.setAccessible(true);
}
return declaredConstructor.newInstance(args);
return declaredConstructor.newInstance();
} catch (Exception e) {
throw new IllegalArgumentException(e);
}
}


public static Type getGenericType(Method method) {
return method.getGenericParameterTypes()[0];
}
Expand All @@ -135,12 +127,8 @@ public static boolean isPresent(String className) {
}


public static <T extends Annotation> T findMappingAnnotation(Method method, Class<T> annotation) {
return method.getAnnotation(annotation);
}

public static <T extends Annotation> T findMappingAnnotation(Field field, Class<T> annotation) {
return field.getAnnotation(annotation);
public static <T extends Annotation> T findMappingAnnotation(AnnotatedElement element, Class<T> annotation) {
return element.getAnnotation(annotation);
}

public static Field[] findAllFields(Class<?> clazz) {
Expand Down

0 comments on commit 17e2f80

Please sign in to comment.