Example usage for java.lang Class getSuperclass

List of usage examples for java.lang Class getSuperclass

Introduction

In this page you can find the example usage for java.lang Class getSuperclass.

Prototype

@HotSpotIntrinsicCandidate
public native Class<? super T> getSuperclass();

Source Link

Document

Returns the Class representing the direct superclass of the entity (class, interface, primitive type or void) represented by this Class .

Usage

From source file:Main.java

public static Object invokeMethod(Object paramObject, String paramString, Class<?>[] paramArrayOfClass,
        Object[] paramArrayOfObject) {
    Class localClass = paramObject.getClass();

    try {//from   w  w  w .ja  va  2  s  . c o m
        Method localException = localClass.getDeclaredMethod(paramString, paramArrayOfClass);
        localException.setAccessible(true);
        return localException.invoke(paramObject, paramArrayOfObject);
    } catch (Exception var9) {
        Method localMethod = null;

        try {
            if (localClass != null && localClass.getSuperclass() != null) {
                localMethod = localClass.getSuperclass().getDeclaredMethod(paramString, paramArrayOfClass);
                if (localMethod != null) {
                    localMethod.setAccessible(true);
                    return localMethod.invoke(paramObject, paramArrayOfObject);
                }
            }
        } catch (Exception var8) {
            ;
        }

        return null;
    }
}

From source file:OAT.ui.util.UiUtil.java

public static void setupColumns(JTable table) {
    for (int i = 0; i < table.getColumnCount(); i++) {
        DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
        TableColumn column = table.getColumnModel().getColumn(i);
        Class columnClass = table.getColumnClass(i);
        String columnName = table.getColumnName(i);
        renderer.setToolTipText(columnName);

        if (columnClass.getSuperclass().equals(Number.class)) {
            renderer.setHorizontalAlignment(DefaultTableCellRenderer.RIGHT);
        }//  w w w .ja v  a2s  .  c o m

        if (table.isEnabled()) {
            if (columnName.equals("Currency")) {
                //addComboCell(column, Product.CURRENCIES);
            } else if (columnName.equals("Holidays")) {
                //column.setCellEditor(new FileChooserCellEditor());
            }
        }

        column.setCellRenderer(renderer);
    }
}

From source file:com.feilong.core.lang.reflect.TypeUtil.java

/**
 *  superclass parameterized type.//from  w ww. j  av a 2 s .co  m
 *
 * @param klass
 *            the klass
 * @return the superclass parameterized type
 * @see java.lang.Class#getGenericSuperclass()
 */
private static ParameterizedType getGenericSuperclassParameterizedType(Class<?> klass) {
    Validate.notNull(klass, "klass can't be null/empty!");

    Class<?> useClass = klass;
    Type type = useClass.getGenericSuperclass(); //com.feilong.core.lang.reflect.res.BaseSolrRepositoryImpl<com.feilong.core.lang.reflect.res.SkuItem, java.lang.Long>

    while (!(type instanceof ParameterizedType) && Object.class != useClass) {
        useClass = useClass.getSuperclass();
        type = useClass.getGenericSuperclass();
    }

    return (ParameterizedType) type;
}

From source file:com.expressui.core.util.StringUtil.java

/**
 * Generates CSS style names from an object's class and all its parents in class hierarchy.
 *
 * @param prefix        to prepend to style name
 * @param topLevelClass style names are only generated up to this top level class in the class hierarchical. Higher
 *                      level classes are ignored
 * @param object        object to reflectively get class from
 * @return List of style names//from  w  w  w .j a  va 2 s  . c  o  m
 */
public static List<String> generateStyleNamesFromClassHierarchy(String prefix, Class topLevelClass,
        Object object) {
    List<String> styles = new ArrayList<String>();
    Class currentClass = object.getClass();
    while (topLevelClass.isAssignableFrom(currentClass)) {
        String simpleName = currentClass.getSimpleName();
        String style = StringUtil.hyphenateCamelCase(simpleName);
        styles.add(prefix + "-" + style);
        currentClass = currentClass.getSuperclass();
    }

    return styles;
}

From source file:com.netflix.hystrix.contrib.javanica.utils.AopUtils.java

/**
 * Gets declared method from specified type by mame and parameters types.
 *
 * @param type           the type/*  w  w w.ja  va  2  s .  c om*/
 * @param methodName     the name of the method
 * @param parameterTypes the parameter array
 * @return a {@link Method} object or null if method doesn't exist
 */
public static Method getDeclaredMethod(Class<?> type, String methodName, Class<?>... parameterTypes) {
    Method method = null;
    try {
        method = type.getDeclaredMethod(methodName, parameterTypes);
        if (method.isBridge()) {
            method = MethodProvider.getInstance().unbride(method, type);
        }
    } catch (NoSuchMethodException e) {
        Class<?> superclass = type.getSuperclass();
        if (superclass != null) {
            method = getDeclaredMethod(superclass, methodName, parameterTypes);
        }
    } catch (ClassNotFoundException e) {
        Throwables.propagate(e);
    } catch (IOException e) {
        Throwables.propagate(e);
    }
    return method;
}

From source file:com.darkstar.beanCartography.utils.NameUtils.java

/**
 * Return public, private, protected, etc. fields declared by the passed
 * class in a field array./* w w w  . j av  a2 s  .  c  o  m*/
 *
 * @param clazz class to inspect
 * @param includeSuperClasses <code>true</code> will cause superclasses to be included in the field collection
 * @return array of Fields found
 */
public static Field[] getClassFields(Class<?> clazz, boolean includeSuperClasses) {
    Preconditions.checkNotNull(clazz, "Class cannot be null!");
    List<Field> allFields = new ArrayList<>();
    do {
        allFields.addAll(Arrays.asList(clazz.getDeclaredFields()));
    } while (includeSuperClasses && (clazz = clazz.getSuperclass()) != null);

    Field[] fields = new Field[allFields.size()];
    return allFields.toArray(fields);
}

From source file:NestUtil.java

/**
 * Get all fields of a class./*from   w  w w .j  a  v  a 2s .  c o m*/
 * 
 * @param clazz The class.
 * @return All fields of a class.
 */
public static Collection<Field> getFields(Class<?> clazz) {
    //      if (log.isDebugEnabled()) {
    //      log.debug("getFields(Class<?>) - start");
    //}

    Map<String, Field> fields = new HashMap<String, Field>();
    while (clazz != null) {
        for (Field field : clazz.getDeclaredFields()) {
            if (!fields.containsKey(field.getName())) {
                fields.put(field.getName(), field);
            }
        }

        clazz = clazz.getSuperclass();
    }

    Collection<Field> returnCollection = fields.values();
    //   if (log.isDebugEnabled()) {
    //   log.debug("getFields(Class<?>) - end");
    //   }
    return returnCollection;
}

From source file:org.codehaus.groovy.grails.plugins.springsecurity.acl.ProxyUtils.java

/**
 * Finds the constructor in the unproxied superclass if proxied.
 * @param constructor  the constructor//from  ww  w. j  a va  2  s . co m
 * @return  the constructor in the unproxied class
 */
public static Constructor<?> unproxy(final Constructor<?> constructor) {
    Class<?> clazz = constructor.getDeclaringClass();

    if (!AopUtils.isCglibProxyClass(clazz)) {
        return constructor;
    }

    Class<?> searchType = unproxy(clazz);
    while (searchType != null) {
        for (Constructor<?> c : searchType.getConstructors()) {
            if (constructor.getName().equals(c.getName()) && (constructor.getParameterTypes() == null
                    || Arrays.equals(constructor.getParameterTypes(), c.getParameterTypes()))) {
                return c;
            }
        }
        searchType = searchType.getSuperclass();
    }

    return null;
}

From source file:com.ms.commons.test.common.ReflectUtil.java

protected static final void getInterfaces(Class<?> clazz, List<Class<?>> clazzList) {
    if (clazz == Object.class) {
        return;//from w w w .  j a v a  2 s  .  co  m
    }
    for (Class<?> c : clazz.getInterfaces()) {
        clazzList.add(c);
    }
    getInterfaces(clazz.getSuperclass(), clazzList);
}

From source file:com.hurence.logisland.classloading.PluginProxy.java

/**
 * Return all interfaces that the given class implements as a Set,
 * including ones implemented by superclasses.
 * <p>If the class itself is an interface, it gets returned as sole interface.
 *
 * @param clazz       the class to analyze for interfaces
 * @param classLoader the ClassLoader that the interfaces need to be visible in
 *                    (may be {@code null} when accepting all declared interfaces)
 * @return all interfaces that the given object implements as a Set
 *//*from  w ww.ja  v  a  2s . c  om*/
public static Set<Class<?>> getAllInterfacesForClassAsSet(Class<?> clazz, ClassLoader classLoader) {
    if (clazz.isInterface() && isVisible(clazz, classLoader)) {
        return Collections.<Class<?>>singleton(clazz);
    }
    Set<Class<?>> interfaces = new LinkedHashSet<Class<?>>();
    Class<?> current = clazz;
    while (current != null) {
        Class<?>[] ifcs = current.getInterfaces();
        for (Class<?> ifc : ifcs) {
            interfaces.addAll(getAllInterfacesForClassAsSet(ifc, classLoader));
        }
        current = current.getSuperclass();
    }
    return interfaces;
}