Here you can find the source of getSuper(Class clazz, Set
Parameter | Description |
---|---|
clazz | to reflect upon |
result | set of classes to populate |
public static void getSuper(Class clazz, Set<Class> result)
//package com.java2s; /************************************************************************************** * Copyright (C) 2008 EsperTech, Inc. All rights reserved. * * http://esper.codehaus.org * * http://www.espertech.com * * ---------------------------------------------------------------------------------- * * The software in this package is published under the terms of the GPL license * * a copy of which has been included with this distribution in the license.txt file. * **************************************************************************************/ import java.util.*; public class Main { /**//from w ww.jav a 2 s . co m * Populates all interface and superclasses for the given class, recursivly. * @param clazz to reflect upon * @param result set of classes to populate */ public static void getSuper(Class clazz, Set<Class> result) { getSuperInterfaces(clazz, result); getSuperClasses(clazz, result); } public static Class[] getSuperInterfaces(Class clazz) { Set<Class> interfaces = new HashSet<Class>(); Class[] declaredInterfaces = clazz.getInterfaces(); for (int i = 0; i < declaredInterfaces.length; i++) { interfaces.add(declaredInterfaces[i]); getSuperInterfaces(declaredInterfaces[i], interfaces); } Set<Class> superClasses = new HashSet<Class>(); getSuperClasses(clazz, superClasses); for (Class superClass : superClasses) { declaredInterfaces = superClass.getInterfaces(); for (int i = 0; i < declaredInterfaces.length; i++) { interfaces.add(declaredInterfaces[i]); getSuperInterfaces(declaredInterfaces[i], interfaces); } } return interfaces.toArray(new Class[declaredInterfaces.length]); } public static void getSuperInterfaces(Class clazz, Set<Class> result) { Class interfaces[] = clazz.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { result.add(interfaces[i]); getSuperInterfaces(interfaces[i], result); } } private static void getSuperClasses(Class clazz, Set<Class> result) { Class superClass = clazz.getSuperclass(); if (superClass == null) { return; } result.add(superClass); getSuper(superClass, result); } }