package de.bmoth.typechecker;

import de.bmoth.parser.Parser;
import de.bmoth.parser.ast.nodes.DeclarationNode;
import de.bmoth.parser.ast.nodes.FormulaNode;
import de.bmoth.parser.ast.nodes.MachineNode;

import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;

public class TestTypechecker {

    private final Hashtable<String, String> constants = new Hashtable<>();
    private final Hashtable<String, String> variables = new Hashtable<>();

    public TestTypechecker(String machine) {
        MachineNode semanticAst = Parser.getMachineAsSemanticAst(machine);

        List<DeclarationNode> constantsDecls = semanticAst.getConstants();
        for (DeclarationNode declarationNode : constantsDecls) {
            constants.put(declarationNode.getName(), declarationNode.getType().toString());

        }

        List<DeclarationNode> variablesDecls = semanticAst.getVariables();
        for (DeclarationNode declarationNode : variablesDecls) {
            variables.put(declarationNode.getName(), declarationNode.getType().toString());

        }
    }

    public static HashMap<String, String> getFormulaTypes(String formula) {
        FormulaNode formulaNode = Parser.getFormulaAsSemanticAst(formula);
        HashMap<String, String> map = new HashMap<>();
        for (DeclarationNode decl : formulaNode.getImplicitDeclarations()) {
            map.put(decl.getName(), decl.getType().toString());
        }
        return map;
    }

    public Hashtable<String, String> getConstants() {
        return constants;
    }

    public Hashtable<String, String> getVariables() {
        return variables;
    }
}

@@ -241,25 +241,20 @@
 va.util.
-Hashtable
+List
 ;%0Aimport
@@ -264,20 +264,19 @@
 va.util.
-List
+Map
 ;%0A%0Apubli
@@ -316,33 +316,27 @@
 ivate final 
-Hashtable
+Map
 %3CString, Str
@@ -356,29 +356,27 @@
 s = new Hash
-table
+Map
 %3C%3E();%0A    pr
@@ -387,25 +387,19 @@
 e final 
-Hashtable
+Map
 %3CString,
@@ -427,21 +427,19 @@
 new Hash
-table
+Map
 %3C%3E();%0A%0A 
@@ -1443,33 +1443,27 @@
 %0A    public 
-Hashtable
+Map
 %3CString, Str
@@ -1532,17 +1532,11 @@
 lic 
-Hashtable
+Map
 %3CStr

use hash map instead of hash table, switch to interface