<commit_before>package org.mvel;

import org.mvel.integration.Interceptor;
import org.mvel.ast.LineLabel;

import java.util.*;
import java.io.Serializable;
import java.lang.reflect.Method;

/**
 * The ParserContext is the main enviroment object used for sharing state throughout the entire
 * parser/compile process.
 */
public class ParserContext implements Serializable {
    private String sourceFile;

    private int lineCount = 1;
    private int lineOffset;

    protected Map<String, Object> imports;
    protected Set<String> packageImports;

    protected Map<String, Interceptor> interceptors;

    private Map<String, Class> variables;
    private Map<String, Class> inputs;

    private List<ErrorDetail> errorList;

    private Map<String, Set<Integer>> sourceMap;
    private LineLabel firstLineLabel;

    private Object rootParser;

    private boolean compiled = false;
    private boolean strictTypeEnforcement = false;
    private boolean fatalError = false;
    private boolean retainParserState = false;
    private boolean debugSymbols = false;

    public ParserContext() {
    }

    public ParserContext(boolean debugSymbols) {
        this.debugSymbols = debugSymbols;
    }

    public ParserContext(Object rootParser) {
        this.rootParser = rootParser;
    }

    public ParserContext(Map<String, Object> imports, Map<String, Interceptor> interceptors, String sourceFile) {
        this.imports = imports;
        this.interceptors = interceptors;
        this.sourceFile = sourceFile;
    }

    public boolean hasVarOrInput(String name) {
        return (variables != null && variables.containsKey(name))
                || (inputs != null && inputs.containsKey(name));
    }

    public Class getVarOrInputType(String name) {
        if (variables != null && variables.containsKey(name)) {
            return variables.get(name);
        }
        else if (inputs != null && inputs.containsKey(name)) {
            return inputs.get(name);
        }
        return Object.class;
    }


    public int getLineCount() {
        return lineCount;
    }

    public void setLineCount(int lineCount) {
        this.lineCount = lineCount;
    }

    public int getLineOffset() {
        return lineOffset;
    }

    public void setLineOffset(int lineOffset) {
        this.lineOffset = lineOffset;
    }

    public void setLineAndOffset(int lineCount, int lineOffset) {
        this.lineCount = lineCount;
        this.lineOffset = lineOffset;
    }

    public Class getImport(String name) {
        return (imports != null && imports.containsKey(name) ? (Class) imports.get(name) : (Class) AbstractParser.LITERALS.get(name));
    }

    public Method getStaticImport(String name) {
        return imports != null ? (Method) imports.get(name) : null;
    }

    public void addPackageImport(String packageName) {
        if (packageImports == null) packageImports = new HashSet<String>();
        packageImports.add(packageName);
    }

    private boolean checkForDynamicImport(String className) {
        if (packageImports == null) return false;

        int found = 0;
        Class cls = null;
        for (String pkg : packageImports) {
            try {
                cls = Class.forName(pkg + "." + className);
                found++;
            }
            catch (ClassNotFoundException e) {
                // do nothing.
            }
        }

        if (found > 1) {
            throw new CompileException("ambiguous class name: " + className);
        }
        else if (found == 1) {
            addImport(className, cls);
            return true;
        }
        else {
            return false;
        }
    }


    public boolean hasImport(String name) {
        return (imports != null && imports.containsKey(name)) || (!"this".equals(name) && AbstractParser.LITERALS.containsKey(name))
                || checkForDynamicImport(name);
    }

    public void addImport(String name, Class cls) {
        if (this.imports == null) this.imports = new HashMap<String, Object>();
        this.imports.put(name, cls);
    }

    public void addImport(String name, Method method) {
        if (this.imports == null) this.imports = new HashMap<String, Object>();
        this.imports.put(name, method);
    }

    public void initializeTables() {
        if (variables == null) variables = new HashMap<String, Class>();
        if (inputs == null) inputs = new HashMap<String, Class>();
    }

    public void addVariable(String name, Class type) {
        if (variables.containsKey(name)) return;
        if (type == null) type = Object.class;
        variables.put(name, type);<commit_msg>bug fix<commit_after>package org.mvel;

import org.mvel.integration.Interceptor;
import org.mvel.ast.LineLabel;

import java.util.*;
import java.io.Serializable;
import java.lang.reflect.Method;

/**
 * The ParserContext is the main enviroment object used for sharing state throughout the entire
 * parser/compile process.
 */
public class ParserContext implements Serializable {
    private String sourceFile;

    private int lineCount = 1;
    private int lineOffset;

    protected Map<String, Object> imports;
    protected Set<String> packageImports;

    protected Map<String, Interceptor> interceptors;

    private Map<String, Class> variables;
    private Map<String, Class> inputs;

    private List<ErrorDetail> errorList;

    private Map<String, Set<Integer>> sourceMap;
    private LineLabel firstLineLabel;

    private Object rootParser;

    private boolean compiled = false;
    private boolean strictTypeEnforcement = false;
    private boolean fatalError = false;
    private boolean retainParserState = false;
    private boolean debugSymbols = false;

    public ParserContext() {
    }

    public ParserContext(boolean debugSymbols) {
        this.debugSymbols = debugSymbols;
    }

    public ParserContext(Object rootParser) {
        this.rootParser = rootParser;
    }

    public ParserContext(Map<String, Object> imports, Map<String, Interceptor> interceptors, String sourceFile) {
        this.imports = imports;
        this.interceptors = interceptors;
        this.sourceFile = sourceFile;
    }

    public boolean hasVarOrInput(String name) {
        return (variables != null && variables.containsKey(name))
                || (inputs != null && inputs.containsKey(name));
    }

    public Class getVarOrInputType(String name) {
        if (variables != null && variables.containsKey(name)) {
            return variables.get(name);
        }
        else if (inputs != null && inputs.containsKey(name)) {
            return inputs.get(name);
        }
        return Object.class;
    }


    public int getLineCount() {
        return lineCount;
    }

    public void setLineCount(int lineCount) {
        this.lineCount = lineCount;
    }

    public int getLineOffset() {
        return lineOffset;
    }

    public void setLineOffset(int lineOffset) {
        this.lineOffset = lineOffset;
    }

    public void setLineAndOffset(int lineCount, int lineOffset) {
        this.lineCount = lineCount;
        this.lineOffset = lineOffset;
    }

    public Class getImport(String name) {
        return (imports != null && imports.containsKey(name) ? (Class) imports.get(name) : (Class) AbstractParser.LITERALS.get(name));
    }

    public Method getStaticImport(String name) {
        return imports != null ? (Method) imports.get(name) : null;
    }

    public void addPackageImport(String packageName) {
        if (packageImports == null) packageImports = new HashSet<String>();
        packageImports.add(packageName);
    }

    private boolean checkForDynamicImport(String className) {
        if (packageImports == null) return false;

        int found = 0;
        Class cls = null;
        for (String pkg : packageImports) {
            try {
                cls = Class.forName(pkg + "." + className);
                found++;
            }
            catch (ClassNotFoundException e) {
                // do nothing.
            }
        }

        if (found > 1) {
            throw new CompileException("ambiguous class name: " + className);
        }
        else if (found == 1) {
            addImport(className, cls);
            return true;
        }
        else {
            return false;
        }
    }


    public boolean hasImport(String name) {
        return (imports != null && imports.containsKey(name)) || (!"this".equals(name) && !"self".equals(name) && !"empty".equals(name)
            && AbstractParser.LITERALS.containsKey(name))
                || checkForDynamicImport(name);
    }

    public void addImport(String name, Class cls) {
        if (this.imports == null) this.imports = new HashMap<String, Object>();
        this.imports.put(name, cls);
    }

    public void addImport(String name, Method method) {
        if (this.imports == null) this.imports = new HashMap<String, Object>();
        this.imports.put(name, method);
    }

    public void initializeTables() {
        if (variables == null) variables = new HashMap<String, Class>();
        if (inputs == null) inputs = new HashMap<String, Class>();
    }

    public void addVariable(String name, Class type) {
        if (variables.containsKey(name)) return;
        if (type == null) type = Object.class;
        variables.put(name, type);
{'fraction_non_alphanumeric': 0.10182907262808856, 'fraction_numerical': 0.0008557064926730132, 'mean_word_length': 2.5203313253012047, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 35, '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': '661606', 'n_tokens_mistral': 2582, 'n_tokens_neox': 2487, 'n_words': 682}