Example usage for java.lang.reflect Parameter getName

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

Introduction

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

Prototype

public String getName() 

Source Link

Document

Returns the name of the parameter.

Usage

From source file:lite.flow.runtime.kiss.ComponentUtil.java

private static Object getConsParamvalue(Parameter consParam, Map<String, Object> resources,
        Map<String, Object> parameters) {
    String name = consParam.getName();

    if (resources.containsKey(name))
        return resources.get(name);

    if (parameters.containsKey(name))
        return parameters.get(name);

    throw new IllegalArgumentException("No resource or parameter is available by name: " + name);
}

From source file:org.mule.runtime.extension.api.util.NameUtils.java

public static String getAliasName(Parameter parameter) {
    return getAliasName(parameter.getName(), parameter.getAnnotation(Alias.class));
}

From source file:com.adaptc.mws.plugins.testing.transformations.TestMixinTransformation.java

/**
 * Creates an argument list from the given parameter types.
 *
 * @param parameterTypes The parameter types
 * @param thisAsFirstArgument Whether to include a reference to 'this' as the first argument
 *
 * @return the arguments/*from   www .jav a 2s . c  om*/
 */
public static ArgumentListExpression createArgumentListFromParameters(Parameter[] parameterTypes,
        boolean thisAsFirstArgument) {
    ArgumentListExpression arguments = new ArgumentListExpression();

    if (thisAsFirstArgument) {
        arguments.addExpression(THIS_EXPRESSION);
    }

    for (Parameter parameterType : parameterTypes) {
        arguments.addExpression(new VariableExpression(parameterType.getName()));
    }
    return arguments;
}

From source file:com.adaptc.mws.plugins.testing.transformations.TestMixinTransformation.java

/**
 * Adds a static method to the given class node that delegates to the given method
 * and resolves the object to invoke the method on from the given expression.
 *
 * @param expression The expression/*  w  ww. j a  v a 2  s  . c  o m*/
 * @param classNode The class node
 * @param delegateMethod The delegate method
 * @return The added method node or null if it couldn't be added
 */
public static MethodNode addDelegateStaticMethod(Expression expression, ClassNode classNode,
        MethodNode delegateMethod) {
    Parameter[] parameterTypes = delegateMethod.getParameters();
    String declaredMethodName = delegateMethod.getName();
    if (classNode.hasDeclaredMethod(declaredMethodName, parameterTypes)) {
        return null;
    }

    BlockStatement methodBody = new BlockStatement();
    ArgumentListExpression arguments = new ArgumentListExpression();

    for (Parameter parameterType : parameterTypes) {
        arguments.addExpression(new VariableExpression(parameterType.getName()));
    }
    MethodCallExpression methodCallExpression = new MethodCallExpression(expression, declaredMethodName,
            arguments);
    methodCallExpression.setMethodTarget(delegateMethod);

    ThrowStatement missingMethodException = createMissingMethodThrowable(classNode, delegateMethod);
    VariableExpression apiVar = addApiVariableDeclaration(expression, delegateMethod, methodBody);
    IfStatement ifStatement = createIfElseStatementForApiMethodCall(methodCallExpression, apiVar,
            missingMethodException);

    methodBody.addStatement(ifStatement);
    ClassNode returnType = nonGeneric(delegateMethod.getReturnType());
    if (METHOD_MISSING_METHOD_NAME.equals(declaredMethodName)) {
        declaredMethodName = STATIC_METHOD_MISSING_METHOD_NAME;
    }
    MethodNode methodNode = classNode.getDeclaredMethod(declaredMethodName, parameterTypes);
    if (methodNode == null) {
        methodNode = new MethodNode(declaredMethodName, Modifier.PUBLIC | Modifier.STATIC, returnType,
                copyParameters(parameterTypes), EMPTY_CLASS_ARRAY, methodBody);
        methodNode.addAnnotations(delegateMethod.getAnnotations());

        classNode.addMethod(methodNode);
    }
    return methodNode;
}

From source file:com.adaptc.mws.plugins.testing.transformations.TestMixinTransformation.java

private static Parameter[] copyParameters(Parameter[] parameterTypes) {
    Parameter[] newParameterTypes = new Parameter[parameterTypes.length];
    for (int i = 0; i < parameterTypes.length; i++) {
        Parameter parameterType = parameterTypes[i];
        Parameter newParameter = new Parameter(nonGeneric(parameterType.getType()), parameterType.getName(),
                parameterType.getInitialExpression());
        newParameter.addAnnotations(parameterType.getAnnotations());
        newParameterTypes[i] = newParameter;
    }/*from   w  w w.j a  v  a2s . co  m*/
    return newParameterTypes;
}

From source file:edu.usu.sdl.openstorefront.doc.JaxrsProcessor.java

private static void mapMethodParameters(List<APIParamModel> parameterList, Parameter parameters[]) {
    for (Parameter parameter : parameters) {
        APIParamModel paramModel = new APIParamModel();
        paramModel.setFieldName(parameter.getName());

        QueryParam queryParam = (QueryParam) parameter.getAnnotation(QueryParam.class);
        FormParam formParam = (FormParam) parameter.getAnnotation(FormParam.class);
        MatrixParam matrixParam = (MatrixParam) parameter.getAnnotation(MatrixParam.class);
        HeaderParam headerParam = (HeaderParam) parameter.getAnnotation(HeaderParam.class);
        CookieParam cookieParam = (CookieParam) parameter.getAnnotation(CookieParam.class);
        PathParam pathParam = (PathParam) parameter.getAnnotation(PathParam.class);
        BeanParam beanParam = (BeanParam) parameter.getAnnotation(BeanParam.class);

        if (queryParam != null) {
            paramModel.setParameterType(QueryParam.class.getSimpleName());
            paramModel.setParameterName(queryParam.value());
        }/*from  w w  w.java  2s. c o m*/
        if (formParam != null) {
            paramModel.setParameterType(FormParam.class.getSimpleName());
            paramModel.setParameterName(formParam.value());
        }
        if (matrixParam != null) {
            paramModel.setParameterType(MatrixParam.class.getSimpleName());
            paramModel.setParameterName(matrixParam.value());
        }
        if (pathParam != null) {
            paramModel.setParameterType(PathParam.class.getSimpleName());
            paramModel.setParameterName(pathParam.value());
        }
        if (headerParam != null) {
            paramModel.setParameterType(HeaderParam.class.getSimpleName());
            paramModel.setParameterName(headerParam.value());
        }
        if (cookieParam != null) {
            paramModel.setParameterType(CookieParam.class.getSimpleName());
            paramModel.setParameterName(cookieParam.value());
        }

        if (beanParam != null) {
            Class paramClass = parameter.getType();
            mapParameters(parameterList, ReflectionUtil.getAllFields(paramClass).toArray(new Field[0]));
        }
        if (StringUtils.isNotBlank(paramModel.getParameterType())) {
            APIDescription aPIDescription = (APIDescription) parameter.getAnnotation(APIDescription.class);
            if (aPIDescription != null) {
                paramModel.setParameterDescription(aPIDescription.value());
            }

            ParameterRestrictions restrictions = (ParameterRestrictions) parameter
                    .getAnnotation(ParameterRestrictions.class);
            if (restrictions != null) {
                paramModel.setRestrictions(restrictions.value());
            }

            RequiredParam requiredParam = (RequiredParam) parameter.getAnnotation(RequiredParam.class);
            if (requiredParam != null) {
                paramModel.setRequired(true);
            }

            DefaultValue defaultValue = (DefaultValue) parameter.getAnnotation(DefaultValue.class);
            if (defaultValue != null) {
                paramModel.setDefaultValue(defaultValue.value());
            }

            parameterList.add(paramModel);
        }
    }
}

From source file:cn.hope.platform.persistence.params.ReflectionParameterResolver.java

@Override
public boolean resolveParameter(ParameterizedDataProvider<? extends Object> dataset, Parameter parameter) {
    String strippedName = parameter.getName().substring(1);
    String[] properties = strippedName.split("\\.");
    int index = 0;
    Object base = object;/*w  w w .  ja v a  2s  . co  m*/
    while (index < properties.length && base != null) {
        base = resolveProperty(base, properties[index]);
        index++;

    }

    if (base != null) {
        parameter.setValue(base);
        return true;
    }

    return false;

}

From source file:com.teradata.tempto.internal.ReflectionInjectorHelper.java

private Object createInstanceWithFields(Parameter[] parameters) {
    DynamicType.Builder<Object> objectBuilder = new ByteBuddy().subclass(Object.class).modifiers(PUBLIC);
    for (Parameter parameter : parameters) {
        objectBuilder = objectBuilder.defineField(parameter.getName(), parameter.getType(), PUBLIC)
                .annotateField(ArrayUtils.add(parameter.getAnnotations(), INJECT_ANNOTATION));
    }//from  w ww  .  j  ava2 s.  co  m
    try {
        Class<?> createdClass = objectBuilder.make()
                .load(getSystemClassLoader(), ClassLoadingStrategy.Default.INJECTION).getLoaded();
        return createdClass.getConstructor().newInstance();
    } catch (ReflectiveOperationException e) {
        throw new RuntimeException(e);
    }
}

From source file:ijfx.ui.widgets.PluginInfoPane.java

private Map<String, String> convert(Parameter item) {

    return Maps.newHashMap(ImmutableMap.<String, String>builder().put("name", item.getName())
            .put("type", item.getType().getSimpleName()).build());

}

From source file:io.silverware.microservices.providers.cdi.internal.RestInterface.java

private static String getParamName(final Parameter methodParameter, Method method, final Class<?> clazz) {
    final ParamName paramName = methodParameter.getAnnotation(ParamName.class);
    if (paramName != null && paramName.value() != null && !paramName.value().trim().isEmpty()) {
        return paramName.value().trim();
    }//from   w  ww.j av  a  2  s .  c  o m
    final JsonProperty jsonProperty = methodParameter.getAnnotation(JsonProperty.class);
    if (jsonProperty != null && jsonProperty.value() != null && !jsonProperty.value().trim().isEmpty()) {
        return jsonProperty.value().trim();
    }

    if (!methodParameter.isNamePresent()) {
        log.warn(String.format(
                "Method parameter name is not present for method %s in class %s. Please use compilation argument (or test compilation argument) \"-parameters\""
                        + " or use annotation @%s or @%s for parameters of this method.",
                method.getName(), clazz.getCanonicalName(), ParamName.class.getCanonicalName(),
                JsonProperty.class.getCanonicalName()));
    }
    return methodParameter.getName();
}