<commit_before>package dk.aau.sw402F15.TypeChecker.Symboltable;

import dk.aau.sw402F15.TypeChecker.Exceptions.ScopeNotFoundException;
import dk.aau.sw402F15.TypeChecker.Exceptions.SymbolAlreadyExistsException;
import dk.aau.sw402F15.TypeChecker.Exceptions.SymbolNotFoundException;
import dk.aau.sw402F15.parser.node.Node;

import java.util.*;

public class Scope {
    private Dictionary<String, Symbol> symbols;
    private List<Scope> scopes;
    private Scope parentScope;
    private Node node;

    public Scope(Scope parentScope, Node node) {
        this.node = node;
        this.symbols = new Hashtable<String, Symbol>();
        this.scopes = new ArrayList<Scope>();
        this.parentScope = parentScope;
    }

    public List<Symbol> toList(){
        Enumeration<Symbol> enumeration = symbols.elements();
        List<Symbol> result = new ArrayList<Symbol>(symbols.size());
        while(enumeration.hasMoreElements())
        {
            Symbol symbol = enumeration.nextElement();
            result.add(symbol);
        }
        return result;
    }

    public void addSymbol(Symbol symbol) {
        if (getSymbol(symbol.getName()) != null) {
            throw new SymbolAlreadyExistsException();
        }

        symbols.put(symbol.getName(), symbol);
    }

    public Scope addSubScope(Node node) {
        Scope scope = new Scope(this, node);
        scopes.add(scope);
        return scope;
    }

    public Symbol getSymbol(String name) {
        Symbol symbol = symbols.get(name);
        if (symbol != null)
            return symbol;

        Scope scope = getParentScope();
        if (scope != null)
            return scope.getSymbol(name);

        return null;
    }

    public Symbol getSymbolOrThrow(String name) {
        Symbol symbol = getSymbol(name);

        if (symbol == null)
            throw new SymbolNotFoundException();

        return symbol;
    }

    public Scope getSubScopeByNode(Node node) {
        for (Scope scope : scopes) {
            if (scope.getNode() == node)
                return scope;
        }

        return null;
    }

    public Scope getSubScopeByNodeOrThrow(Node node){
        Scope scope = getSubScopeByNode(node);

        if (scope == null)
            throw new ScopeNotFoundException();

        return scope;
    }

    public Scope getParentScope() {
        return parentScope;
    }

    public Node getNode() {
        return node;
    }
}
<commit_msg>Added clear symbols to scope<commit_after>package dk.aau.sw402F15.TypeChecker.Symboltable;

import dk.aau.sw402F15.TypeChecker.Exceptions.ScopeNotFoundException;
import dk.aau.sw402F15.TypeChecker.Exceptions.SymbolAlreadyExistsException;
import dk.aau.sw402F15.TypeChecker.Exceptions.SymbolNotFoundException;
import dk.aau.sw402F15.parser.node.Node;

import java.util.*;

public class Scope {
    private Hashtable<String, Symbol> symbols;
    private ArrayList<Scope> scopes;
    private Scope parentScope;
    private Node node;

    public Scope(Scope parentScope, Node node) {
        this.node = node;
        this.symbols = new Hashtable<String, Symbol>();
        this.scopes = new ArrayList<Scope>();
        this.parentScope = parentScope;
    }

    public List<Symbol> toList(){
        Enumeration<Symbol> enumeration = symbols.elements();
        List<Symbol> result = new ArrayList<Symbol>(symbols.size());
        while(enumeration.hasMoreElements())
        {
            Symbol symbol = enumeration.nextElement();
            result.add(symbol);
        }
        return result;
    }

    public void addSymbol(Symbol symbol) {
        if (getSymbol(symbol.getName()) != null) {
            throw new SymbolAlreadyExistsException();
        }

        symbols.put(symbol.getName(), symbol);
    }

    public Scope addSubScope(Node node) {
        Scope scope = new Scope(this, node);
        scopes.add(scope);
        return scope;
    }

    public Symbol getSymbol(String name) {
        Symbol symbol = symbols.get(name);
        if (symbol != null)
            return symbol;

        Scope scope = getParentScope();
        if (scope != null)
            return scope.getSymbol(name);

        return null;
    }

    public Symbol getSymbolOrThrow(String name) {
        Symbol symbol = getSymbol(name);

        if (symbol == null)
            throw new SymbolNotFoundException();

        return symbol;
    }

    public Scope getSubScopeByNode(Node node) {
        for (Scope scope : scopes) {
            if (scope.getNode() == node)
                return scope;
        }

        return null;
    }

    public Scope getSubScopeByNodeOrThrow(Node node){
        Scope scope = getSubScopeByNode(node);

        if (scope == null)
            throw new ScopeNotFoundException();

        return scope;
    }

    public Scope getParentScope() {
        return parentScope;
    }

    public Node getNode() {
        return node;
    }

    public void clearSymbols() {
        this.symbols.clear();
    }
}

{'fraction_non_alphanumeric': 0.09841651633593906, 'fraction_numerical': 0.010022048506714773, 'mean_word_length': 2.3311081441922563, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2140704', 'n_tokens_mistral': 1455, 'n_tokens_neox': 1379, 'n_words': 332}