1 /*******************************************************************************
2 * Copyright (c) 2010 Association for Decentralized Information Management in
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.databoard.util;
14 import java.lang.reflect.Field;
15 import java.lang.reflect.Method;
16 import java.util.ArrayList;
17 import java.util.Collection;
18 import java.util.HashSet;
19 import java.util.LinkedList;
25 * @author Toni Kalajainen (toni.kalajainen@vtt.fi)
27 public class ReflectionUtils {
30 * Returns all methods public, protected and private
35 public static Method[] getAllMethods(Class<?> clazz)
37 Set<Method> result = new HashSet<Method>();
38 _getAllMethods(clazz, result);
39 return result.toArray(new Method[result.size()]);
42 public static Field[] getAllFields(Class<?> clazz)
44 LinkedList<Class<?>> classes = new LinkedList<Class<?>>();
46 classes.addFirst(clazz);
47 clazz = clazz.getSuperclass();
50 ArrayList<Field> result = new ArrayList<Field>();
51 for (Class<?> _class : classes) {
52 _getAllFields(_class, result);
55 return result.toArray(new Field[result.size()]);
58 private static void _getAllFields(Class<?> clazz, Collection<Field> result)
60 for (Field m : clazz.getDeclaredFields())
64 private static void _getAllMethods(Class<?> clazz, Collection<Method> result)
66 for (Method m : clazz.getDeclaredMethods())