use of java.lang.reflect.Executable in project spoon by INRIA.
the class CtTypeParameterTest method checkTypeParamErasureOfExecutable.
private void checkTypeParamErasureOfExecutable(CtTypeParameter typeParam) throws NoSuchFieldException, SecurityException {
CtExecutable<?> exec = (CtExecutable<?>) typeParam.getParent();
CtParameter<?> param = exec.filterChildren(new NamedElementFilter<>(CtParameter.class, "param" + typeParam.getSimpleName())).first();
assertNotNull("Missing param" + typeParam.getSimpleName() + " in " + exec.getSignature(), param);
int paramIdx = exec.getParameters().indexOf(param);
Class declClass = exec.getParent(CtType.class).getActualClass();
Executable declExec;
if (exec instanceof CtConstructor) {
declExec = declClass.getDeclaredConstructors()[0];
} else {
declExec = getMethodByName(declClass, exec.getSimpleName());
}
Class<?> paramType = declExec.getParameterTypes()[paramIdx];
// contract the type erasure given with Java reflection is the same as the one computed by spoon
assertEquals("TypeErasure of executable param " + getTypeParamIdentification(typeParam), paramType.getName(), typeParam.getTypeErasure().toString());
}
use of java.lang.reflect.Executable in project scheduler by btrplace.
the class TestScanner method testGroups.
public List<TestCampaign> testGroups(String... groups) throws IllegalAccessException, InvocationTargetException, InstantiationException {
List<Executable> ms = new ArrayList<>();
Set<String> ok = Stream.of(groups).collect(Collectors.toSet());
FastClasspathScanner scanner = new FastClasspathScanner();
scanner.matchClassesWithMethodAnnotation(CstrTest.class, (cl, m) -> {
CstrTest a = m.getAnnotation(CstrTest.class);
for (String g : a.groups()) {
if (ok.contains(g)) {
ms.add(m);
}
}
}).scan(Runtime.getRuntime().availableProcessors() - 1);
return test(ms.toArray(new Method[ms.size()]));
}
use of java.lang.reflect.Executable in project junit-dataprovider by TNG.
the class DataProviderParameterResolver method supportsParameter.
@Override
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) {
Executable declaringExecutable = parameterContext.getParameter().getDeclaringExecutable();
Method testMethod = extensionContext.getTestMethod().orElse(null);
return declaringExecutable.equals(testMethod) && parameterContext.getIndex() < arguments.size();
}
use of java.lang.reflect.Executable in project tutorials by eugenp.
the class MethodParameterFactory method createSynthesizingMethodParameter.
public static SynthesizingMethodParameter createSynthesizingMethodParameter(Parameter parameter) {
Assert.notNull(parameter, "Parameter must not be null");
Executable executable = parameter.getDeclaringExecutable();
if (executable instanceof Method) {
return new SynthesizingMethodParameter((Method) executable, getIndex(parameter));
}
throw new UnsupportedOperationException("Cannot create a SynthesizingMethodParameter for a constructor parameter: " + parameter);
}
use of java.lang.reflect.Executable in project tutorials by eugenp.
the class MethodParameterFactory method getIndex.
private static int getIndex(Parameter parameter) {
Assert.notNull(parameter, "Parameter must not be null");
Executable executable = parameter.getDeclaringExecutable();
Parameter[] parameters = executable.getParameters();
for (int i = 0; i < parameters.length; i++) {
if (parameters[i] == parameter) {
return i;
}
}
throw new IllegalStateException(String.format("Failed to resolve index of parameter [%s] in executable [%s]", parameter, executable.toGenericString()));
}
Aggregations