Fix #323
All checks were successful
Build and Test with Maven / Build-and-test-with-Maven (push) Successful in 3m14s

This commit is contained in:
Daniel Holle 2024-04-18 10:20:35 +02:00
parent b3bd5cde10
commit c21e5202d6
3 changed files with 42 additions and 32 deletions

View File

@ -133,20 +133,18 @@ public class JavaTXCompiler {
var recordClass = ASTFactory.createClass(Record.class); var recordClass = ASTFactory.createClass(Record.class);
allClasses.add(objectClass); allClasses.add(objectClass);
allClasses.add(recordClass); allClasses.add(recordClass);
// Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
for (Entry<File, SourceFile> source : sourceFiles.entrySet()) { var sf = sourceFiles.get(sourceFile);
var importedClasses = new ArrayList<ClassOrInterface>(); var importedClasses = new ArrayList<ClassOrInterface>();
for (JavaClassName name : source.getValue().getImports()) { for (JavaClassName name : sf.getImports()) {
importedClasses.addAll(getAvailableClasses(name)); importedClasses.addAll(getAvailableClasses(name));
} }
for (Class c : CompilationEnvironment.loadDefaultPackageClasses(source.getValue().getPkgName(), source.getKey(), this)) { for (Class c : CompilationEnvironment.loadDefaultPackageClasses(sf.getPkgName(), sourceFile, this)) {
ClassOrInterface importedClass = ASTFactory.createClass(c); ClassOrInterface importedClass = ASTFactory.createClass(c);
importedClasses.add(importedClass); importedClasses.add(importedClass);
} }
source.getValue().availableClasses.addAll(importedClasses); sf.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); 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 // sf enthaelt neues Source-File, neue Klassen-Objekte und neue
// ArrayListen-Objekte fuer Fields, Construktoren und Methoden // ArrayListen-Objekte fuer Fields, Construktoren und Methoden
@ -165,9 +163,10 @@ public class JavaTXCompiler {
sf_new.KlassenVektor.forEach(cl -> addMethods(sf_new, cl, sf.availableClasses, objectClass)); sf_new.KlassenVektor.forEach(cl -> addMethods(sf_new, cl, sf.availableClasses, objectClass));
allClasses.addAll(sf_new.getClasses()); allClasses.addAll(sf_new.getClasses());
} }
}
TYPE ty = new TYPE(sourceFiles.get(sourceFile), allClasses); allClasses.addAll(sf.KlassenVektor);
TYPE ty = new TYPE(sf, allClasses);
var constraints = ty.getConstraints(); var constraints = ty.getConstraints();
return constraints; return constraints;
} }

View File

@ -185,4 +185,16 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope {
return this.name.toString() + this.genericClassParameters.toString(); 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);
}
} }

View File

@ -26,7 +26,6 @@ public class TYPE {
public ConstraintSet getConstraints() { public ConstraintSet getConstraints() {
ConstraintSet ret = new ConstraintSet(); ConstraintSet ret = new ConstraintSet();
for (ClassOrInterface cl : sf.KlassenVektor) { for (ClassOrInterface cl : sf.KlassenVektor) {
System.out.println(sf.availableClasses);
var allClasses = new HashSet<ClassOrInterface>(); var allClasses = new HashSet<ClassOrInterface>();
allClasses.addAll(allAvailableClasses); allClasses.addAll(allAvailableClasses);
allClasses.addAll(sf.availableClasses); allClasses.addAll(sf.availableClasses);