package de.dhbwstuttgart.environment; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.Set; import org.reflections.Reflections; import org.reflections.scanners.ResourcesScanner; import org.reflections.scanners.SubTypesScanner; import org.reflections.util.ClasspathHelper; import org.reflections.util.ConfigurationBuilder; import org.reflections.util.FilterBuilder; import de.dhbwstuttgart.exceptions.DebugException; import de.dhbwstuttgart.parser.JavaTXParser; import de.dhbwstuttgart.parser.antlr.Java8Parser.CompilationUnitContext; import de.dhbwstuttgart.parser.scope.GatherNames; import de.dhbwstuttgart.parser.scope.JavaClassRegistry; /** * Stellt die Java-Environment dar und speichert alle Binarys, Librarys und Sourcefiles im zu kompilierenden Projekt * Sie erstellt anhand dieser Informationen die JavaClassNameRegistry * * TODO: Zur Initialisierung der CompilationEnvironment sollten alle SourceFiles mit ANTLR geparst werden und alle Klassen Generics und Typen herausgefunden werden */ public class CompilationEnvironment { private final List librarys; /** * Imitiert die Environment beim Aufruf des JavaCompilers auf einer Menge von java-Dateien * Die Environment enthält automatisch die Java Standard Library * @param sourceFiles die zu kompilierenden Dateien */ public CompilationEnvironment(List sourceFiles) { String bootClassPath = System.getProperty("sun.boot.class.path"); librarys = new ArrayList<>(); for(String path : bootClassPath.split(";")) { try { librarys.add(new URL("file:"+path)); } catch (MalformedURLException e) { new DebugException("Fehler im Classpath auf diesem System"); } } } public JavaClassRegistry getRegistry(File forSourceFile) throws ClassNotFoundException, IOException { List allNames = new ArrayList<>(); CompilationUnitContext tree = JavaTXParser.parse(forSourceFile); return new JavaClassRegistry(GatherNames.getNames(tree, new PackageCrawler(librarys))); } }