Package org.jbpm.ui.custom

Source Code of org.jbpm.ui.custom.ClassLoaderUtil

package org.jbpm.ui.custom;

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

import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.jbpm.ui.DesignerLogger;

public class ClassLoaderUtil {

    public static List<String> getChildsOfType(IJavaProject project, String parentClassName) {
        List<IType> result = new ArrayList<IType>();
        try {
            IType type = project.findType(parentClassName);
            if (type == null) {
                throw new RuntimeException("Type not found: " + parentClassName);
            }
            // get all subclasses of parent class
            IType[] types = type.newTypeHierarchy(project, null).getAllSubtypes(type);
            for (IType childType : types) {
                try {
                    if (!Flags.isAbstract(childType.getFlags()) && !Flags.isEnum(childType.getFlags())) {
                        result.add(childType);
                    }
                } catch (JavaModelException e) {
                    DesignerLogger.logError("Exception while testing type (bad class?) " + childType.getFullyQualifiedName(), e);
                    // Ignoring
                }
            }
        } catch (JavaModelException e) {
            throw new RuntimeException("Error while search types of the class: " + parentClassName, e);
        }
        List<String> classNames = new ArrayList<String>(result.size());
        for (IType type : result) {
            classNames.add(type.getFullyQualifiedName());
        }
        return classNames;
    }

}
TOP

Related Classes of org.jbpm.ui.custom.ClassLoaderUtil

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.