Search in sources :

Example 1 with MethodParameterInfo

use of io.github.classgraph.MethodParameterInfo in project conquery by bakdata.

the class GroupHandler method handleEndpoint.

private void handleEndpoint(String url, MethodInfo method) throws IOException {
    Introspection introspec = Introspection.from(root, method.getClassInfo()).findMethod(method);
    try (Closeable details = details(getRestMethod(method) + "\u2001" + url, method.getClassInfo(), introspec)) {
        out.paragraph("Method: " + code(method.getName()));
        for (MethodParameterInfo param : method.getParameterInfo()) {
            if (param.hasAnnotation(PATH_PARAM) || param.hasAnnotation(AUTH) || param.hasAnnotation(CONTEXT)) {
                continue;
            }
            out.line("Expects: " + printType(new Ctx(), param.getTypeSignatureOrTypeDescriptor()));
        }
        out.paragraph("Returns: " + printType(new Ctx(), method.getTypeSignatureOrTypeDescriptor().getResultType()));
    }
}
Also used : Closeable(java.io.Closeable) Introspection(com.bakdata.conquery.introspection.Introspection) MethodParameterInfo(io.github.classgraph.MethodParameterInfo)

Example 2 with MethodParameterInfo

use of io.github.classgraph.MethodParameterInfo in project helidon by oracle.

the class JaxRsMethodAnalyzer method find.

Set<Class<?>> find() {
    ClassInfoList classes = context.scan().getClassesWithMethodAnnotation(HTTP_METHOD_ANNOTATION);
    for (ClassInfo aClass : classes) {
        MethodInfoList methods = aClass.getMethodInfo();
        for (MethodInfo method : methods) {
            if (method.hasAnnotation(HTTP_METHOD_ANNOTATION)) {
                add(method.getTypeSignatureOrTypeDescriptor().getResultType());
                MethodParameterInfo[] parameterInfo = method.getParameterInfo();
                for (MethodParameterInfo param : parameterInfo) {
                    if (param.getAnnotationInfo().isEmpty()) {
                        add(param.getTypeSignatureOrTypeDescriptor());
                    }
                }
            }
        }
    }
    Set<String> result = Set.copyOf(classesToAdd);
    classesToAdd.clear();
    return result.stream().map(nativeUtil.classMapper("jaxrs-result-or-param")).filter(Objects::nonNull).filter(nativeUtil.inclusionFilter("jaxrs-result-or-param")).collect(Collectors.toSet());
}
Also used : ClassInfoList(io.github.classgraph.ClassInfoList) Objects(java.util.Objects) MethodInfoList(io.github.classgraph.MethodInfoList) MethodInfo(io.github.classgraph.MethodInfo) MethodParameterInfo(io.github.classgraph.MethodParameterInfo) ClassInfo(io.github.classgraph.ClassInfo)

Example 3 with MethodParameterInfo

use of io.github.classgraph.MethodParameterInfo in project classgraph by classgraph.

the class MethodInfoTest method testMethodInfoLoadMethodForArrayArg.

/**
 * MethodInfo.loadClassAndGetMethod for arrays argument (#344)
 */
@Test
public void testMethodInfoLoadMethodForArrayArg() {
    try (ScanResult scanResult = new ClassGraph().acceptPackages(MethodInfoTest.class.getPackage().getName()).enableClassInfo().enableMethodInfo().enableAnnotationInfo().scan()) {
        final MethodInfo mi = scanResult.getClassInfo(MethodInfoTest.class.getName()).getMethodInfo().getSingleMethod("publicMethodWithArgs");
        assertThat(mi).isNotNull();
        assertThatCode(() -> {
            mi.loadClassAndGetMethod();
        }).doesNotThrowAnyException();
        assertThat(mi.loadClassAndGetMethod()).isNotNull();
        // Extract array-typed params from method params
        final List<ArrayClassInfo> arrayClassInfoList = new ArrayList<>();
        for (final MethodParameterInfo mpi : mi.getParameterInfo()) {
            final TypeSignature paramTypeSig = mpi.getTypeSignatureOrTypeDescriptor();
            if (paramTypeSig instanceof ArrayTypeSignature) {
                arrayClassInfoList.add(((ArrayTypeSignature) paramTypeSig).getArrayClassInfo());
            }
        }
        assertThat(arrayClassInfoList.toString()).isEqualTo("[class float[], class byte[][], " + "class " + X.class.getName() + "[][][], " + "class java.lang.String[][]]");
        final ArrayClassInfo p1 = arrayClassInfoList.get(1);
        assertThat(p1.loadElementClass()).isEqualTo(byte.class);
        assertThat(p1.loadClass()).isEqualTo(byte[][].class);
        assertThat(p1.getElementClassInfo()).isNull();
        assertThat(p1.getNumDimensions()).isEqualTo(2);
        final ArrayClassInfo p2 = arrayClassInfoList.get(2);
        assertThat(p2.loadElementClass()).isEqualTo(X.class);
        assertThat(p2.getElementClassInfo().getName()).isEqualTo(X.class.getName());
        assertThat(p2.loadClass()).isEqualTo(X[][][].class);
        assertThat(p2.getElementClassInfo().getMethodInfo().get(0).getName()).isEqualTo("xMethod");
        assertThat(p2.getNumDimensions()).isEqualTo(3);
        final ArrayClassInfo p3 = arrayClassInfoList.get(3);
        assertThat(p3.loadElementClass()).isEqualTo(String.class);
        assertThat(p3.loadClass()).isEqualTo(String[][].class);
        assertThat(p3.getElementClassInfo()).isNull();
        assertThat(p3.getNumDimensions()).isEqualTo(2);
    }
}
Also used : ArrayClassInfo(io.github.classgraph.ArrayClassInfo) ScanResult(io.github.classgraph.ScanResult) TypeSignature(io.github.classgraph.TypeSignature) ArrayTypeSignature(io.github.classgraph.ArrayTypeSignature) ClassGraph(io.github.classgraph.ClassGraph) ArrayList(java.util.ArrayList) MethodInfo(io.github.classgraph.MethodInfo) MethodParameterInfo(io.github.classgraph.MethodParameterInfo) ArrayTypeSignature(io.github.classgraph.ArrayTypeSignature) Test(org.junit.jupiter.api.Test)

Example 4 with MethodParameterInfo

use of io.github.classgraph.MethodParameterInfo in project classgraph by classgraph.

the class Issue355 method test.

/**
 * Test.
 *
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
@Test
public void test() throws IOException {
    try (ScanResult scanResult = new ClassGraph().acceptPackagesNonRecursive(Issue355.class.getPackage().getName()).enableClassInfo().enableInterClassDependencies().scan()) {
        final ClassInfo y = scanResult.getClassInfo(Y.class.getName());
        final ClassInfo x = scanResult.getClassInfo(X.class.getName());
        assertThat(y).isNotNull();
        assertThat(x).isNotNull();
        // Test array-typed annotation parameter
        final Object annParamVal = ((Object[]) y.getAnnotationInfo().get(0).getParameterValues().get(0).getValue())[0];
        assertThat(annParamVal).isInstanceOf(AnnotationClassRef.class);
        final AnnotationClassRef annClassRef = (AnnotationClassRef) annParamVal;
        assertThat(annClassRef.getClassInfo().getName()).isEqualTo(X.class.getName());
        // Test class dep from annotation param of array element type shows up in class deps
        final ClassInfoList yDeps = scanResult.getClassDependencyMap().get(y);
        assertThat(yDeps).isNotNull();
        assertThat(yDeps).contains(x);
        // Test array-typed method parameter
        final MethodParameterInfo yParam = y.getMethodInfo().get(0).getParameterInfo()[0];
        final ArrayTypeSignature paramTypeSignature = (ArrayTypeSignature) yParam.getTypeSignatureOrTypeDescriptor();
        final ArrayClassInfo arrayClassInfo = paramTypeSignature.getArrayClassInfo();
        assertThat(arrayClassInfo.getElementClassInfo().equals(x));
        assertThat(arrayClassInfo.loadClass()).isEqualTo(X[].class);
        assertThat(arrayClassInfo.loadElementClass()).isEqualTo(X.class);
    }
}
Also used : ArrayClassInfo(io.github.classgraph.ArrayClassInfo) ScanResult(io.github.classgraph.ScanResult) AnnotationClassRef(io.github.classgraph.AnnotationClassRef) ClassInfoList(io.github.classgraph.ClassInfoList) ClassGraph(io.github.classgraph.ClassGraph) MethodParameterInfo(io.github.classgraph.MethodParameterInfo) ArrayTypeSignature(io.github.classgraph.ArrayTypeSignature) ClassInfo(io.github.classgraph.ClassInfo) ArrayClassInfo(io.github.classgraph.ArrayClassInfo) Test(org.junit.jupiter.api.Test)

Aggregations

MethodParameterInfo (io.github.classgraph.MethodParameterInfo)4 ArrayClassInfo (io.github.classgraph.ArrayClassInfo)2 ArrayTypeSignature (io.github.classgraph.ArrayTypeSignature)2 ClassGraph (io.github.classgraph.ClassGraph)2 ClassInfo (io.github.classgraph.ClassInfo)2 ClassInfoList (io.github.classgraph.ClassInfoList)2 MethodInfo (io.github.classgraph.MethodInfo)2 ScanResult (io.github.classgraph.ScanResult)2 Test (org.junit.jupiter.api.Test)2 Introspection (com.bakdata.conquery.introspection.Introspection)1 AnnotationClassRef (io.github.classgraph.AnnotationClassRef)1 MethodInfoList (io.github.classgraph.MethodInfoList)1 TypeSignature (io.github.classgraph.TypeSignature)1 Closeable (java.io.Closeable)1 ArrayList (java.util.ArrayList)1 Objects (java.util.Objects)1