Finds generic interface implementation based on the source class and the target interface.
Returns null if not found. Recurses the interface hierarchy.
167697
private static Type findGenericInterface(Class<?> sourceClass, Class<?> targetBaseInterface) {
        for (int i = 0; i < sourceClass.getInterfaces().length; i++) {
            Class<?> inter = sourceClass.getInterfaces()[i];
            if (inter == targetBaseInterface) {
                return sourceClass.getGenericInterfaces()[0];
            } else {
                Type deeper = findGenericInterface(inter, targetBaseInterface);
                if (deeper != null) {
                    return deeper;
                }
            }
        }
        return null;
    }
779923
private <T> Converter<T> lookupConverter(Type targetType)
    {
        // Try with complete type
        Converter<T> converter = getConverter(targetType);

        // Try with simple class
        if (converter == null && targetType instanceof ParameterizedType) {
            Class<?> targetClass = ReflectionUtils.getTypeClass(targetType);
            converter = getConverter(targetClass);
        }

        if (converter == null) {
            if (targetType instanceof Class && Enum.class.isAssignableFrom((Class<?>) targetType)) {
                // It's an Enum
                converter = (Converter<T>) this.enumConverter;
            } else {
                // Fallback on default converter

                this.logger.debug("Using the default Converter for type [{}]", targetType);

                converter = this.defaultConverter;
            }
        }

        return converter;
    }
871819
public static Type narrowestParameterizedType(Class<?> subClass, ParameterizedType parameterizedType) {
        Validate.notNull(parameterizedType, "ParameterizedType must not be null");
        if (subClass == null) {
            return parameterizedType;
        }
        final Class<?> rawType = (Class<?>) parameterizedType.getRawType();
        Validate.isAssignableFrom(rawType, subClass);

        final Map<TypeVariable<?>, Type> typeArguments = TypeUtils.getTypeArguments(subClass, rawType);

        hierarchy: for (Class<?> t : ClassUtils.hierarchy(subClass, Interfaces.INCLUDE)) {
            if (t.equals(rawType)) {
                break;
            }
            if (!rawType.isAssignableFrom(t)) {
                continue;
            }
            if (t.getTypeParameters().length > 0) {
                // try to parameterize raw runtime type:
                try {
                    final Map<TypeVariable<?>, Type> typeArgMappings =
                        TypeUtils.determineTypeArguments(t, parameterizedType);
                    return TypeUtils.parameterize(t, typeArgMappings);
                } catch (Exception e) {
                    // use basic parameterized source type
                }
            } else {
                for (TypeVariable<?> v : rawType.getTypeParameters()) {
                    final Type arg = typeArguments.get(v);
                    if (arg == null || arg instanceof TypeVariable<?>) {
                        continue hierarchy;
                    }
                }
                // if we are here, we have determined that rt explicitly binds all type params of the declared type
                // of pos:
                return t;
            }
        }
        return parameterizedType;
    }
1235935
private static SubjectAware findInternal(boolean recursive,
    Annotation... annotations)
  {
    SubjectAware subjectAware = null;

    for (Annotation annotation : annotations)
    {
      if (annotation.annotationType().isAssignableFrom(SubjectAware.class))
      {
        subjectAware = (SubjectAware) annotation;

        break;
      }
    }

    if ((subjectAware == null) && recursive)
    {
      for (Annotation annotation : annotations)
      {
        subjectAware = findInternal(false,
          annotation.annotationType().getAnnotations());
      }
    }

    return subjectAware;
  }
327498
private void findAllModifiedClasses(String name,
                                      PathImpl sourceDir,
                                      PathImpl classDir,
                                      String sourcePath,
                                      ArrayList<String> sources)
    throws IOException, ClassNotFoundException
  {
    String []list;

    try {
      list = sourceDir.list();
    } catch (IOException e) {
      return;
    }

    for (int i = 0; list != null && i < list.length; i++) {
      if (list[i].startsWith("."))
        continue;

      if (_excludedDirectories.contains(list[i]))
        continue;
      
      PathImpl subSource = sourceDir.lookup(list[i]);

      if (subSource.isDirectory()) {
        findAllModifiedClasses(name + list[i] + "/", subSource,
                               classDir.lookup(list[i]), sourcePath, sources);
      }
      else if (list[i].endsWith(_sourceExt)) {
        int tail = list[i].length() - _sourceExt.length();
        String prefix = list[i].substring(0, tail);
        PathImpl subClass = classDir.lookup(prefix + ".class");

        if (subClass.getLastModified() < subSource.getLastModified()) {
          sources.add(name + list[i]);
        }
      }
    }

    if (! _requireSource)
      return;
    
    try {
      list = classDir.list();
    } catch (IOException e) {
      return;
    }

    for (int i = 0; list != null && i < list.length; i++) {
      if (list[i].startsWith("."))
        continue;

      if (_excludedDirectories.contains(list[i]))
        continue;
      
      PathImpl subClass = classDir.lookup(list[i]);

      if (list[i].endsWith(".class")) {
        String prefix = list[i].substring(0, list[i].length() - 6);
        PathImpl subSource = sourceDir.lookup(prefix + _sourceExt);

        if (! subSource.exists()) {
          String tail = subSource.getTail();
          boolean doRemove = true;

          if (tail.indexOf('$') > 0) {
            String subTail = tail.substring(0, tail.indexOf('$')) + _sourceExt;
            PathImpl subJava = subSource.getParent().lookup(subTail);

            if (subJava.exists())
              doRemove = false;
          }

          if (doRemove) {
            log.finer(L.l("removing obsolete class '{0}'.", subClass.getPath()));

            subClass.remove();
          }
        }
      }
    }
  }
86856
private static void getAllInterfaces(Class<?> cls, Collection<Class<?>> interfacesFound) {
        while (cls != null) {
            Class<?>[] interfaces = cls.getInterfaces();

            for (int i = 0; i < interfaces.length; i++) {
                interfacesFound.add(interfaces[i]);
                getAllInterfaces(interfaces[i], interfacesFound);
            }

            cls = cls.getSuperclass();
         }
     }
385080
protected Class[] getInterfaces(TargetMetaDef targetMetaDef) {
		Class[] interfaces = targetMetaDef.getInterfaces();
		if (interfaces != null)
			return interfaces;
		try {
			interfaces = getPOJOInterfaces(targetMetaDef);
		} catch (Exception ex) {
			Debug.logError("[JdonFramework] getInterfaces error:" + ex, module);
		} catch (Throwable ex) {
			Debug.logError("[JdonFramework] getInterfaces error:" + ex, module);
		}
		if ((interfaces == null) || (interfaces.length == 0)) {
			Debug.logError("[JdonFramework] no find any interface for the service:" + targetMetaDef.getClassName(), module);
		} else {
			targetMetaDef.setInterfaces(interfaces); // cache the result
			Debug.logVerbose("[JdonFramework]found the the below interfaces for the service:" + targetMetaDef.getClassName(), module);
			for (int i = 0; i < interfaces.length; i++) {
				Debug.logVerbose(interfaces[i].getName() + ";", module);
			}
		}
		return interfaces;
	}
308687
@SuppressWarnings("unchecked")
  protected <T extends Component> T findAncestor(Class<T> clazz) {
    Stack<? extends Component> componentStack = getComponentStack();
    for (int i = componentStack.size() - 2; i >= 0; i--) {
      Component component = componentStack.get(i);
      if (clazz.equals(component.getClass())) return (T) component;
    }
    return null;
  }
200077
@Override
    public final DataSource getJtaDataSource() {
        if (ivJtaDataSource == null || ivJtaDataSource instanceof GenericDataSource) { // d455055
            ivJtaDataSource = getJPADataSource(ivJtaDataSourceJNDIName);
        }
        return ivJtaDataSource;
    }
811832
public @NotNull TypeConversion getConversionFromDbValue(@NotNull Type source, @NotNull Type target) {
        TypeConversion conversion = findConversionFromDbValue(source, target).orElse(null);
        if (conversion != null)
            return conversion;
        else
            throw new InstantiationFailureException("could not find a conversion from " + source.getTypeName() + " to " + target.getTypeName());
    }
1013811
@SuppressWarnings("unchecked")
    private <T> TypedStringConverter<T> findConverterQuiet(final Class<T> cls) {
        if (cls == null) {
            throw new IllegalArgumentException("Class must not be null");
        }
        TypedStringConverter<T> conv = (TypedStringConverter<T>) registered.get(cls);
        if (conv == CACHED_NULL) {
            return null;
        }
        if (conv == null) {
            try {
                conv = findAnyConverter(cls);
            } catch (RuntimeException ex) {
                registered.putIfAbsent(cls, CACHED_NULL);
                throw ex;
            }
            if (conv == null) {
                registered.putIfAbsent(cls, CACHED_NULL);
                return null;
            }
            registered.putIfAbsent(cls, conv);
        }
        return conv;
    }
751081
def _find_Generic_super_origin(subclass, superclass_origin):
    
    stack = [subclass]
    param_map = {}
    while len(stack) > 0:
        bs = stack.pop()
        if is_Generic(bs):
            if not bs.__origin__ is None and len(bs.__origin__.__parameters__) > 0:
                for i in range(len(bs.__args__)):
                    ors = bs.__origin__.__parameters__[i]
                    if bs.__args__[i] != ors and isinstance(bs.__args__[i], TypeVar):
                        param_map[ors] = bs.__args__[i]
            if (bs.__origin__ is superclass_origin or \
                    (bs.__origin__ is None and bs is superclass_origin)):
                prms = []
                try:
                    if len(bs.__origin__.__parameters__) > len(bs.__parameters__):
                        prms.extend(bs.__origin__.__parameters__)
                    else:
                        prms.extend(bs.__parameters__)
                except:
                    prms.extend(bs.__parameters__)
                for i in range(len(prms)):
                    while prms[i] in param_map:
                        prms[i] = param_map[prms[i]]
                return prms
            try:
                stack.extend(bs.__orig_bases__)
            except AttributeError:
                stack.extend(bs.__bases__)
    return None
926030
private Map<Class<?>, InterfaceInfo> getInterfaceInfoMap() {

        if (interfaceInfoMap == null) {
            interfaceInfoMap = new HashMap<Class<?>, InterfaceInfo>();
            for (final Class<?> c : packageClasses) {
                if (INTERESTING_CLASSES.accept( c )) {
                    if (!interfaceInfoMap.containsKey( c )) {
                        interfaceInfoMap.put( c, new InterfaceInfo( c ) );
                    }
                } else {
                    final Contract contract = c.getAnnotation( Contract.class );
                    if (contract != null) {
                        InterfaceInfo ii = interfaceInfoMap.get( contract.value() );
                        if (ii == null) {
                            ii = new InterfaceInfo( contract.value() );
                            interfaceInfoMap.put( contract.value(), ii );
                        }
                        ii.add( c );
                    }
                }
            }
        }
        return interfaceInfoMap;
    }
822842
public InterfaceMethodRefConstant getInterfaceRef(String className,
                                                    String name,
                                                    String type)
  {
    for (int i = 0; i < _entries.size(); i++) {
      ConstantPoolEntry entry = _entries.get(i);

      if (! (entry instanceof InterfaceMethodRefConstant))
        continue;

      InterfaceMethodRefConstant methodEntry;
      methodEntry = (InterfaceMethodRefConstant) entry;

      if (methodEntry.getClassName().equals(className) &&
          methodEntry.getName().equals(name) &&
          methodEntry.getType().equals(type))
        return methodEntry;
    }

    return null;
  }
190244
public static void getAllInterfaces(Class<?> classObject, ArrayList<Type> interfaces) {
        Type[] superInterfaces = classObject.getGenericInterfaces();
        interfaces.addAll((Arrays.asList(superInterfaces)));

        // for cases where the extended class is defined with a Generic.
        Type tgs = classObject.getGenericSuperclass();
        if (tgs != null) {
            if ((tgs) instanceof ParameterizedType) {
                interfaces.add(tgs);
            }
        }

        if (tc.isDebugEnabled()) {
            Tr.debug(tc, "updated interfaces to: " + interfaces);
        }

        Class<?> superClass = classObject.getSuperclass();
        if (superClass != null) {
            getAllInterfaces(superClass, interfaces);
        }
    }
860844
public static Type getGenericInterfaceType(Object instance, Class<?> iface, int position) {
    Class<?> type = instance.getClass();
    while (type != Object.class) {
      for (Type genericType : type.getGenericInterfaces()) {
        if (genericType instanceof ParameterizedType) {
          ParameterizedType parameterizedType = (ParameterizedType) genericType;
          if (parameterizedType.getRawType() == iface) {
            return parameterizedType.getActualTypeArguments()[position];
          }
        }
      }
      type = type.getSuperclass();
    }
    return null;
  }
429227
protected void findEntryPoint() {
        if (entryPoint == null) {
            StringBuilder path = new StringBuilder();
            Resource parent = resource;
            String name = null;
            while (parent != null && !ResourceUtil.CONTENT_NODE.equals(name = parent.getName())) {
                if (inheritanceType != Type.contentBased) {
                    if (path.length() > 0) {
                        path.insert(0, '/');
                    }
                    path.insert(0, name);
                }
                parent = parent.getParent();
            }
            if (inheritanceType != Type.nodeRelated && inheritanceType != Type.sameContent
                    && parent != null && ResourceUtil.CONTENT_NODE.equals(name)) {
                // the resource is a child of an element with a content subtree ('jcr:content/...')
                path.insert(0, '/');
                path.insert(0, ResourceUtil.CONTENT_NODE);
                relativePath = path.toString();
                entryPoint = parent.getParent();
            } else {
                // node inheritance or no content subtree ('jcr:content/...') detected...
                relativePath = "";
                entryPoint = resource.getParent();
                if (inheritanceType == Type.sameContent && parent != null && ResourceUtil.CONTENT_NODE.equals(name)) {
                    exitPoint = parent;
                }
            }
        }
    }