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()));
}
}
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());
}
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);
}
}
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);
}
}
Aggregations