Example usage for java.lang.reflect Member getName

List of usage examples for java.lang.reflect Member getName

Introduction

In this page you can find the example usage for java.lang.reflect Member getName.

Prototype

public String getName();

Source Link

Document

Returns the simple name of the underlying member or constructor represented by this Member.

Usage

From source file:Main.java

public static String methodToString(Member member) {
    StringBuffer sb = new StringBuffer(member.getName());
    if (member instanceof Method) {
        Class[] params = ((Method) member).getParameterTypes();
        sb.append("(");
        for (int i = 0; i < params.length; i++) {
            String s = params[i].getName();
            sb.append(s);/*from  ww  w .ja  v a 2 s  .c  o m*/
            if (i < params.length - 1) {
                sb.append(", ");
            }
        }
        sb.append(")");
    }
    return sb.toString();
}

From source file:ReflectionHelper.java

/**
 * Process bean properties getter by applying the JavaBean naming conventions.
 *
 * @param member the member for which to get the property name.
 *
 * @return The bean method name with the "is" or "get" prefix stripped off, <code>null</code>
 *         the method name id not according to the JavaBeans standard.
 *///from  www.  java  2  s . co  m
public static String getPropertyName(Member member) {
    String name = null;

    if (member instanceof Field) {
        name = member.getName();
    }

    if (member instanceof Method) {
        String methodName = member.getName();
        if (methodName.startsWith("is")) {
            name = Introspector.decapitalize(methodName.substring(2));
        } else if (methodName.startsWith("get")) {
            name = Introspector.decapitalize(methodName.substring(3));
        }
    }
    return name;
}

From source file:Main.java

public static String methodToString(final Member member) {
    if (member == null) {
        return "null";
    }//  www . ja v  a 2  s . c  o m

    StringBuilder sb = new StringBuilder(member.getName());

    if (member instanceof Method) {
        Class<?>[] params = ((Method) member).getParameterTypes();
        sb.append("(");
        for (int i = 0; i < params.length; i++) {
            String s = params[i].getName();
            sb.append(s);
            if (i < params.length - 1) {
                sb.append(", ");
            }
        }
        sb.append(")");
    }
    return sb.toString();
}

From source file:com.opensymphony.xwork2.util.ProxyUtil.java

/**
 * Check whether the given class has a given member.
 * @param clazz the class to check/*  w  w w  .j  av a 2  s  .  co  m*/
 * @param member the member to check
 */
private static boolean hasMember(Class<?> clazz, Member member) {
    if (member instanceof Method) {
        return null != MethodUtils.getMatchingMethod(clazz, member.getName(),
                ((Method) member).getParameterTypes());
    }
    if (member instanceof Field) {
        return null != FieldUtils.getField(clazz, member.getName(), true);
    }
    if (member instanceof Constructor) {
        return null != ConstructorUtils.getMatchingAccessibleConstructor(clazz,
                ((Constructor) member).getParameterTypes());
    }

    return false;
}

From source file:com.fer.hr.olap.util.ObjectUtil.java

public static SaikuMember convert(Member m) {
    return new SaikuMember(m.getName(), m.getUniqueName(), m.getCaption(), m.getDescription(),
            m.getDimension().getUniqueName(), m.getHierarchy().getUniqueName(), m.getLevel().getUniqueName(),
            m.isCalculated());//from  www.j av a 2s .c o  m
}

From source file:ShowClass.java

public static void printMethodOrConstructor(Member member) {
    Class returntype = null, parameters[], exceptions[];
    if (member instanceof Method) {
        Method m = (Method) member;
        returntype = m.getReturnType();/*  w  w w.j  a  v a 2 s  . c o m*/
        parameters = m.getParameterTypes();
        exceptions = m.getExceptionTypes();
        System.out.print(
                "  " + modifiers(member.getModifiers()) + typeName(returntype) + " " + member.getName() + "(");
    } else {
        Constructor c = (Constructor) member;
        parameters = c.getParameterTypes();
        exceptions = c.getExceptionTypes();
        System.out.print("  " + modifiers(member.getModifiers()) + typeName(c.getDeclaringClass()) + "(");
    }

    for (int i = 0; i < parameters.length; i++) {
        if (i > 0)
            System.out.print(", ");
        System.out.print(typeName(parameters[i]));
    }
    System.out.print(")");
    if (exceptions.length > 0)
        System.out.print(" throws ");
    for (int i = 0; i < exceptions.length; i++) {
        if (i > 0)
            System.out.print(", ");
        System.out.print(typeName(exceptions[i]));
    }
    System.out.println(";");
}

From source file:Main.java

public static void print_method_or_constructor(Member member) {
    Class returntype = null, parameters[], exceptions[];
    if (member instanceof Method) {
        Method m = (Method) member;
        returntype = m.getReturnType();//from  w  w  w.j  a v a2s  .  c  om
        parameters = m.getParameterTypes();
        exceptions = m.getExceptionTypes();
        System.out.print(
                "  " + modifiers(member.getModifiers()) + typename(returntype) + " " + member.getName() + "(");
    } else {
        Constructor c = (Constructor) member;
        parameters = c.getParameterTypes();
        exceptions = c.getExceptionTypes();
        System.out.print("  " + modifiers(member.getModifiers()) + typename(c.getDeclaringClass()) + "(");
    }
    for (int i = 0; i < parameters.length; i++) {
        if (i > 0)
            System.out.print(", ");
        System.out.print(typename(parameters[i]));
    }
    System.out.print(")");
    if (exceptions.length > 0)
        System.out.print(" throws ");
    for (int i = 0; i < exceptions.length; i++) {
        if (i > 0)
            System.out.print(", ");
        System.out.print(typename(exceptions[i]));
    }
    System.out.println(";");
}

From source file:ShowClass.java

/**
 * Print the modifiers, return type, name, parameter types and exception type
 * of a method or constructor. Note the use of the Member interface to allow
 * this method to work with both Method and Constructor objects
 *//*  w  ww .  j av a 2 s.  c o m*/
public static void print_method_or_constructor(Member member) {
    Class returntype = null, parameters[], exceptions[];
    if (member instanceof Method) {
        Method m = (Method) member;
        returntype = m.getReturnType();
        parameters = m.getParameterTypes();
        exceptions = m.getExceptionTypes();
        System.out.print(
                "  " + modifiers(member.getModifiers()) + typename(returntype) + " " + member.getName() + "(");
    } else {
        Constructor c = (Constructor) member;
        parameters = c.getParameterTypes();
        exceptions = c.getExceptionTypes();
        System.out.print("  " + modifiers(member.getModifiers()) + typename(c.getDeclaringClass()) + "(");
    }

    for (int i = 0; i < parameters.length; i++) {
        if (i > 0)
            System.out.print(", ");
        System.out.print(typename(parameters[i]));
    }
    System.out.print(")");
    if (exceptions.length > 0)
        System.out.print(" throws ");
    for (int i = 0; i < exceptions.length; i++) {
        if (i > 0)
            System.out.print(", ");
        System.out.print(typename(exceptions[i]));
    }
    System.out.println(";");
}

From source file:ClassReader.java

protected static String getSignature(Member method, Class[] paramTypes) {
    // compute the method descriptor

    StringBuffer b = new StringBuffer((method instanceof Method) ? method.getName() : "<init>");
    b.append('(');

    for (int i = 0; i < paramTypes.length; i++) {
        addDescriptor(b, paramTypes[i]);
    }/*from   ww  w.  ja v  a2 s.c  o m*/

    b.append(')');
    if (method instanceof Method) {
        addDescriptor(b, ((Method) method).getReturnType());
    } else if (method instanceof Constructor) {
        addDescriptor(b, void.class);
    }

    return b.toString();
}

From source file:com.ryantenney.metrics.spring.Util.java

static String chooseName(String explicitName, boolean absolute, Class<?> klass, Member member,
        Object... arguments) {//from   ww  w .jav a2 s.  c o  m
    if (explicitName != null && !explicitName.isEmpty()) {
        //if a method annotation, check arguments for @MetricParam and substitute values in explicitName
        String resolvedName = "";
        if (member instanceof Method) {
            resolvedName = resolveName(explicitName, (Method) member, arguments);
        } else {
            resolvedName = explicitName;
        }
        if (absolute) {
            return resolvedName;
        }
        return name(klass.getCanonicalName(), resolvedName);
    }
    return name(name(klass.getCanonicalName(), member.getName()));
}