use of java.lang.reflect.Executable in project junit5 by junit-team.
the class ExecutableInvoker method resolveParameter.
private Object resolveParameter(ParameterContext parameterContext, Executable executable, ExtensionContext extensionContext, ExtensionRegistry extensionRegistry) {
try {
// @formatter:off
List<ParameterResolver> matchingResolvers = extensionRegistry.stream(ParameterResolver.class).filter(resolver -> resolver.supportsParameter(parameterContext, extensionContext)).collect(toList());
if (matchingResolvers.isEmpty()) {
throw new ParameterResolutionException(String.format("No ParameterResolver registered for parameter [%s] in executable [%s].", parameterContext.getParameter(), executable.toGenericString()));
}
if (matchingResolvers.size() > 1) {
// @formatter:off
String resolverNames = matchingResolvers.stream().map(resolver -> resolver.getClass().getName()).collect(joining(", "));
// @formatter:on
throw new ParameterResolutionException(String.format("Discovered multiple competing ParameterResolvers for parameter [%s] in executable [%s]: %s", parameterContext.getParameter(), executable.toGenericString(), resolverNames));
}
ParameterResolver resolver = matchingResolvers.get(0);
Object value = resolver.resolveParameter(parameterContext, extensionContext);
validateResolvedType(parameterContext.getParameter(), value, executable, resolver);
logger.trace(() -> String.format("ParameterResolver [%s] resolved a value of type [%s] for parameter [%s] in executable [%s].", resolver.getClass().getName(), (value != null ? value.getClass().getName() : null), parameterContext.getParameter(), executable.toGenericString()));
return value;
} catch (ParameterResolutionException ex) {
throw ex;
} catch (Throwable ex) {
throw new ParameterResolutionException(String.format("Failed to resolve parameter [%s] in executable [%s]", parameterContext.getParameter(), executable.toGenericString()), ex);
}
}
use of java.lang.reflect.Executable in project SilverKing by Morgan-Stanley.
the class JNIUtil method getReferencedClasses.
public static <E extends Executable> Set<Class> getReferencedClasses(E[] ea) {
Set<Class> s;
s = new HashSet<>();
for (Executable e : ea) {
s.addAll(getReferencedClasses(e));
}
return s;
}
use of java.lang.reflect.Executable in project SilverKing by Morgan-Stanley.
the class JNIUtil method main.
public static void main(String[] args) {
// System.out.println(CollectionUtil.toString(getReferencedClasses(GetOptions.class)));
for (Executable e : GetOptions.class.getDeclaredMethods()) {
System.out.println(e);
}
System.out.println();
System.out.println();
for (Executable e : GetOptions.class.getMethods()) {
System.out.println(e);
}
}
use of java.lang.reflect.Executable in project graal by oracle.
the class JNIFunctions method ToReflectedMethod.
/*
* jobject ToReflectedMethod(JNIEnv *env, jclass cls, jmethodID methodID, jboolean isStatic);
*/
@CEntryPoint
@CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, exceptionHandler = JNIExceptionHandlerReturnNullHandle.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static JNIObjectHandle ToReflectedMethod(JNIEnvironment env, JNIObjectHandle classHandle, JNIMethodId methodId, boolean isStatic) {
Executable result = null;
if (JNIAccessFeature.singleton().haveJavaRuntimeReflectionSupport()) {
JNIAccessibleMethod jniMethod = JNIReflectionDictionary.getMethodByID(methodId);
JNIAccessibleMethodDescriptor descriptor = JNIReflectionDictionary.getMethodDescriptor(jniMethod);
if (descriptor != null) {
Class<?> clazz = jniMethod.getDeclaringClass().getClassObject();
if (descriptor.isConstructor()) {
for (Constructor<?> ctor : clazz.getDeclaredConstructors()) {
if (descriptor.equals(JNIAccessibleMethodDescriptor.of(ctor))) {
result = ctor;
break;
}
}
} else {
for (Method method : clazz.getDeclaredMethods()) {
if (descriptor.getName().equals(method.getName())) {
if (descriptor.equals(JNIAccessibleMethodDescriptor.of(method))) {
result = method;
break;
}
}
}
}
}
}
return JNIThreadLocalHandles.get().create(result);
}
use of java.lang.reflect.Executable in project graal by oracle.
the class JNIAccessFeature method duringAnalysis.
@Override
public void duringAnalysis(DuringAnalysisAccess a) {
DuringAnalysisAccessImpl access = (DuringAnalysisAccessImpl) a;
if (!wereElementsAdded()) {
return;
}
for (Class<?> clazz : newClasses) {
addClass(clazz, access);
}
newClasses.clear();
for (Executable method : newMethods) {
addMethod(method, access);
}
newMethods.clear();
for (Field field : newFields) {
addField(field, access);
}
newFields.clear();
JNIReflectionDictionary.singleton().addLinkages(newLinkages);
newLinkages.clear();
access.requireAnalysisIteration();
}
Aggregations