Java Reflection Method Name getMethodNameWithClassName(Method a_Method)

Here you can find the source of getMethodNameWithClassName(Method a_Method)

Description

Return method name from Method object

License

Open Source License

Parameter

Parameter Description
a_Method a parameter

Return

method name including return type and throws.

Declaration

public static String getMethodNameWithClassName(Method a_Method) 

Method Source Code


//package com.java2s;
/*//from   w w  w  .ja  va  2 s .com
NetForm Library
---------------
Copyright (C) 2001-2005 - Sampsa Sohlman, Teemu Sohlman
    
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
    
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.
    
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
*/

import java.lang.reflect.Method;

public class Main {
    /**
     * Return method name from Method object 
     * 
     * @param a_Method
     * @return method name including return type and throws.
     */
    public static String getMethodNameWithClassName(Method a_Method) {
        if (a_Method == null) {
            throw new NullPointerException("Parameter method is null");
        }

        StringBuffer l_StringBuffer = new StringBuffer();
        l_StringBuffer.append(a_Method.getReturnType().getName());
        l_StringBuffer.append(" ");
        l_StringBuffer.append(a_Method.getDeclaringClass().getName());
        l_StringBuffer.append(".");
        l_StringBuffer.append(a_Method.getName());
        l_StringBuffer.append("(");
        Class[] l_Classes = a_Method.getParameterTypes();
        for (int li_index = 0; li_index < l_Classes.length; li_index++) {
            if (li_index != 0)
                l_StringBuffer.append(",");
            l_StringBuffer.append(l_Classes[li_index].getName());
        }
        l_Classes = a_Method.getExceptionTypes();
        for (int li_index = 0; li_index < l_Classes.length; li_index++) {
            if (li_index == 0) {
                l_StringBuffer.append(" implements ");
            } else {
                l_StringBuffer.append(",");
            }
            l_StringBuffer.append(l_Classes[li_index].getName());
        }

        l_StringBuffer.append(")");
        return l_StringBuffer.toString();
    }
}

Related

  1. getMethodNameAndDescriptor(Method m)
  2. getMethodNameList(Class theClass)
  3. getMethodNameMinusGet(Method aMethod)
  4. getMethodNames(Class cls, boolean insertDefaultValues)
  5. getMethodNames(Class cls)
  6. getMethodOnlyByName(Class c, String methodName)
  7. getMethodOrNull(Class cls, String name, Class[] args)
  8. getMethodPropertyName(java.lang.reflect.Method method)
  9. getMethods(Class clazz, String name, int args)