This commit is contained in:
JanUlrich 2020-01-03 01:12:58 +01:00
parent 691d31df5e
commit abdff6c8d2
2 changed files with 12 additions and 8 deletions

View File

@ -88,22 +88,26 @@ public class JavaTXCompiler {
INSTANCE = this;
}
public ConstraintSet<Pair> getConstraints() throws ClassNotFoundException {
public ConstraintSet<Pair> getConstraints() throws ClassNotFoundException, IOException {
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
for (SourceFile sf : sourceFiles.values()) {
allClasses.addAll(sf.getClasses());
}
List<ClassOrInterface> importedClasses = new ArrayList<>();
//Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
for (File forSourceFile : sourceFiles.keySet())
for (File forSourceFile : sourceFiles.keySet()){
for (JavaClassName name : sourceFiles.get(forSourceFile).getImports()) {
//TODO: Hier werden imports von eigenen (.jav) Klassen nicht beachtet
ClassOrInterface importedClass = ASTFactory.createClass(
classLoader.loadClass(name.toString()));
importedClasses.add(importedClass);
}
for(Class c : CompilationEnvironment.loadDefaultPackageClasses(forSourceFile, classLoader)){
ClassOrInterface importedClass = ASTFactory.createClass(c);
importedClasses.add(importedClass);
}
}
allClasses.addAll(importedClasses);
return new TYPE(sourceFiles.values(), allClasses).getConstraints();
}
@ -289,7 +293,7 @@ public class JavaTXCompiler {
*/
public UnifyResultModel typeInferenceAsync(UnifyResultListener resultListener, Writer logFile)
throws ClassNotFoundException {
throws ClassNotFoundException, IOException {
List<ClassOrInterface> allClasses = new ArrayList<>();// environment.getAllAvailableClasses();
// Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
for (SourceFile sf : this.sourceFiles.values()) {
@ -457,7 +461,7 @@ public class JavaTXCompiler {
return urm;
}
public List<ResultSet> typeInference() throws ClassNotFoundException {
public List<ResultSet> typeInference() throws ClassNotFoundException, IOException {
List<ClassOrInterface> allClasses = new ArrayList<>();// environment.getAllAvailableClasses();
// Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
for (SourceFile sf : this.sourceFiles.values()) {
@ -743,7 +747,7 @@ public class JavaTXCompiler {
public List<GenericGenratorResultForSourceFile> getGeneratedGenericResultsForAllSourceFiles()
throws ClassNotFoundException {
throws ClassNotFoundException, IOException {
List<GenericGenratorResultForSourceFile> result = new ArrayList<>();
for (File f : sourceFiles.keySet()) {
SourceFile sf = sourceFiles.get(f);

View File

@ -79,7 +79,7 @@ public class CompilationEnvironment {
return new JavaClassRegistry(allNames);
}
public List<Class> loadDefaultPackageClasses(File forSourceFile, ClassLoader classLoader) throws IOException, ClassNotFoundException {
public static List<Class> loadDefaultPackageClasses(File forSourceFile, ClassLoader classLoader) throws IOException, ClassNotFoundException {
List<Class> ret = new ArrayList<>();
String packageName = getPackageName(JavaTXParser.parse(forSourceFile));
//Set classLoader to include default package for this specific source file
@ -96,7 +96,7 @@ public class CompilationEnvironment {
return ret;
}
private String getPackageName(CompilationUnitContext forTree){
private static String getPackageName(CompilationUnitContext forTree){
String packageName = "";
for(TerminalNode subPackage : forTree.packageDeclaration().Identifier()){
packageName += subPackage.toString() + ".";