Java Class Load getClassesTree(Class clazz)

Here you can find the source of getClassesTree(Class clazz)

Description

get Classes Tree

License

Open Source License

Declaration

public static List<Class<?>> getClassesTree(Class<?> clazz) 

Method Source Code

//package com.java2s;
/**/*from w  w  w  .  ja  va  2  s  .c  om*/
 * Aptana Studio
 * Copyright (c) 2005-2011 by Appcelerator, Inc. All Rights Reserved.
 * Licensed under the terms of the GNU Public License (GPL) v3 (with exceptions).
 * Please see the license.html included with this distribution for details.
 * Any modifications to this file must keep this entire header intact.
 */

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static List<Class<?>> getClassesTree(Class<?> clazz) {
        List<Class<?>> classes = new ArrayList<Class<?>>();
        classes.add(clazz);
        if (clazz.isInterface()) {
            processInterface(clazz, classes);
        } else {
            processClass(clazz, classes);
        }
        return classes;
    }

    private static void processInterface(Class<?> clazz, List<Class<?>> classes) {
        Class<?>[] interfaces = clazz.getInterfaces();
        for (Class<?> i : interfaces) {
            if (!classes.contains(i)) {
                classes.add(i);
                processInterface(i, classes);
            }
        }
    }

    private static void processClass(Class<?> clazz, List<Class<?>> classes) {
        Class<?>[] interfaces = clazz.getInterfaces();
        for (Class<?> i : interfaces) {
            if (!classes.contains(i)) {
                classes.add(i);
                processInterface(i, classes);
            }
        }
        Class<?> superClass = clazz.getSuperclass();
        if (superClass != null && !classes.contains(superClass)) {
            classes.add(superClass);
            processClass(superClass, classes);
        }
    }
}

Related

  1. getClasses(Class t)
  2. getClasses(Object... objects)
  3. getClasses(String input)
  4. getClassesFromPaths(String[] classpaths)
  5. getClassesOfType(T[] l, Class type)
  6. getClassForDomain(String domain)
  7. getClassFQNString(Class clazz, StringBuilder sb)
  8. getClassHierarchyFrom(Class clazz)
  9. getClassHierarchyLeaf( Collection> classes)