Example usage for java.lang.reflect Method getParameterTypes

List of usage examples for java.lang.reflect Method getParameterTypes

Introduction

In this page you can find the example usage for java.lang.reflect Method getParameterTypes.

Prototype

@Override
public Class<?>[] getParameterTypes() 

Source Link

Usage

From source file:com.arpnetworking.jackson.BuilderDeserializer.java

static boolean isSetterMethod(final Class<?> builderClass, final Method method) {
    return method.getName().startsWith(SETTER_PREFIX) && builderClass.equals(method.getReturnType())
            && !method.isVarArgs() && method.getParameterTypes().length == 1;
}

From source file:com.curl.orb.servlet.InstanceManagementUtil.java

public static boolean isGetter(Method method) {
    return (method.getName().startsWith("get") && Character.isUpperCase(method.getName().charAt(3))
            && method.getParameterTypes().length == 0 && method.getReturnType() != void.class);
}

From source file:com.curl.orb.servlet.InstanceManagementUtil.java

public static boolean isSetter(Method method) {
    return (method.getName().startsWith("set") && Character.isUpperCase(method.getName().charAt(3))
            && method.getParameterTypes().length == 1 && method.getReturnType() == void.class);
}

From source file:hydrograph.ui.expression.editor.buttons.ValidateExpressionToolButton.java

/**
 * Complies the given expression using engine's jar from ELT-Project's build path. 
 * //  w w w  . j av a 2s .  c o  m
 * @param expressionStyledText
 * @param fieldMap
 * @param componentName
 * @return DiagnosticCollector 
 *          complete diagnosis of given expression
 * @throws JavaModelException
 * @throws InvocationTargetException
 * @throws ClassNotFoundException
 * @throws MalformedURLException
 * @throws IllegalAccessException
 * @throws IllegalArgumentException
 */
@SuppressWarnings({ "unchecked" })
public static DiagnosticCollector<JavaFileObject> compileExpresion(String expressionStyledText,
        Map<String, Class<?>> fieldMap, String componentName)
        throws JavaModelException, InvocationTargetException, ClassNotFoundException, MalformedURLException,
        IllegalAccessException, IllegalArgumentException {
    LOGGER.debug("Compiling expression using Java-Compiler");
    String expressiontext = getExpressionText(expressionStyledText);
    DiagnosticCollector<JavaFileObject> diagnostics = null;
    Object[] returObj = getBuildPathForMethodInvocation();
    List<URL> urlList = (List<URL>) returObj[0];
    String transfromJarPath = (String) returObj[1];
    String propertyFilePath = (String) returObj[2];
    URLClassLoader child = URLClassLoader.newInstance(urlList.toArray(new URL[urlList.size()]));

    Class<?> class1 = Class.forName(HYDROGRAPH_ENGINE_EXPRESSION_VALIDATION_API_CLASS, true, child);
    Thread.currentThread().setContextClassLoader(child);
    Method[] methods = class1.getDeclaredMethods();
    for (Method method : methods) {
        if (method.getParameterTypes().length == 4
                && StringUtils.equals(method.getName(),
                        COMPILE_METHOD_OF_EXPRESSION_JAR_FOR_TRANSFORM_COMPONENTS)
                && !StringUtils.equalsIgnoreCase(componentName, hydrograph.ui.common.util.Constants.FILTER)) {
            method.getDeclaringClass().getClassLoader();
            diagnostics = (DiagnosticCollector<JavaFileObject>) method.invoke(null, expressiontext,
                    propertyFilePath, fieldMap, transfromJarPath);

            break;
        } else if (method.getParameterTypes().length == 4
                && StringUtils.equals(method.getName(), COMPILE_METHOD_OF_EXPRESSION_JAR_FOR_FILTER_COMPONENT)
                && StringUtils.equalsIgnoreCase(componentName, hydrograph.ui.common.util.Constants.FILTER)) {
            method.getDeclaringClass().getClassLoader();
            diagnostics = (DiagnosticCollector<JavaFileObject>) method.invoke(null, expressiontext,
                    propertyFilePath, fieldMap, transfromJarPath);
            break;
        }

    }

    try {
        child.close();
    } catch (IOException ioException) {
        LOGGER.error("Error occurred while closing classloader", ioException);
    }
    return diagnostics;
}

From source file:com.onesignal.TrackGooglePurchase.java

private static Method getAsInterfaceMethod(Class clazz) {
    for (Method method : clazz.getMethods()) {
        Class<?>[] args = method.getParameterTypes();
        if (args.length == 1 && args[0] == android.os.IBinder.class)
            return method;
    }/*from   w w  w. j  av a 2s. c o  m*/

    return null;
}

From source file:com.onesignal.TrackGooglePurchase.java

private static Method getGetPurchasesMethod(Class clazz) {
    for (Method method : clazz.getMethods()) {
        Class<?>[] args = method.getParameterTypes();
        if (args.length == 4 && args[0] == int.class && args[1] == String.class && args[2] == String.class
                && args[3] == String.class)
            return method;
    }//w  ww. ja  va 2 s.  c  o  m

    return null;
}

From source file:com.onesignal.TrackGooglePurchase.java

private static Method getGetSkuDetailsMethod(Class clazz) {
    for (Method method : clazz.getMethods()) {
        Class<?>[] args = method.getParameterTypes();
        if (args.length == 4 && args[0] == int.class && args[1] == String.class && args[2] == String.class
                && args[3] == Bundle.class)
            return method;
    }/*from w  w w .j a  v a  2 s  . c om*/

    return null;
}

From source file:com.enonic.cms.business.portal.datasource.methodcall.MethodCallFactory.java

private static Method resolveMethod(Class targetClass, String methodName, int numParams, boolean useContext) {
    final String localMethodName = resolveLocalMethodName(methodName);

    for (Method method : targetClass.getMethods()) {
        if (localMethodName.equals(method.getName()) && (method.getParameterTypes().length == numParams)) {
            return method;
        }/*from ww  w  . j  a  v  a  2s  .  c  om*/
    }
    throw new VerticalRenderException("Method [" + localMethodName + "] with ["
            + (useContext ? numParams - 1 : numParams) + "] parameters does not exist");
}

From source file:IntrospectionUtil.java

public static boolean isSameSignature(Method methodA, Method methodB) {
    if (methodA == null)
        return false;
    if (methodB == null)
        return false;

    List parameterTypesA = Arrays.asList(methodA.getParameterTypes());
    List parameterTypesB = Arrays.asList(methodB.getParameterTypes());

    if (methodA.getName().equals(methodB.getName()) && parameterTypesA.containsAll(parameterTypesB))
        return true;

    return false;
}

From source file:unquietcode.tools.beanmachine.AnnotationUtils.java

/**
 * Retrieve the given annotation's attributes as a Map.
 * @param annotation the annotation to retrieve the attributes for
 * @param classValuesAsString whether to turn Class references into Strings (for compatibility with
 * {@link org.springframework.core.type.AnnotationMetadata} or to preserve them as Class references
 * @return the Map of annotation attributes, with attribute names as keys and
 * corresponding attribute values as values
 */// www . java  2 s.  c  o  m
public static Map<String, Object> getAnnotationAttributes(Annotation annotation, boolean classValuesAsString) {
    Map<String, Object> attrs = new HashMap<String, Object>();
    Method[] methods = annotation.annotationType().getDeclaredMethods();
    for (Method method : methods) {
        if (method.getParameterTypes().length == 0 && method.getReturnType() != void.class) {
            try {
                Object value = method.invoke(annotation);
                if (classValuesAsString) {
                    if (value instanceof Class) {
                        value = ((Class) value).getName();
                    } else if (value instanceof Class[]) {
                        Class[] clazzArray = (Class[]) value;
                        String[] newValue = new String[clazzArray.length];
                        for (int i = 0; i < clazzArray.length; i++) {
                            newValue[i] = clazzArray[i].getName();
                        }
                        value = newValue;
                    }
                }
                attrs.put(method.getName(), value);
            } catch (Exception ex) {
                throw new IllegalStateException("Could not obtain annotation attribute values", ex);
            }
        }
    }
    return attrs;
}