Exemple #1
0
 private void addGenericInterfaces(Class<?> clazz) {
   Type[] genericInterfaces = clazz.getGenericInterfaces();
   for (Type genericInterface : genericInterfaces) {
     if (genericInterface instanceof ParameterizedType) {
       ParameterizedType pt = (ParameterizedType) genericInterface;
       Class<?> interf = (Class<?>) pt.getRawType();
       addGenericInterfaces(interf);
       doApplyArguments(interf, pt.getActualTypeArguments());
     }
   }
 }
Exemple #2
0
 @SuppressWarnings({"unchecked", "rawtypes"})
 public <C extends T> GenericInfo<C> build(Class<C> clazz) {
   if (userOperateFlag == true) {
     throw new IllegalStateException("has applied arguments.");
   }
   Type genericSuperclass = clazz.getGenericSuperclass();
   Class superClass;
   Type[] actualArguments;
   if (genericSuperclass == null) {
     if (addInterfaceGeneric) {
       GenericInfo genericInfo =
           new GenericInfo(
               new HashMap<TypeVariable<?>, Type>(),
               new HashMap<TypeVariable<?>, List<Listener>>(),
               clazz);
       genericInfo.addGenericInterfaces(clazz);
       return genericInfo;
     } else {
       return (GenericInfo) OBJECT_INFO; // 处理接口?
     }
   } else if (genericSuperclass instanceof Class) {
     superClass = (Class) genericSuperclass;
     actualArguments = null;
   } else {
     ParameterizedType parameterizedType = (ParameterizedType) genericSuperclass;
     superClass = (Class) parameterizedType.getRawType();
     actualArguments = parameterizedType.getActualTypeArguments();
   }
   GenericInfo superGenericInfo;
   if (superClass == representingClass) {
     superGenericInfo = this;
   } else {
     superGenericInfo = build(superClass);
   }
   GenericInfo child = superGenericInfo.applyArguments0(actualArguments);
   child.representingClass = clazz;
   if (addInterfaceGeneric) {
     child.addGenericInterfaces(clazz);
   }
   return child;
 }