import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.typedeployment.TypeInsert;
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.nio.file.Path;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class TestTypeDeployment {

    @Test
    public void testTypeDeployment() throws Exception {
        var path = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Cycle.jav");
        var file = path.toFile();
        var compiler = new JavaTXCompiler(file);
        compiler.parseAll();
        var parsedSource = compiler.sourceFiles.get(file);
        var tiResults = compiler.typeInference(file);
        Set<TypeInsert> tips = new HashSet<>();

        System.out.println(compiler.getGeneratedGenerics());

        for (int i = 0; i < tiResults.size(); i++) {
            ResultSet tiResult = tiResults.get(i);
            tips.addAll(TypeInsertFactory.createTypeInsertPoints(parsedSource, tiResult, compiler.getGeneratedGenerics().get(compiler.sourceFiles.get(file)).get(i)));
            for (TypeInsert p : tips) {
                System.out.println(p);
            }
        }
    }
}
