use of java.lang.reflect.Parameter in project springframework-source-5.1.x by wb02125055.
the class StandardReflectionParameterNameDiscoverer method getParameterNames.
@Nullable
private String[] getParameterNames(Parameter[] parameters) {
String[] parameterNames = new String[parameters.length];
for (int i = 0; i < parameters.length; i++) {
Parameter param = parameters[i];
if (!param.isNamePresent()) {
return null;
}
parameterNames[i] = param.getName();
}
return parameterNames;
}
use of java.lang.reflect.Parameter in project springframework-source-5.1.x by wb02125055.
the class MethodParameter method findParameterIndex.
protected static int findParameterIndex(Parameter parameter) {
Executable executable = parameter.getDeclaringExecutable();
Parameter[] allParams = executable.getParameters();
// Try first with identity checks for greater performance.
for (int i = 0; i < allParams.length; i++) {
if (parameter == allParams[i]) {
return i;
}
}
// conditions while invoking java.lang.reflect.Executable.getParameters().
for (int i = 0; i < allParams.length; i++) {
if (parameter.equals(allParams[i])) {
return i;
}
}
throw new IllegalArgumentException("Given parameter [" + parameter + "] does not match any parameter in the declaring executable");
}
use of java.lang.reflect.Parameter in project springframework-source-5.1.x by wb02125055.
the class MethodParameter method getParameter.
/**
* Return the {@link Parameter} descriptor for method/constructor parameter.
* @since 5.0
*/
public Parameter getParameter() {
if (this.parameterIndex < 0) {
throw new IllegalStateException("Cannot retrieve Parameter descriptor for method return type");
}
Parameter parameter = this.parameter;
if (parameter == null) {
parameter = getExecutable().getParameters()[this.parameterIndex];
this.parameter = parameter;
}
return parameter;
}
use of java.lang.reflect.Parameter in project VMF by miho.
the class DelegationInfo method newInstance.
public static DelegationInfo newInstance(Model model, Method m, DelegationInfo constructorDelegationInfo) {
DelegateTo delegation = m.getAnnotation(DelegateTo.class);
String className = delegation == null ? (constructorDelegationInfo == null ? "" : constructorDelegationInfo.fullTypeName) : delegation.className();
// if(delegation==null) {
// return null;
// }
List<String> paramTypes = new ArrayList<>(m.getParameters().length);
List<String> paramNames = new ArrayList<>(m.getParameters().length);
boolean delegated = !m.getName().startsWith("get") && !m.getName().startsWith("is");
boolean varargs = m.isVarArgs();
for (Parameter p : m.getParameters()) {
paramTypes.add(TypeUtil.getTypeAsString(model, p.getType(), delegated, varargs));
paramNames.add(p.getName());
}
Doc doc = m.getAnnotation(Doc.class);
String customDocumentation;
if (doc != null) {
customDocumentation = doc.value();
} else {
customDocumentation = "";
}
return newInstance(className, m.getName(), TypeUtil.getReturnTypeAsString(model, m), paramTypes, paramNames, false, customDocumentation);
}
use of java.lang.reflect.Parameter in project quarkus by quarkusio.
the class GenerateAllLogUsages method main.
public static void main(String[] args) {
println("package io.quarkus.logging;");
println("");
println("// generated by GenerateAllLogUsages, don't update manually");
println("public class GeneratedBean {");
println(" public void testLogging() {");
Arrays.stream(Log.class.getDeclaredMethods()).filter(method -> Modifier.isPublic(method.getModifiers())).sorted(Comparator.comparing(Method::getName).thenComparingInt(Method::getParameterCount)).forEach(method -> {
Parameter[] parameters = method.getParameters();
String[] arguments = new String[method.getParameterCount()];
for (int i = 0; i < parameters.length; i++) {
Parameter parameter = parameters[i];
String argument;
if (parameter.getType() == Object.class && "message".equals(parameter.getName())) {
argument = "\"foobar\"";
} else if (parameter.getType() == Object.class && (parameter.getName().startsWith("param") || parameter.getName().startsWith("arg"))) {
argument = "new Object()";
} else if (parameter.getType() == Object[].class && "params".equals(parameter.getName())) {
argument = "new Object[] {}";
} else if (parameter.getType() == String.class && "loggerFqcn".equals(parameter.getName())) {
argument = "\"io.quarkus.logging.GeneratedBean\"";
} else if (parameter.getType() == String.class && "format".equals(parameter.getName())) {
argument = "\"foobar\"";
} else if (parameter.getType() == int.class) {
argument = "13";
} else if (parameter.getType() == long.class) {
argument = "42L";
} else if (parameter.getType() == Throwable.class) {
argument = "new NoStackTraceTestException()";
} else if (parameter.getType() == Logger.Level.class) {
argument = "org.jboss.logging.Logger.Level.INFO";
} else {
throw new RuntimeException("Couldn't generate argument value for parameter " + i + " of type " + method.getParameterTypes()[i] + ": " + method);
}
arguments[i] = argument;
}
println(" Log." + method.getName() + "(" + String.join(", ", arguments) + ");");
});
println(" }");
println("}");
}
Aggregations