2017-09-20 13:52:14 +00:00
|
|
|
|
package de.dhbwstuttgart.environment;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
2017-09-20 15:26:09 +00:00
|
|
|
|
import java.io.IOException;
|
2017-09-20 13:52:14 +00:00
|
|
|
|
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;
|
2017-09-20 15:26:09 +00:00
|
|
|
|
import de.dhbwstuttgart.parser.JavaTXParser;
|
|
|
|
|
import de.dhbwstuttgart.parser.antlr.Java8Parser.CompilationUnitContext;
|
|
|
|
|
import de.dhbwstuttgart.parser.scope.GatherNames;
|
|
|
|
|
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
2017-09-20 13:52:14 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Stellt die Java-Environment dar und speichert alle Binarys, Librarys und Sourcefiles im zu kompilierenden Projekt
|
|
|
|
|
* Sie erstellt anhand dieser Informationen die JavaClassNameRegistry
|
2017-09-20 15:26:09 +00:00
|
|
|
|
*
|
|
|
|
|
* TODO: Zur Initialisierung der CompilationEnvironment sollten alle SourceFiles mit ANTLR geparst werden und alle Klassen Generics und Typen herausgefunden werden
|
2017-09-20 13:52:14 +00:00
|
|
|
|
*/
|
|
|
|
|
public class CompilationEnvironment {
|
|
|
|
|
private final List<URL> librarys;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Imitiert die Environment beim Aufruf des JavaCompilers auf einer Menge von java-Dateien
|
2017-09-20 16:20:52 +00:00
|
|
|
|
* Die Environment enth<EFBFBD>lt automatisch die Java Standard Library
|
2017-09-20 13:52:14 +00:00
|
|
|
|
* @param sourceFiles die zu kompilierenden Dateien
|
|
|
|
|
*/
|
|
|
|
|
public CompilationEnvironment(List<File> sourceFiles) {
|
|
|
|
|
String bootClassPath = System.getProperty("sun.boot.class.path");
|
|
|
|
|
librarys = new ArrayList<>();
|
2017-09-20 16:20:52 +00:00
|
|
|
|
for(String path : bootClassPath.split(File.pathSeparator)) {
|
2017-09-20 13:52:14 +00:00
|
|
|
|
try {
|
|
|
|
|
librarys.add(new URL("file:"+path));
|
|
|
|
|
} catch (MalformedURLException e) {
|
|
|
|
|
new DebugException("Fehler im Classpath auf diesem System");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-20 15:26:09 +00:00
|
|
|
|
|
|
|
|
|
public JavaClassRegistry getRegistry(File forSourceFile) throws ClassNotFoundException, IOException {
|
|
|
|
|
List<String> allNames = new ArrayList<>();
|
|
|
|
|
CompilationUnitContext tree = JavaTXParser.parse(forSourceFile);
|
2017-09-20 16:20:52 +00:00
|
|
|
|
allNames = GatherNames.getNames(tree, new PackageCrawler(librarys));
|
|
|
|
|
return new JavaClassRegistry(allNames);
|
2017-09-20 15:26:09 +00:00
|
|
|
|
}
|
2017-09-20 13:52:14 +00:00
|
|
|
|
}
|