diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index ce45dd53..7d284c22 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -133,41 +133,40 @@ public class JavaTXCompiler { var recordClass = ASTFactory.createClass(Record.class); allClasses.add(objectClass); allClasses.add(recordClass); - // Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC - for (Entry source : sourceFiles.entrySet()) { - var importedClasses = new ArrayList(); - for (JavaClassName name : source.getValue().getImports()) { - importedClasses.addAll(getAvailableClasses(name)); - } - for (Class c : CompilationEnvironment.loadDefaultPackageClasses(source.getValue().getPkgName(), source.getKey(), this)) { - ClassOrInterface importedClass = ASTFactory.createClass(c); - importedClasses.add(importedClass); - } - source.getValue().availableClasses.addAll(importedClasses); - } - for (File f : this.sourceFiles.keySet()) { - SourceFile sf = sourceFiles.get(f); - SourceFile sf_new = new SourceFile(sf.getPkgName(), sf.KlassenVektor.stream().map(cl -> new ClassOrInterface(cl)).collect(Collectors.toCollection(ArrayList::new)), sf.imports); - // sf enthaelt neues Source-File, neue Klassen-Objekte und neue - // ArrayListen-Objekte fuer Fields, Construktoren und Methoden - // Alle anderen Objekte werden nur kopiert. - var isCached = false; - for (var clazz : sf.availableClasses) { - if (loadedClasses.containsKey(clazz.getClassName())) { - allClasses.removeIf(cl -> cl.getClassName().equals(clazz.getClassName())); - var cif = loadedClasses.get(clazz.getClassName()).cif(); - allClasses.add(cif); - isCached = true; - } - } - if (!isCached) { - sf_new.KlassenVektor.forEach(cl -> addMethods(sf_new, cl, sf.availableClasses, objectClass)); - allClasses.addAll(sf_new.getClasses()); + var sf = sourceFiles.get(sourceFile); + var importedClasses = new ArrayList(); + for (JavaClassName name : sf.getImports()) { + importedClasses.addAll(getAvailableClasses(name)); + } + for (Class c : CompilationEnvironment.loadDefaultPackageClasses(sf.getPkgName(), sourceFile, this)) { + ClassOrInterface importedClass = ASTFactory.createClass(c); + importedClasses.add(importedClass); + } + sf.availableClasses.addAll(importedClasses); + + SourceFile sf_new = new SourceFile(sf.getPkgName(), sf.KlassenVektor.stream().map(cl -> new ClassOrInterface(cl)).collect(Collectors.toCollection(ArrayList::new)), sf.imports); + // sf enthaelt neues Source-File, neue Klassen-Objekte und neue + // ArrayListen-Objekte fuer Fields, Construktoren und Methoden + // Alle anderen Objekte werden nur kopiert. + var isCached = false; + for (var clazz : sf.availableClasses) { + if (loadedClasses.containsKey(clazz.getClassName())) { + allClasses.removeIf(cl -> cl.getClassName().equals(clazz.getClassName())); + var cif = loadedClasses.get(clazz.getClassName()).cif(); + allClasses.add(cif); + isCached = true; } } - TYPE ty = new TYPE(sourceFiles.get(sourceFile), allClasses); + if (!isCached) { + sf_new.KlassenVektor.forEach(cl -> addMethods(sf_new, cl, sf.availableClasses, objectClass)); + allClasses.addAll(sf_new.getClasses()); + } + + allClasses.addAll(sf.KlassenVektor); + + TYPE ty = new TYPE(sf, allClasses); var constraints = ty.getConstraints(); return constraints; } diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java b/src/main/java/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java index 6c348105..71240ae9 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java @@ -185,4 +185,16 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope { return this.name.toString() + this.genericClassParameters.toString(); } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ClassOrInterface that = (ClassOrInterface) o; + return Objects.equals(name, that.name); + } + + @Override + public int hashCode() { + return Objects.hash(name); + } } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java index 25be711b..c763cfef 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java @@ -26,7 +26,6 @@ public class TYPE { public ConstraintSet getConstraints() { ConstraintSet ret = new ConstraintSet(); for (ClassOrInterface cl : sf.KlassenVektor) { - System.out.println(sf.availableClasses); var allClasses = new HashSet(); allClasses.addAll(allAvailableClasses); allClasses.addAll(sf.availableClasses);