use of io.github.classgraph.MethodInfo in project conquery by bakdata.
the class GroupHandler method handle.
public void handle() throws IOException {
out.heading(group.getName());
out.paragraph("This is an automatically created documentation. It is not 100% accurate since the generator does not handle every edge case.");
out.paragraph("Instead of a list ConQuery also always accepts a single element.");
if (group.getDescription() != null) {
out.paragraph(group.getDescription());
}
for (Base base : group.getBases()) {
content.putAll(base, scan.getAllClasses().stream().filter(c -> c.hasAnnotation(CPS_TYPE)).flatMap(c -> Arrays.stream(c.loadClass().getAnnotationsByType(CPSType.class)).map(anno -> Pair.of(anno, c))).filter(p -> p.getLeft().base().equals(base.getBaseClass())).collect(Collectors.toList()));
}
for (Class<?> resource : group.getResources()) {
collectEndpoints(resource);
}
if (!endpoints.isEmpty()) {
out.heading("REST endpoints");
for (Pair<String, MethodInfo> endpoint : endpoints.stream().sorted(Comparator.comparing(Pair::getLeft)).collect(Collectors.toList())) {
handleEndpoint(endpoint.getLeft(), endpoint.getRight());
}
}
for (Base base : group.getBases()) {
handleBase(base);
}
out.subHeading("Other Types");
for (Class<?> t : group.getOtherClasses().stream().sorted(Comparator.comparing(Class::getSimpleName)).collect(Collectors.toList())) {
handleClass(typeTitle(t), scan.getClassInfo(t.getName()));
}
if (!group.getMarkerInterfaces().isEmpty()) {
out.subHeading("Marker Interfaces");
for (Class<?> t : group.getMarkerInterfaces().stream().sorted(Comparator.comparing(Class::getSimpleName)).collect(Collectors.toList())) {
handleMarkerInterface(markerTitle(t), scan.getClassInfo(t.getName()));
}
}
}
use of io.github.classgraph.MethodInfo in project conquery by bakdata.
the class GroupHandler method collectEndpoints.
private void collectEndpoints(Class<?> resource) throws IOException {
ClassInfo info = scan.getClassInfo(resource.getName());
for (MethodInfo method : info.getMethodInfo()) {
if (getRestMethod(method) == null) {
continue;
}
UriBuilder builder = UriBuilder.fromResource(resource);
if (method.hasAnnotation(PATH)) {
builder = builder.path(resource, method.getName());
}
endpoints.add(Pair.of(builder.toTemplate(), method));
}
}
use of io.github.classgraph.MethodInfo 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.MethodInfo in project AdvantageKit by Mechanical-Advantage.
the class Sigcheck method compareClasses.
private static boolean compareClasses(ClassInfo original, ClassInfo patch) {
List<String> failures = new ArrayList<>();
// Ensure patch class has same fields as original
for (FieldInfo originalField : original.getFieldInfo()) {
if (!originalField.isPublic())
// Skip non-public fields (not part of the API)
continue;
// Check that the patch class has the field
FieldInfo patchField = patch.getFieldInfo(originalField.getName());
if (patchField != null) {
List<String> fieldFailures = new ArrayList<>();
// Field is present, compare
if (!originalField.getModifiersStr().equals(patchField.getModifiersStr())) {
fieldFailures.add("\t -> Expected modifiers '" + originalField.getModifiersStr() + "' but got '" + patchField.getModifiersStr() + "'");
}
if (!originalField.getTypeSignatureOrTypeDescriptorStr().equals(patchField.getTypeSignatureOrTypeDescriptorStr())) {
// Intentionally not using getTypeSignatureOrTypeDescriptorStr as this method
// doesn't return nice names for primitives
fieldFailures.add("\t -> Expected type '" + originalField.getTypeSignatureOrTypeDescriptor() + "' but got '" + patchField.getTypeSignatureOrTypeDescriptor() + "'");
}
if (!fieldFailures.isEmpty()) {
failures.add("\t-> For field '" + originalField.getName() + "'");
failures.addAll(fieldFailures);
}
} else {
failures.add("\t-> Missing field '" + originalField + "'");
}
}
// Ensure patch class has same methods as original
for (MethodInfo originalMethod : original.getMethodAndConstructorInfo()) {
if (!originalMethod.isPublic())
// Skip non-public methods (not part of the API)
continue;
// Check that the patch class has the method
MethodInfo patchMethod = patch.getMethodInfo(originalMethod.getName()).stream().filter(originalMethod::equals).findFirst().orElse(null);
if (patchMethod == null) {
failures.add("\t-> Missing method '" + originalMethod + "'");
// The method is either outright missing or incorrectly defined
// Reverse lookup in the original class to see if there are any methods defined
// in the patch that aren't defined in the original
List<String> mismatchedMethods = new ArrayList<>();
for (MethodInfo m : patch.getMethodInfo(originalMethod.getName())) {
if (!original.getMethodAndConstructorInfo().contains(m)) {
mismatchedMethods.add("\t -> '" + m + "'");
}
}
if (!mismatchedMethods.isEmpty()) {
failures.add("\t -> Found " + mismatchedMethods.size() + (mismatchedMethods.size() == 1 ? " method" : " methods") + " with same name in patch that " + (mismatchedMethods.size() == 1 ? "does" : "do") + " not match any original method signatures");
failures.addAll(mismatchedMethods);
}
}
}
if (!failures.isEmpty()) {
System.out.println("[FAIL] For class '" + original.getName() + "'");
failures.forEach(System.out::println);
return false;
} else {
System.out.println("[PASS] Class '" + original.getName() + "'");
}
return true;
}
use of io.github.classgraph.MethodInfo in project domui by fjalvingh.
the class PageUrlMapping method scan.
public void scan() {
ScanResult r = m_application.getClasspathScanResult();
for (ClassInfo classInfo : r.getClassesWithAnnotation(UIPage.class.getName())) {
AnnotationInfo anninfo = classInfo.getAnnotationInfo(UIPage.class.getName());
String pattern = (String) anninfo.getParameterValues().getValue("value");
LOG.info("Page " + classInfo.getName() + " url " + pattern);
// -- Find all methods annotated with UIUrlParameter
Map<String, String> pageParams = new HashMap<>();
for (MethodInfo methodInfo : classInfo.getMethodInfo()) {
AnnotationInfo mai = methodInfo.getAnnotationInfo(UIUrlParameter.class.getName());
if (null != mai) {
String typeStr = methodInfo.getTypeDescriptor().getResultType().toString();
String pname = (String) mai.getParameterValues().getValue("name");
if (pname == null || pname.isEmpty()) {
pname = methodInfo.getName();
if (pname.startsWith("is")) {
pname = pname.substring(2);
} else if (pname.startsWith("get")) {
pname = pname.substring(3);
}
pname = Introspector.decapitalize(pname);
}
pageParams.put(pname, typeStr);
}
}
appendPage(classInfo.getName(), pattern, pageParams);
}
}
Aggregations