Search in sources :

Example 26 with Executable

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());
}
Also used : CtType(spoon.reflect.declaration.CtType) NamedElementFilter(spoon.reflect.visitor.filter.NamedElementFilter) CtClass(spoon.reflect.declaration.CtClass) Executable(java.lang.reflect.Executable) CtExecutable(spoon.reflect.declaration.CtExecutable) CtExecutable(spoon.reflect.declaration.CtExecutable) CtConstructor(spoon.reflect.declaration.CtConstructor)

Example 27 with Executable

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()]));
}
Also used : Constraint(org.btrplace.safeplace.spec.Constraint) Arrays(java.util.Arrays) List(java.util.List) FastClasspathScanner(io.github.lukehutch.fastclasspathscanner.FastClasspathScanner) Stream(java.util.stream.Stream) Executable(java.lang.reflect.Executable) Set(java.util.Set) Method(java.lang.reflect.Method) Collectors(java.util.stream.Collectors) InvocationTargetException(java.lang.reflect.InvocationTargetException) ArrayList(java.util.ArrayList) FastClasspathScanner(io.github.lukehutch.fastclasspathscanner.FastClasspathScanner) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) Executable(java.lang.reflect.Executable)

Example 28 with Executable

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();
}
Also used : Method(java.lang.reflect.Method) Executable(java.lang.reflect.Executable)

Example 29 with Executable

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);
}
Also used : SynthesizingMethodParameter(org.springframework.core.annotation.SynthesizingMethodParameter) Method(java.lang.reflect.Method) Executable(java.lang.reflect.Executable)

Example 30 with Executable

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()));
}
Also used : Parameter(java.lang.reflect.Parameter) MethodParameter(org.springframework.core.MethodParameter) SynthesizingMethodParameter(org.springframework.core.annotation.SynthesizingMethodParameter) Executable(java.lang.reflect.Executable)

Aggregations

Executable (java.lang.reflect.Executable)39 Method (java.lang.reflect.Method)14 Constructor (java.lang.reflect.Constructor)9 Parameter (java.lang.reflect.Parameter)8 Field (java.lang.reflect.Field)6 Member (java.lang.reflect.Member)5 Annotation (java.lang.annotation.Annotation)4 List (java.util.List)4 AnalysisField (com.oracle.graal.pointsto.meta.AnalysisField)2 CEntryPointOptions (com.oracle.svm.core.c.function.CEntryPointOptions)2 JNIAccessibleMethodDescriptor (com.oracle.svm.jni.access.JNIAccessibleMethodDescriptor)2 AnnotatedType (java.lang.reflect.AnnotatedType)2 TypeVariable (java.lang.reflect.TypeVariable)2 Arrays (java.util.Arrays)2 HashSet (java.util.HashSet)2 Nullable (javax.annotation.Nullable)2 AnnotatedParameter (javax.enterprise.inject.spi.AnnotatedParameter)2 Named (javax.inject.Named)2 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2