List of usage examples for java.lang Class getSuperclass
@HotSpotIntrinsicCandidate public native Class<? super T> getSuperclass();
From source file:com.nabla.wapp.server.database.StatementFormat.java
public static IStatementSetter getSetter(final Class parameterClass) { Class c = parameterClass; while (c != null) { final IStatementSetter writer = cache.get(c); if (writer != null) return writer; c = c.getSuperclass(); }/*from w w w .j av a 2s . c o m*/ if (log.isDebugEnabled()) log.debug("found no SQL statement setter for type '" + parameterClass.getSimpleName() + "'"); return defaultSetter; }
From source file:Main.java
/** * Check if the object has a class to avoid * @param object Object to check/*from w ww .java 2 s. c o m*/ * @param avoidClasses Class[] list of classes to avoid * @return boolean TRUE if the class is in the list, FALSE to continue */ private static boolean isObjectToAvoid(Object object, Class[] avoidClasses) { if (object != null && avoidClasses != null) { Class objectClass = object.getClass(); do { for (Class klass : avoidClasses) { if (objectClass.equals(klass)) { return true; } } objectClass = objectClass.getSuperclass(); } while (objectClass != null); } //not found return false; }
From source file:Main.java
/** * @param clz class name/* w ww .j a v a 2s. c om*/ * @param methodName method name * @return true if the method is in the class, else false */ public static Method getMethod(Class clz, String methodName, Class... parameterTypes) { if (null != clz) { try { return clz.getMethod(methodName, parameterTypes); } catch (Exception e) { } return (clz == Object.class ? null : getMethod(clz.getSuperclass(), methodName, parameterTypes)); } return null; }
From source file:Main.java
private static Field findFieldRecursiveImpl(Class<?> clazz, String fieldName) throws NoSuchFieldException { try {// ww w.j av a 2s.c o m return clazz.getDeclaredField(fieldName); } catch (NoSuchFieldException e) { while (true) { clazz = clazz.getSuperclass(); if (clazz == null || clazz.equals(Object.class)) break; try { return clazz.getDeclaredField(fieldName); } catch (NoSuchFieldException ignored) { } } throw e; } }
From source file:com.monarchapis.driver.spring.rest.ApiRequestHandlerInterceptor.java
/** * Looks for an annotation first on the method, then inspects the class. * // www .j ava 2s. com * @param method * The method search for the desired annotation. * @param clazz * THe class to search if the annotation is not present on the * method. * @return the annotation if found, null otherwise. */ private static <T extends Annotation> T getAnnotation(Method method, Class<T> clazz) { T annotation = method.getAnnotation(clazz); if (annotation == null) { Class<?> declaringClass = method.getDeclaringClass(); annotation = declaringClass.getAnnotation(clazz); while (annotation == null && declaringClass.getSuperclass() != null) { declaringClass = declaringClass.getSuperclass(); annotation = declaringClass.getAnnotation(clazz); } } return annotation; }
From source file:Main.java
public static boolean isSuperclass(final Class<? extends Object> superclass, final Class<? extends Object> clazz) { if (superclass.equals(clazz)) { return true; }/*w w w. ja v a 2s .com*/ // all classes are superlcass of Object if (clazz.equals(Object.class)) { return false; } return isSuperclass(superclass, clazz.getSuperclass()); }
From source file:Main.java
/** * Returns the first field of the given type in a class. * Might be useful for Proguard'ed classes to identify fields with unique types. * If no matching field was not found, a {@link NoSuchFieldError} will be thrown. *//*from www. j av a 2 s.c o m*/ public static Field findFirstFieldByExactType(Class<?> clazz, Class<?> type) { Class<?> clz = clazz; do { for (Field field : clz.getDeclaredFields()) { if (field.getType() == type) { field.setAccessible(true); return field; } } } while ((clz = clz.getSuperclass()) != null); throw new NoSuchFieldError("Field of type " + type.getName() + " in class " + clazz.getName()); }
From source file:Main.java
/** * @param clz class name//from ww w . j a v a2 s. c o m * @param fieldName field name * @return the Field object if the class is exists, else null */ public static Field getField(Class clz, String fieldName) { if (null != clz) { try { return clz.getField(fieldName); } catch (Exception e) { } return (clz == Object.class ? null : getField(clz.getSuperclass(), fieldName)); } return null; }
From source file:com.opensymphony.xwork2.util.ProxyUtil.java
/** * Determine the ultimate target class of the given spring bean instance, traversing * not only a top-level spring proxy but any number of nested spring proxies as well — * as long as possible without side effects, that is, just for singleton targets. * @param candidate the instance to check (might be a spring AOP proxy) * @return the ultimate target class (or the plain class of the given * object as fallback; never {@code null}) *//*ww w.j a va 2 s.c o m*/ private static Class<?> springUltimateTargetClass(Object candidate) { Object current = candidate; Class<?> result = null; while (null != current && implementsInterface(current.getClass(), SPRING_TARGETCLASSAWARE_CLASS_NAME)) { try { result = (Class<?>) MethodUtils.invokeMethod(current, "getTargetClass"); } catch (Throwable ignored) { } current = getSingletonTarget(current); } if (result == null) { Class<?> clazz = candidate.getClass(); result = (isCglibProxyClass(clazz) ? clazz.getSuperclass() : candidate.getClass()); } return result; }
From source file:Main.java
/** * Retrieves the a field with the specified name from the given class. Other than Class's getField(String) method, * this method will also return protected and private fields. * * @param clazz Class from which the field should be obtained. * @param fieldName Name of the field.// w w w.j av a 2 s .co m * @return field with the specified name. */ public static Field getField(final Class clazz, final String fieldName) { try { return clazz.getField(fieldName); } catch (NoSuchFieldException e) { /* Means there's no public field, let's keep looking */ } Class runner = clazz; while (runner != null) { try { return runner.getDeclaredField(fieldName); } catch (NoSuchFieldException e) { /* No luck here either */ } runner = runner.getSuperclass(); } return null; }