Skip to content

Commit

Permalink
tudo ou nad
Browse files Browse the repository at this point in the history
  • Loading branch information
yaansz committed Aug 29, 2024
1 parent 7244424 commit dea1c47
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void scan() {
}

private void scanPackage(String packageName) {
List<Class> classes = ScanUtils.getClassesInPackage(packageName, DiscordController.class).stream().toList();
List<Class<?>> classes = ScanUtils.getClassesInPackage(packageName, DiscordController.class).stream().toList();

for(Class clazz : classes) {
Object instance = context.getInstance(clazz);
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/com/softawii/curupira/v2/utils/ScanUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,25 @@ public class ScanUtils {

private static final Logger LOGGER = LoggerFactory.getLogger(ScanUtils.class);

public static Set<Class> getClassesInPackage(String pkg, Class annotation) {
public static Set<Class<?>> getClassesInPackage(String pkg, Class annotation) {
LOGGER.info("Scanning package: {}, annotation: {}", pkg, annotation);
Reflections reflections = new Reflections(
new ConfigurationBuilder()
.forPackages(pkg)
.setScanners(Scanners.SubTypes, Scanners.TypesAnnotated)
.filterInputsBy((input) -> input.endsWith(".class") && input.startsWith(pkg.replace('.', '/')))
);
return new HashSet<>(reflections.getTypesAnnotatedWith(annotation));
HashSet<Class<?>> set = new HashSet<Class<?>>(reflections.getTypesAnnotatedWith(annotation));

for(Class<?> clazz : set.stream().toList()) {
if(clazz.getPackage().getName().startsWith(pkg)) {
LOGGER.info("Found class: {}", clazz.getName());
} else {
set.remove(clazz);
}
}

return set;
}

public static List<Method> getMethodsAnnotatedWith(Class clazz, Class filtering) {
Expand Down

0 comments on commit dea1c47

Please sign in to comment.