<commit_before>package com.foo;

import com.bar.BarRepository;
import com.gaz.GazRepository;

import java.io.*;
import java.lang.reflect.*;
import java.net.*;
import java.util.*;

import static java.util.Collections.emptyList;

public class ProjectRunner {
    private static Map<Class, Object> demoComponentClasses = collectDemoComponentClasses();

    public static void main(String[] args) throws IOException, URISyntaxException, IllegalAccessException, InstantiationException, InvocationTargetException {
        FooController fooController = new FooController();

        for (Package p : Package.getPackages()) {
            List<Class> classesForPackage = getClassesForPackage(p);

            classesForPackage.forEach(cls -> {
                if (cls.isAnnotationPresent(DemoController.class)) {
                    for (Field field : cls.getDeclaredFields()) {
                        if (field.isAnnotationPresent(DemoAutowired.class)) {
                            if (demoComponentClasses.containsKey(field.getType())) {
                                try {
                                    // @TJ is the man
                                    field.set(fooController, demoComponentClasses.get(field.getType()));
                                } catch (IllegalAccessException e) {
                                    e.printStackTrace();
                                }
                            }
                        }
                    }
                }
            });
        }

        fooController.serveSomePage();
    }

    private static Map<Class, Object> collectDemoComponentClasses() {
        BarRepository barRepository = new BarRepository();
        GazRepository gazRepository = new GazRepository();

        Map<Class, Object> classInstances = new HashMap<>();

        for (Package p : Package.getPackages()) {
            List<Class> classesForPackage = getClassesForPackage(p);

            classesForPackage.forEach(cls -> {
                if (cls.isAnnotationPresent(DemoRepository.class)) {
                    try {
                        classInstances.put(cls, cls.newInstance());
                    } catch (InstantiationException | IllegalAccessException e) {
                        e.printStackTrace();
                    }
                }
            });
        }

        return classInstances;
    }

    /*
    for (Method method : cls.getDeclaredMethods()) {
                        if (method.isAnnotationPresent(DemoAutowired.class)) {
                            DemoAutowired demoAutowiredAnnotation = method.getAnnotation(DemoAutowired.class);

                            try {
                                method.invoke(cls.newInstance());
                            } catch (IllegalAccessException | InvocationTargetException | InstantiationException e) {
                                e.printStackTrace();
                            }
                        }
                    }
     */

    private static List<Class> getClassesForPackage(Package aPackage) {
        String packageName = aPackage.getName();
        List<Class> classes = new ArrayList<>();
        String relativePath = packageName.replace('.', '/');
        URL resource = ClassLoader.getSystemClassLoader().getResource(relativePath);

        if (resource == null) {
            // System.out.println("No resource for " + relativePath);
            return emptyList();
        }

        File directory;
        try {
            directory = new File(resource.toURI());
        } catch (URISyntaxException | IllegalArgumentException e) {
            // System.out.println(packageName + " (" + resource + ") does not appear to be a valid URL / URI.  Strange, since we got it from the system...");
            return emptyList();
        }

        if (directory.exists()) {
            for (String file : directory.list()) {
                if (file.endsWith(".class")) {
                    // removes the .class extension
                    String className = packageName + '.' + file.substring(0, file.length() - 6);

                    try {
                        classes.add(Class.forName(className));
                    } catch (ClassNotFoundException e) {
                        throw new RuntimeException("ClassNotFoundException loading " + className);
                    }
                }
            }
        } else {
            // System.out.println(packageName + " (" + directory + ") does not appear to be a valid package");
            return emptyList();
        }

        return classes;
    }
}
<commit_msg>Cleanup<commit_after>package com.foo;

import com.bar.BarRepository;
import com.gaz.GazRepository;

import java.io.*;
import java.lang.reflect.*;
import java.net.*;
import java.util.*;

import static java.util.Collections.emptyList;

public class ProjectRunner {
    private static Map<Class, Object> demoComponentClasses = collectDemoComponentClasses();

    public static void main(String[] args) throws IOException, URISyntaxException, IllegalAccessException, InstantiationException, InvocationTargetException {
        FooController fooController = new FooController();

        for (Package p : Package.getPackages()) {
            List<Class> classesForPackage = getClassesForPackage(p);

            classesForPackage.forEach(cls -> {
                if (cls.isAnnotationPresent(DemoController.class)) {
                    for (Field field : cls.getDeclaredFields()) {
                        if (field.isAnnotationPresent(DemoAutowired.class)) {
                            if (demoComponentClasses.containsKey(field.getType())) {
                                try {
                                    field.set(fooController, demoComponentClasses.get(field.getType()));
                                } catch (IllegalAccessException e) {
                                    e.printStackTrace();
                                }
                            }
                        }
                    }
                }
            });
        }

        fooController.serveSomePage();
    }

    private static Map<Class, Object> collectDemoComponentClasses() {
        BarRepository barRepository = new BarRepository();
        GazRepository gazRepository = new GazRepository();

        Map<Class, Object> classInstances = new HashMap<>();

        for (Package p : Package.getPackages()) {
            List<Class> classesForPackage = getClassesForPackage(p);

            classesForPackage.forEach(cls -> {
                if (cls.isAnnotationPresent(DemoRepository.class)) {
                    try {
                        classInstances.put(cls, cls.newInstance());
                    } catch (InstantiationException | IllegalAccessException e) {
                        e.printStackTrace();
                    }
                }
            });
        }

        return classInstances;
    }

    /*
    for (Method method : cls.getDeclaredMethods()) {
                        if (method.isAnnotationPresent(DemoAutowired.class)) {
                            DemoAutowired demoAutowiredAnnotation = method.getAnnotation(DemoAutowired.class);

                            try {
                                method.invoke(cls.newInstance());
                            } catch (IllegalAccessException | InvocationTargetException | InstantiationException e) {
                                e.printStackTrace();
                            }
                        }
                    }
     */

    private static List<Class> getClassesForPackage(Package aPackage) {
        String packageName = aPackage.getName();
        List<Class> classes = new ArrayList<>();
        String relativePath = packageName.replace('.', '/');
        URL resource = ClassLoader.getSystemClassLoader().getResource(relativePath);

        if (resource == null) {
            // System.out.println("No resource for " + relativePath);
            return emptyList();
        }

        File directory;
        try {
            directory = new File(resource.toURI());
        } catch (URISyntaxException | IllegalArgumentException e) {
            // System.out.println(packageName + " (" + resource + ") does not appear to be a valid URL / URI.  Strange, since we got it from the system...");
            return emptyList();
        }

        if (directory.exists()) {
            for (String file : directory.list()) {
                if (file.endsWith(".class")) {
                    // removes the .class extension
                    String className = packageName + '.' + file.substring(0, file.length() - 6);

                    try {
                        classes.add(Class.forName(className));
                    } catch (ClassNotFoundException e) {
                        throw new RuntimeException("ClassNotFoundException loading " + className);
                    }
                }
            }
        } else {
            // System.out.println(packageName + " (" + directory + ") does not appear to be a valid package");
            return emptyList();
        }

        return classes;
    }
}

{'fraction_non_alphanumeric': 0.09597286058218428, 'fraction_numerical': 0.0004377325454147516, 'mean_word_length': 1.5542202347680267, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4555756', 'n_tokens_mistral': 2103, 'n_tokens_neox': 2005, 'n_words': 450}