List of usage examples for java.lang Class getSuperclass
@HotSpotIntrinsicCandidate public native Class<? super T> getSuperclass();
From source file:org.fastmongo.odm.util.ReflectionUtils.java
/** * Attempt to find a {@link Field field} on the supplied {@link Class} with the * supplied {@code name} and/or {@link Class type}. Searches all superclasses * up to {@link Object}.// w ww. j ava 2 s. c om * * @param clazz the class to introspect * @param name the name of the field (may be {@code null} if type is specified) * @param type the type of the field (may be {@code null} if name is specified) * @return the corresponding Field object, or {@code null} if not found */ public static Field findField(Class<?> clazz, String name, Class<?> type) { Class<?> searchType = clazz; while (!Object.class.equals(searchType) && searchType != null) { Field[] fields = searchType.getDeclaredFields(); for (Field field : fields) { if ((name == null || name.equals(field.getName())) && (type == null || type.equals(field.getType()))) { return field; } } searchType = searchType.getSuperclass(); } return null; }
From source file:com.github.gekoh.yagen.util.MappingUtils.java
private static void fillTreeEntityMap(Map<Class, TreeEntity> treeEntities, Set<Attribute> attributes, Class entityClass) {// w w w .j a va2s . c om for (Attribute attribute : attributes) { if (attribute instanceof SingularAttribute && ((SingularAttribute) attribute).getType() instanceof EmbeddableType) { fillTreeEntityMap(treeEntities, ((EmbeddableType) ((SingularAttribute) attribute).getType()).getAttributes(), entityClass); } else if (!attribute.isCollection() && attribute.getPersistentAttributeType() != Attribute.PersistentAttributeType.BASIC && attribute.getDeclaringType() instanceof EntityType) { Class targetEntity = attribute.getJavaType(); addMasterEntity(treeEntities, entityClass, targetEntity); } else if (attribute.isCollection() && attribute.getPersistentAttributeType() != Attribute.PersistentAttributeType.MANY_TO_MANY && attribute instanceof PluralAttribute) { addMasterEntity(treeEntities, ((PluralAttribute) attribute).getElementType().getJavaType(), entityClass); } } if (!entityClass.isAnnotationPresent(Table.class)) { Class lastEntity = entityClass; Class parent = lastEntity; do { parent = parent.getSuperclass(); if (parent.isAnnotationPresent(Entity.class)) { addMasterEntity(treeEntities, parent, lastEntity); lastEntity = parent; } if (parent.isAnnotationPresent(Table.class)) { break; } } while (parent.getSuperclass() != null); } }
From source file:com.dungnv.vfw5.base.utils.StringUtils.java
public static void escapeHTMLString(Object escapeObject) { String oldData = ""; String newData = ""; try {/*from w ww. j av a2s.c o m*/ if (escapeObject != null) { Class escapeClass = escapeObject.getClass(); Field fields[] = escapeClass.getDeclaredFields(); Field superFields[] = escapeClass.getSuperclass().getDeclaredFields(); Field allField[] = new Field[fields.length + superFields.length]; System.arraycopy(fields, 0, allField, 0, fields.length); System.arraycopy(superFields, 0, allField, fields.length, superFields.length); for (Field f : allField) { f.setAccessible(true); if (f.getType().equals(java.lang.String.class) && !Modifier.isFinal(f.getModifiers())) { if (f.get(escapeObject) != null) { oldData = f.get(escapeObject).toString(); newData = StringEscapeUtils.escapeSql(oldData); f.set(escapeObject, newData); } } else if (f.getType().isArray()) { if (f.getType().getComponentType().equals(java.lang.String.class)) { String[] tmpArr = (String[]) f.get(escapeObject); if (tmpArr != null) { for (int i = 0; i < tmpArr.length; i++) { tmpArr[i] = StringEscapeUtils.escapeSql(tmpArr[i]); } f.set(escapeObject, tmpArr); } } } else if (f.get(escapeObject) instanceof List) { List<Object> tmpList = (List<Object>) f.get(escapeObject); for (int i = 0; i < tmpList.size(); i++) { if (tmpList.get(i) instanceof java.lang.String) { tmpList.set(i, StringEscapeUtils.escapeSql(tmpList.get(i).toString())); } } f.set(escapeObject, tmpList); } } } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.github.rinde.rinsim.scenario.measure.Metrics.java
/** * Computes the number of occurrences of each event type in the specified * {@link Scenario}./*from w ww .jav a2 s .c o m*/ * @param s The scenario to check. * @return A {@link ImmutableMultiset} of event types. */ public static ImmutableMultiset<Class<?>> getEventTypeCounts(Scenario s) { final Multiset<Class<?>> set = LinkedHashMultiset.create(); for (final TimedEvent te : s.getEvents()) { set.add(te.getClass()); } final List<Class<?>> toMove = new ArrayList<>(); for (final Class<?> c : set.elementSet()) { if (!Modifier.isPublic(c.getModifiers()) && TimedEvent.class.isAssignableFrom(c.getSuperclass()) && !set.contains(c.getSuperclass())) { toMove.add(c); } } for (final Class<?> c : toMove) { set.add(c.getSuperclass(), set.count(c)); set.remove(c, set.count(c)); } return ImmutableMultiset.copyOf(set); }
From source file:com.opensymphony.xwork2.util.AnnotationUtils.java
/** * Adds all fields with the specified Annotation of class clazz and its superclasses to allFields * * @param annotationClass the {@link Annotation}s to find * @param clazz The {@link Class} to inspect * @param allFields list of all fields//w w w. j ava2 s. co m */ public static void addAllFields(Class<? extends Annotation> annotationClass, Class clazz, List<Field> allFields) { if (clazz == null) { return; } Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { Annotation ann = field.getAnnotation(annotationClass); if (ann != null) { allFields.add(field); } } addAllFields(annotationClass, clazz.getSuperclass(), allFields); }
From source file:com.springframework.beans.BeanUtils.java
/** * Find a method with the given method name and the given parameter types, * declared on the given class or one of its superclasses. Will return a public, * protected, package access, or private method. * <p>Checks {@code Class.getDeclaredMethod}, cascading upwards to all superclasses. * @param clazz the class to check/* w w w.j ava2 s .co m*/ * @param methodName the name of the method to find * @param paramTypes the parameter types of the method to find * @return the Method object, or {@code null} if not found * @see Class#getDeclaredMethod */ public static Method findDeclaredMethod(Class<?> clazz, String methodName, Class<?>... paramTypes) { try { return clazz.getDeclaredMethod(methodName, paramTypes); } catch (NoSuchMethodException ex) { if (clazz.getSuperclass() != null) { return findDeclaredMethod(clazz.getSuperclass(), methodName, paramTypes); } return null; } }
From source file:com.smart.utils.ReflectionUtils.java
/** * ?Class(),ListClass/*from w w w. j av a2s . com*/ * * @param bean * @return */ public static List<Class> getAllClassesOfClazz(Class clz) { List classFamilyTree = new LinkedList(); classFamilyTree.add(clz); Class tempSuperClass = clz; while ((tempSuperClass = tempSuperClass.getSuperclass()) != null) { classFamilyTree.add(tempSuperClass); } return classFamilyTree; }
From source file:com.bosscs.spark.commons.utils.Utils.java
/** * Get all fields rec./*from ww w .j av a 2s . c o m*/ * * @param clazz the clazz * @param fields the fields * @return the field [ ] */ private static Field[] getAllFieldsRec(Class clazz, List<Field> fields) { Class superClazz = clazz.getSuperclass(); if (superClazz != null) { getAllFieldsRec(superClazz, fields); } fields.addAll(Arrays.asList(clazz.getDeclaredFields())); return fields.toArray(new Field[fields.size()]); }
From source file:com.dragome.callbackevictor.serverside.utils.ReflectionUtils.java
public static Map<String, Object> discoverFields(final Class<?> pClazz, final Matcher pMatcher, final Indexer pIndexer) { log.debug("discovering fields on " + pClazz.getName()); final Map<String, Object> result = new HashMap<String, Object>(); Class<?> current = pClazz; do {// w ww. j av a 2 s . c o m final Field[] fields = current.getDeclaredFields(); for (int i = 0; i < fields.length; i++) { final String fname = fields[i].getName(); if (pMatcher.matches(fname)) { pIndexer.put(result, fname, fields[i]); log.debug("discovered field " + fname + " -> " + fields[i]); } } current = current.getSuperclass(); } while (current != null); return result; }
From source file:com.rockagen.commons.util.ClassUtil.java
/** * obtain fields list of specified class If recursively is true, obtain * fields from all class hierarchy/*from ww w .j a v a2 s .c o m*/ * * @param clazz class * where fields are searching * @param recursively * param * @return array of fields */ public static Field[] getDeclaredFields(Class<?> clazz, boolean recursively) { List<Field> fields = new LinkedList<Field>(); Field[] declaredFields = clazz.getDeclaredFields(); Collections.addAll(fields, declaredFields); Class<?> superClass = clazz.getSuperclass(); if (superClass != null && recursively) { Field[] declaredFieldsOfSuper = getDeclaredFields(superClass, true); if (declaredFieldsOfSuper.length > 0) Collections.addAll(fields, declaredFieldsOfSuper); } return fields.toArray(new Field[fields.size()]); }