use of java.lang.reflect.Parameter in project neo4j by neo4j.
the class MethodSignatureCompiler method signatureFor.
public List<FieldSignature> signatureFor(Method method) throws ProcedureException {
Parameter[] params = method.getParameters();
Type[] types = method.getGenericParameterTypes();
List<FieldSignature> signature = new ArrayList<>(params.length);
boolean seenDefault = false;
for (int i = 0; i < params.length; i++) {
Parameter param = params[i];
Type type = types[i];
if (!param.isAnnotationPresent(Name.class)) {
throw new ProcedureException(Status.Procedure.ProcedureRegistrationFailed, "Argument at position %d in method `%s` is missing an `@%s` annotation.%n" + "Please add the annotation, recompile the class and try again.", i, method.getName(), Name.class.getSimpleName());
}
Name parameter = param.getAnnotation(Name.class);
String name = parameter.value();
if (name.trim().length() == 0) {
throw new ProcedureException(Status.Procedure.ProcedureRegistrationFailed, "Argument at position %d in method `%s` is annotated with a name,%n" + "but the name is empty, please provide a non-empty name for the argument.", i, method.getName());
}
try {
NeoValueConverter valueConverter = typeMappers.converterFor(type);
Optional<Neo4jValue> defaultValue = valueConverter.defaultValue(parameter);
//it is not allowed to have holes in default values
if (seenDefault && !defaultValue.isPresent()) {
throw new ProcedureException(Status.Procedure.ProcedureRegistrationFailed, "Non-default argument at position %d with name %s in method %s follows default argument. " + "Add a default value or rearrange arguments so that the non-default values comes first.", i, parameter.value(), method.getName());
}
seenDefault = defaultValue.isPresent();
signature.add(new FieldSignature(name, valueConverter.type(), defaultValue));
} catch (ProcedureException e) {
throw new ProcedureException(e.status(), "Argument `%s` at position %d in `%s` with%n" + "type `%s` cannot be converted to a Neo4j type: %s", name, i, method.getName(), param.getType().getSimpleName(), e.getMessage());
}
}
return signature;
}
use of java.lang.reflect.Parameter in project Synthese_2BIN by TheYoungSensei.
the class Controleur method chercherConstruteurs.
private List<Propriete> chercherConstruteurs(Class cls) {
List<Propriete> constructeurs = new ArrayList<Propriete>();
for (Constructor constructeur : cls.getDeclaredConstructors()) {
Visibilite visibilite = chercherVisibilite(constructeur.getModifiers());
boolean estStatique = false;
if (Modifier.isStatic(constructeur.getModifiers()))
estStatique = true;
String nom = constructeur.getName();
String ex = chercherExceptions(constructeur.getExceptionTypes());
Parameter[] parameters = constructeur.getParameters();
nom += " (";
nom += chercherParametres(parameters);
nom += ") " + ex;
Propriete prop = new Propriete(nom, estStatique, Modifier.isAbstract(constructeur.getModifiers()), visibilite);
constructeurs.add(prop);
}
return constructeurs;
}
use of java.lang.reflect.Parameter in project spring-framework by spring-projects.
the class SpringExtension method supports.
/**
* Determine if the value for the {@link Parameter} in the supplied {@link ParameterContext}
* should be autowired from the test's {@link ApplicationContext}.
* <p>Returns {@code true} if the parameter is declared in a {@link Constructor}
* that is annotated with {@link Autowired @Autowired} and otherwise delegates to
* {@link ParameterAutowireUtils#isAutowirable}.
* <p><strong>WARNING</strong>: If the parameter is declared in a {@code Constructor}
* that is annotated with {@code @Autowired}, Spring will assume the responsibility
* for resolving all parameters in the constructor. Consequently, no other registered
* {@link ParameterResolver} will be able to resolve parameters.
* @see #resolve
* @see ParameterAutowireUtils#isAutowirable
*/
@Override
public boolean supports(ParameterContext parameterContext, ExtensionContext extensionContext) {
Parameter parameter = parameterContext.getParameter();
Executable executable = parameter.getDeclaringExecutable();
return (executable instanceof Constructor && AnnotatedElementUtils.hasAnnotation(executable, Autowired.class)) || ParameterAutowireUtils.isAutowirable(parameter);
}
use of java.lang.reflect.Parameter in project spring-framework by spring-projects.
the class MethodParameter method findParameterIndex.
protected static int findParameterIndex(Parameter parameter) {
Executable executable = parameter.getDeclaringExecutable();
Parameter[] allParams = executable.getParameters();
for (int i = 0; i < allParams.length; i++) {
if (parameter == 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 felix by apache.
the class Helpers method getLambdaParameterName.
/**
* Extracts the first parameter of a lambda.
*/
public static String getLambdaParameterName(SerializableLambda lambda, int index) {
SerializedLambda serialized = getSerializedLambda(lambda);
Method m = getLambdaMethod(serialized, lambda.getClass().getClassLoader());
Parameter p = m.getParameters()[index];
if (Objects.equals("arg0", p.getName())) {
throw new IllegalStateException("Can'f find lambda method name (Please check you are using javac -parameters option).");
}
return p.getName();
}
Aggregations