@Override public boolean hasSuperClass() { return (this.introspectedClass.getSuperclass() != null); }
@Override @Nullable public String getSuperClassName() { Class<?> superClass = this.introspectedClass.getSuperclass(); return (superClass != null ? superClass.getName() : null); }
public EnumSerializer(Class cl) { // hessian/32b[12], hessian/3ab[23] if (!cl.isEnum() && cl.getSuperclass().isEnum()) cl = cl.getSuperclass(); try { _name = cl.getMethod("name", new Class[0]); } catch (Exception e) { throw new RuntimeException(e); } }
public static Class<?> getEnumType(Class<?> targetType) { Class<?> enumType = targetType; while (enumType != null && !enumType.isEnum()) { enumType = enumType.getSuperclass(); } Assert.notNull(enumType, () -> "The target type " + targetType.getName() + " does not refer to an enum"); return enumType; }
public static Method findDeclaredMethod(final Class type, final String methodName, final Class[] parameterTypes) throws NoSuchMethodException { Class cl = type; while (cl != null) { try { return cl.getDeclaredMethod(methodName, parameterTypes); } catch (NoSuchMethodException e) { cl = cl.getSuperclass(); } } throw new NoSuchMethodException(methodName); }
/** * Return the user-defined class for the given class: usually simply the given * class, but the original class in case of a CGLIB-generated subclass. * @param clazz the class to check * @return the user-defined class */ public static Class<?> getUserClass(Class<?> clazz) { if (clazz.getName().contains(CGLIB_CLASS_SEPARATOR)) { Class<?> superclass = clazz.getSuperclass(); if (superclass != null && superclass != Object.class) { return superclass; } } return clazz; }
/** * Returns the writeReplace method */ protected Method getWriteReplace(Class cl, Class param) { for (; cl != null; cl = cl.getSuperclass()) { for (Method method : cl.getDeclaredMethods()) { if (method.getName().equals("writeReplace") && method.getParameterTypes().length == 1 && param.equals(method.getParameterTypes()[0])) return method; } } return null; }
/** * Returns the writeReplace method */ protected Method getWriteReplace(Class cl, Class param) { for (; cl != null; cl = cl.getSuperclass()) { for (Method method : cl.getDeclaredMethods()) { if (method.getName().equals("writeReplace") && method.getParameterTypes().length == 1 && param.equals(method.getParameterTypes()[0])) return method; } } return null; }
@Override @Nullable Class<?> getSuperclass(Class<?> type) { return type.getSuperclass(); } };
private static Class<?> findParameterizedTypeReferenceSubclass(Class<?> child) { Class<?> parent = child.getSuperclass(); if (Object.class == parent) { throw new IllegalStateException("Expected ParameterizedTypeReference superclass"); } else if (ParameterizedTypeReference.class == parent) { return child; } else { return findParameterizedTypeReferenceSubclass(parent); } }
private int getDepth(String exceptionMapping, Class<?> exceptionClass, int depth) { if (exceptionClass.getName().contains(exceptionMapping)) { // Found it! return depth; } // If we've gone as far as we can go and haven't found it... if (exceptionClass == Throwable.class) { return -1; } return getDepth(exceptionMapping, exceptionClass.getSuperclass(), depth + 1); }
public static List addAllInterfaces(Class type, List list) { Class superclass = type.getSuperclass(); if (superclass != null) { list.addAll(Arrays.asList(type.getInterfaces())); addAllInterfaces(superclass, list); } return list; }
private int getDepth(Class<?> exceptionClass, int depth) { if (exceptionClass.getName().contains(this.exceptionName)) { // Found it! return depth; } // If we've gone as far as we can go and haven't found it... if (exceptionClass == Throwable.class) { return -1; } return getDepth(exceptionClass.getSuperclass(), depth + 1); }
private int getDepth(Class<?> declaredException, Class<?> exceptionToMatch, int depth) { if (exceptionToMatch.equals(declaredException)) { // Found it! return depth; } // If we've gone as far as we can go and haven't found it... if (exceptionToMatch == Throwable.class) { return Integer.MAX_VALUE; } return getDepth(declaredException, exceptionToMatch.getSuperclass(), depth + 1); }
@Override @Nullable public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable { Field field = ReflectionUtils.findField(obj.getClass(), BEAN_FACTORY_FIELD); Assert.state(field != null, "Unable to find generated BeanFactory field"); field.set(obj, args[0]); // Does the actual (non-CGLIB) superclass implement BeanFactoryAware? // If so, call its setBeanFactory() method. If not, just exit. if (BeanFactoryAware.class.isAssignableFrom(ClassUtils.getUserClass(obj.getClass().getSuperclass()))) { return proxy.invokeSuper(obj, args); } return null; }
@Override public Object postProcessBeforeInitialization(Object bean, String beanName) { if (bean instanceof ImportAware) { ImportRegistry ir = this.beanFactory.getBean(IMPORT_REGISTRY_BEAN_NAME, ImportRegistry.class); AnnotationMetadata importingClass = ir.getImportingClassFor(bean.getClass().getSuperclass().getName()); if (importingClass != null) { ((ImportAware) bean).setImportMetadata(importingClass); } } return bean; } }
/** [descendant, ancestor) */ private static Set<Class<?>> getClassesBetween(Class<?> descendant, Class<?> ancestor) { Set<Class<?>> classes = newHashSet(); while (!descendant.equals(ancestor)) { classes.add(descendant); descendant = descendant.getSuperclass(); } return classes; }
public SourceClass getSuperClass() throws IOException { if (this.source instanceof Class) { return asSourceClass(((Class<?>) this.source).getSuperclass()); } return asSourceClass(((MetadataReader) this.source).getClassMetadata().getSuperClassName()); }
public void testGetGenericSuperclass_withSuperclass() { TypeToken<? super ArrayList<String>> superToken = new TypeToken<ArrayList<String>>() {}.getGenericSuperclass(); assertEquals(ArrayList.class.getSuperclass(), superToken.getRawType()); assertEquals( String.class, ((ParameterizedType) superToken.getType()).getActualTypeArguments()[0]); assertEquals(TypeToken.of(Base.class), TypeToken.of(Sub.class).getGenericSuperclass()); assertEquals(TypeToken.of(Object.class), TypeToken.of(Sub[].class).getGenericSuperclass()); }
public <T, T1 extends T> void testAssignableGenericArrayToClass() { assertTrue(TypeToken.of(Object[].class.getSuperclass()).isSupertypeOf(new TypeToken<T[]>() {})); for (Class<?> interfaceType : Object[].class.getInterfaces()) { assertTrue(TypeToken.of(interfaceType).isSupertypeOf(new TypeToken<T[]>() {})); } assertTrue(TypeToken.of(Object.class).isSupertypeOf(new TypeToken<T[]>() {})); assertFalse(TypeToken.of(String.class).isSupertypeOf(new TypeToken<T[]>() {})); }