From 9b1fa43792353b851ebfcfb160aac35c900454b6 Mon Sep 17 00:00:00 2001 From: rob bygrave Date: Tue, 2 Jul 2019 20:48:19 +1200 Subject: [PATCH] #1747 - Refactor tidy remove unused ParamTypeUtil --- .../server/deploy/ParamTypeUtil.java | 79 ------------------- 1 file changed, 79 deletions(-) delete mode 100644 src/main/java/io/ebeaninternal/server/deploy/ParamTypeUtil.java diff --git a/src/main/java/io/ebeaninternal/server/deploy/ParamTypeUtil.java b/src/main/java/io/ebeaninternal/server/deploy/ParamTypeUtil.java deleted file mode 100644 index c19f06a52..000000000 --- a/src/main/java/io/ebeaninternal/server/deploy/ParamTypeUtil.java +++ /dev/null @@ -1,79 +0,0 @@ -package io.ebeaninternal.server.deploy; - -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; - -/** - * Helper object to find generic parameter types for a given class. - */ -class ParamTypeUtil { - - /** - * Find and return the parameter type given a generic interface or class. - *

- * This assumes there is only one generic parameter. - *

- *

- * Returns null if no match was found. - *

- * - * @param cls the class to search for the parameter type - * @param matchType the type which has the generic parameter - */ - public static Class findParamType(Class cls, Class matchType) { - - // search for: implementing a generic interface - Type paramType = matchByInterfaces(cls, matchType); - if (paramType == null) { - // search for: extending a generic class - Type genericSuperclass = cls.getGenericSuperclass(); - if (genericSuperclass != null) { - paramType = matchParamType(genericSuperclass, matchType); - } - } - - if (paramType instanceof Class) { - // only interested in classes - return (Class) paramType; - } else { - return null; - } - } - - /** - * Check if the type is a generic one with parameters and of the correct type we are - * searching for. Return the parameter type if this matches otherwise return null. - */ - private static Type matchParamType(Type type, Class matchType) { - if (type instanceof ParameterizedType) { - ParameterizedType pt = (ParameterizedType) type; - Type rawType = pt.getRawType(); - boolean isAssignable = matchType.isAssignableFrom((Class) rawType); - if (isAssignable) { - // assume there is only one parameter type - Type[] typeArguments = pt.getActualTypeArguments(); - if (typeArguments.length != 1) { - String m = "Expecting only 1 generic paramater but got " + typeArguments.length + " for " + type; - throw new RuntimeException(m); - } - return typeArguments[0]; - } - } - return null; - } - - /** - * Search the interfaces this class implements. - */ - private static Type matchByInterfaces(Class cls, Class matchType) { - - Type[] gis = cls.getGenericInterfaces(); - for (Type gi : gis) { - Type match = matchParamType(gi, matchType); - if (match != null) { - return match; - } - } - return null; - } -}