<commit_before>package org.metaborg.spoofax.core.analysis.constraint;

import org.metaborg.core.MetaborgException;
import org.metaborg.scopegraph.INameResolution;
import org.metaborg.scopegraph.IScopeGraph;
import org.metaborg.scopegraph.ScopeGraphException;
import org.metaborg.scopegraph.impl.NameResolution;
import org.metaborg.scopegraph.impl.ScopeGraph;
import org.spoofax.interpreter.core.Tools;
import org.spoofax.interpreter.terms.IStrategoAppl;
import org.spoofax.interpreter.terms.IStrategoTerm;

public class FinalResult {

    public final IStrategoTerm errors;
    public final IStrategoTerm warnings;
    public final IStrategoTerm notes;
    public final IScopeGraph scopeGraph;
    public final INameResolution nameResolution;
    public final IStrategoTerm analysis;
 
    public FinalResult(IStrategoTerm errors, IStrategoTerm warnings,
            IStrategoTerm notes, IScopeGraph scopeGraph,
            INameResolution nameResolution, IStrategoTerm analysis) {
        this.errors = errors;
        this.warnings = warnings;
        this.notes = notes;
        this.scopeGraph = scopeGraph;
        this.nameResolution = nameResolution;
        this.analysis = analysis;
    }

    public static FinalResult fromTerm(IStrategoTerm term) throws MetaborgException {
        if(!Tools.hasConstructor((IStrategoAppl)term, "FinalResult", 4)) {
            throw new MetaborgException("Wrong format for final result.");
        }
        IStrategoTerm analysis = term.getSubterm(3);
        IScopeGraph scopeGraph = null;
        INameResolution nameResolution = null;
        for(IStrategoTerm component : analysis) {
            if(Tools.hasConstructor((IStrategoAppl)component, "ScopeGraph", 1)) {
                scopeGraph = new ScopeGraph(component.getSubterm(0));
            }
            if(Tools.hasConstructor((IStrategoAppl)component, "NameResolution", 1)) {
                try {
                    nameResolution = new NameResolution(component.getSubterm(0));<commit_msg>Guard casts.<commit_after>package org.metaborg.spoofax.core.analysis.constraint;

import org.metaborg.core.MetaborgException;
import org.metaborg.scopegraph.INameResolution;
import org.metaborg.scopegraph.IScopeGraph;
import org.metaborg.scopegraph.ScopeGraphException;
import org.metaborg.scopegraph.impl.NameResolution;
import org.metaborg.scopegraph.impl.ScopeGraph;
import org.spoofax.interpreter.core.Tools;
import org.spoofax.interpreter.terms.IStrategoAppl;
import org.spoofax.interpreter.terms.IStrategoTerm;

public class FinalResult {

    public final IStrategoTerm errors;
    public final IStrategoTerm warnings;
    public final IStrategoTerm notes;
    public final IScopeGraph scopeGraph;
    public final INameResolution nameResolution;
    public final IStrategoTerm analysis;
 
    public FinalResult(IStrategoTerm errors, IStrategoTerm warnings,
            IStrategoTerm notes, IScopeGraph scopeGraph,
            INameResolution nameResolution, IStrategoTerm analysis) {
        this.errors = errors;
        this.warnings = warnings;
        this.notes = notes;
        this.scopeGraph = scopeGraph;
        this.nameResolution = nameResolution;
        this.analysis = analysis;
    }

    public static FinalResult fromTerm(IStrategoTerm term) throws MetaborgException {
        if(!(Tools.isTermAppl(term) && Tools.hasConstructor((IStrategoAppl)term, "FinalResult", 4))) {
            throw new MetaborgException("Wrong format for final result.");
        }
        IStrategoTerm analysis = term.getSubterm(3);
        IScopeGraph scopeGraph = null;
        INameResolution nameResolution = null;
        for(IStrategoTerm component : analysis) {
            if(Tools.isTermAppl(component) && Tools.hasConstructor((IStrategoAppl)component, "ScopeGraph", 1)) {
                scopeGraph = new ScopeGraph(component.getSubterm(0));
            }
            if(Tools.isTermAppl(component) && Tools.hasConstructor((IStrategoAppl)component, "NameResolution", 1)) {
                try {
                    nameResolution = new NameResolution(component.getSubterm(0));
{'fraction_non_alphanumeric': 0.0826203862136397, 'fraction_numerical': 0.0029332681495966755, 'mean_word_length': 3.5066079295154187, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3408781', 'n_tokens_mistral': 1210, 'n_tokens_neox': 1190, 'n_words': 231}