package utils.staticResults;

import soot.*;
import soot.jimple.Stmt;
import utils.staticResults.implementation.Dynamic;
import utils.staticResults.implementation.Public;
import utils.staticResults.implementation.Types;

import java.util.Collection;

/**
 * A Helper that fills the var, cx and instantiation maps with the approprioate typings
 */
public class ResultsServer {


    // ======================= SET VAR TYPING ==========================
    public static void setDynamic(MSLMap<BeforeAfterContainer> mslMap, Collection<String> allClasses) {
        for (String s : allClasses) {
            SootClass sootClass = Scene.v().loadClassAndSupport(s);
            sootClass.setApplicationClass();

            for (SootMethod sm : sootClass.getMethods()) {
                Body b = sootClass.getMethodByName(sm.getName()).retrieveActiveBody();
                for (Unit u: b.getUnits()) {
                    Stmt stmt = (Stmt) u;
                    for (Local l: b.getLocals()) {
                        BeforeAfterContainer tmp = new BeforeAfterContainer<>(new Dynamic<>(), new Dynamic<>());
                        mslMap.put(sm, stmt, l, tmp);
                    }
                }
            }
        }
    }

    public static void setPublic(MSLMap<BeforeAfterContainer> mslMap, Collection<String> allClasses) {
        for (String s : allClasses) {
            SootClass sootClass = Scene.v().loadClassAndSupport(s);
            sootClass.setApplicationClass();

            for (SootMethod sm : sootClass.getMethods()) {
                Body b = sootClass.getMethodByName(sm.getName()).retrieveActiveBody();
                for (Unit u: b.getUnits()) {
                    Stmt stmt = (Stmt) u;
                    for (Local l: b.getLocals()) {
                        mslMap.put(sm, stmt, l, new BeforeAfterContainer<>(new Public<>(), new Public<>()));
                    }
                }
            }
        }
    }


    // ========================= SET CX / Instantiation ===========================
    public static void setDynamic(MSMap<Types> msMap, Collection<String> allClasses) {
        for (String s : allClasses) {
            SootClass sootClass = Scene.v().loadClassAndSupport(s);
            sootClass.setApplicationClass();

            for (SootMethod sm : sootClass.getMethods()) {
                Body b = sootClass.getMethodByName(sm.getName()).retrieveActiveBody();
                for (Unit u: b.getUnits()) {
                    Stmt stmt = (Stmt) u;
                    msMap.put(sm, stmt, new Dynamic<>());
                }
            }
        }
    }

    public static void setPublic(MSMap<Types> msMap, Collection<String> allClasses) {
        for (String s : allClasses) {
            SootClass sootClass = Scene.v().loadClassAndSupport(s);
            sootClass.setApplicationClass();

            for (SootMethod sm : sootClass.getMethods()) {
                Body b = sootClass.getMethodByName(sm.getName()).retrieveActiveBody();
                for (Unit u: b.getUnits()) {
                    Stmt stmt = (Stmt) u;
                    msMap.put(sm, stmt, new Public<>());
                }
            }
        }
    }
}

@@ -435,32 +435,280 @@
 ================
+%0A%0A    /**%0A     * Creates a mapping (methods, statements and variables) =%3E (Dynamic, Dynamic)%0A     * @param mslMap            Map to fill%0A     * @param allClasses        Collection of Strings specifying the soot classes that contain the keys%0A     */
 %0A    public stat
@@ -1462,32 +1462,277 @@
        %7D%0A    %7D%0A%0A
+    /**%0A     * Creates a mapping (methods, statements and variables) =%3E (Public, Public)%0A     * @param mslMap            Map to fill%0A     * @param allClasses        Collection of Strings specifying the soot classes that contain the keys%0A     */%0A
     public stati
@@ -2519,16 +2519,237 @@
 =======%0A
+    /**%0A     * Creates a mapping (methods, statements) =%3E Dynamic%0A     * @param msMap            Map to fill%0A     * @param allClasses        Collection of Strings specifying the soot classes that contain the keys%0A     */%0A
     publ
@@ -3314,24 +3314,243 @@
     %7D%0A    %7D%0A
+    /**%0A     * Creates a mapping (methods, statements) =%3E Public%0A     * @param msMap            Map to fill%0A     * @param allClasses        Collection of Strings specifying the soot classes that contain the keys%0A     */
 %0A    public 

add javadoc