List of usage examples for java.lang Class getSuperclass
@HotSpotIntrinsicCandidate public native Class<? super T> getSuperclass();
From source file:DebugUtilities.java
public static void printClassHierarchy(Class aClass, PrintWriter writer, String prefix) { String subPrefix = "-->"; for (int i = 0;; ++i) { writer.println(prefix + " " + subPrefix + " " + aClass.getName()); aClass = aClass.getSuperclass(); if (aClass == Object.class) break; subPrefix = "--" + subPrefix; }/*from ww w . j ava 2 s . c o m*/ }
From source file:com.sonatype.security.ldap.api.DeepEqualsBuilder.java
private static void reflectionAppend(Object lhs, Object rhs, Class clazz, EqualsBuilder builder, boolean useTransients, String[] excludeFields) { while (clazz.getSuperclass() != null) { Field[] fields = clazz.getDeclaredFields(); List excludedFieldList = excludeFields != null ? Arrays.asList(excludeFields) : Collections.EMPTY_LIST; AccessibleObject.setAccessible(fields, true); for (int i = 0; i < fields.length && builder.isEquals(); i++) { Field f = fields[i];/* w ww . j av a 2 s. c o m*/ if (!excludedFieldList.contains(f.getName()) && (f.getName().indexOf('$') == -1) && (useTransients || !Modifier.isTransient(f.getModifiers())) && (!Modifier.isStatic(f.getModifiers()))) { try { Object lhsChild = f.get(lhs); Object rhsChild = f.get(rhs); Class testClass = getTestClass(lhsChild, rhsChild); boolean hasEqualsMethod = classHasEqualsMethod(testClass); if (testClass != null && !hasEqualsMethod) { reflectionAppend(lhsChild, rhsChild, testClass, builder, useTransients, excludeFields); } else { builder.append(lhsChild, rhsChild); } } catch (IllegalAccessException e) { // this can't happen. Would get a Security exception instead // throw a runtime exception in case the impossible happens. throw new InternalError("Unexpected IllegalAccessException"); } } } // now for the parent clazz = clazz.getSuperclass(); reflectionAppend(lhs, rhs, clazz, builder, useTransients, excludeFields); } }
From source file:Main.java
/** * @param clz class name/*from www .j a va 2s.c o m*/ * @param fieldName field name * @return true if the field is in the class, else false */ public static boolean existsField(Class clz, String fieldName) { if (null != clz) { try { return clz.getDeclaredField(fieldName) != null; } catch (Exception e) { } if (clz != Object.class) { return existsField(clz.getSuperclass(), fieldName); } } return false; }
From source file:com.mmj.app.common.file.ExcelUtils.java
public static Field[] getAllFields(List<Field> fields, Class<?> type) { for (Field field : type.getDeclaredFields()) { fields.add(field);//w w w.ja v a2s. co m } if (type.getSuperclass() != null) { fields.addAll(Arrays.asList(getAllFields(fields, type.getSuperclass()))); } return fields.toArray(new Field[fields.size()]); }
From source file:Main.java
/** * Returns all fields declared in the class passed as argument or in its super classes. *///from w w w . j a va 2s . c o m public static List<Field> getAllDeclaredField(Class<?> clazz, boolean includeSuperClass) { final List<Field> result = new LinkedList<Field>(); for (final Field field : clazz.getDeclaredFields()) { result.add(field); } final Class<?> superClass = clazz.getSuperclass(); if (superClass != null && includeSuperClass) { result.addAll(getAllDeclaredField(superClass, true)); } return result; }
From source file:Main.java
public static List<Field> getAllFieldsOfType(List<Field> fields, Class<?> type, Class<?> fieldType) { for (Field field : type.getDeclaredFields()) { if (fieldType == null || fieldType.isAssignableFrom(field.getType())) { fields.add(field);//from w w w . j a va 2 s . c om } } if (type.getSuperclass() != null) { fields = getAllFieldsOfType(fields, type.getSuperclass(), fieldType); } return fields; }
From source file:Main.java
static private String getElementName(Class<?> clazz) { while (clazz != null) { XmlRootElement rootElement = clazz.getAnnotation(XmlRootElement.class); if (rootElement != null) { return rootElement.name(); }/*from w w w .j a v a2 s . c om*/ clazz = clazz.getSuperclass(); } throw new RuntimeException(); }
From source file:io.pivotal.spring.xd.jdbcgpfdist.TestUtils.java
public static void setField(String name, Object target, Object value) throws Exception { Field field = null;/* ww w . j a v a 2 s . c om*/ Class<?> clazz = target.getClass(); do { try { field = clazz.getDeclaredField(name); } catch (Exception ex) { } clazz = clazz.getSuperclass(); } while (field == null && !clazz.equals(Object.class)); if (field == null) throw new IllegalArgumentException( "Cannot find field '" + name + "' in the class hierarchy of " + target.getClass()); field.setAccessible(true); field.set(target, value); }
From source file:Main.java
public static ParameterizedType resolveParameterizedType(Type t, Class<?> baseClass) { Class<?> raw = getRawType(t); if (t instanceof ParameterizedType && baseClass.isAssignableFrom(raw)) { return (ParameterizedType) t; }/*from w ww. ja v a 2 s . c o m*/ ParameterizedType pt = null; if (raw.getSuperclass() != null && raw.getSuperclass() != Object.class) { pt = resolveParameterizedType(raw.getGenericSuperclass(), baseClass); if (pt != null) return pt; } if (!raw.isInterface()) { for (Type ifs : raw.getGenericInterfaces()) { pt = resolveParameterizedType(ifs, baseClass); if (pt != null) return pt; } } return null; }
From source file:io.pivotal.spring.xd.jdbcgpfdist.TestUtils.java
@SuppressWarnings("unchecked") public static <T> T readField(String name, Object target) throws Exception { Field field = null;/*w w w. j av a 2 s . co m*/ Class<?> clazz = target.getClass(); do { try { field = clazz.getDeclaredField(name); } catch (Exception ex) { } clazz = clazz.getSuperclass(); } while (field == null && !clazz.equals(Object.class)); if (field == null) throw new IllegalArgumentException( "Cannot find field '" + name + "' in the class hierarchy of " + target.getClass()); field.setAccessible(true); return (T) field.get(target); }