Java Reflection Method Get from Object getMethodNames(Object obj, boolean includeInheritedMethods)

Here you can find the source of getMethodNames(Object obj, boolean includeInheritedMethods)

Description

get Method Names

License

Open Source License

Declaration

public static Set<String> getMethodNames(Object obj, boolean includeInheritedMethods) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2008 The University of York.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * //from w  w w . j a va 2 s.c  o m
 * Contributors:
 *     Dimitrios Kolovos - initial API and implementation
 ******************************************************************************/

import java.lang.reflect.Method;

import java.util.HashSet;

import java.util.Set;

public class Main {
    public static Set<String> getMethodNames(Object obj, boolean includeInheritedMethods) {

        HashSet<String> methodNames = new HashSet<String>();

        if (obj == null)
            return methodNames;

        Method[] methods = null;

        if (includeInheritedMethods) {
            methods = obj.getClass().getMethods();
        } else {
            methods = obj.getClass().getDeclaredMethods();
        }

        for (int i = 0; i < methods.length; i++) {
            methodNames.add(getMethodName(methods[i]));
        }

        return methodNames;
    }

    protected static String getMethodName(Method method) {
        String methodName = method.getName();
        if (methodName.startsWith("_"))
            methodName = methodName.substring(1);
        return methodName;
    }
}

Related

  1. getMethodInHolder(String methodName, Object holder)
  2. getMethodInstace(Class c, Object inst, String name, Class[] types, boolean access)
  3. getMethodName(AccessibleObject method)
  4. getMethodNamed(String methodName, Object holder)
  5. getMethodNames(Object obj, boolean hasParent)
  6. getMethodObject(Class type, Class clazz, String method, Class[] args, Object object, Object[] objects)
  7. getMethodObject(Object object, String method, Object[] parametre)
  8. getMethodResult(final Object element, final String methodName)
  9. getMethodReturn(String className, String methodName, Class[] params, Object[] args, boolean isStatic)