<commit_before>package polyglot.ext.jl5.types.inference;

import java.util.*;

import com.sun.codemodel.internal.ClassType;

import polyglot.ext.jl5.types.*;
import polyglot.frontend.Job;
import polyglot.types.*;
import polyglot.types.Package;
import polyglot.util.CollectionUtil;
import polyglot.util.InternalCompilerError;
import polyglot.util.Position;


public class LubType_c extends ClassType_c implements LubType {

    protected List<ReferenceType> lubElems;
    public LubType_c(TypeSystem ts, Position pos, List<ReferenceType> lubElems) {
        super(ts, pos);
        this.lubElems = lubElems;
    }

    public List<ReferenceType> lubElements() {
        return lubElems;
    }
    
    protected Type lubCalculated = null;
    public Type calculateLub() {
        if (lubCalculated == null) {
            lubCalculated = lub_force();
        }
        return lubCalculated;
    }
    
//    @Override
//    public List<ReferenceType> bounds() {
//        return calculateLub().bounds();
//    }

    @Override
    public Kind kind() {
        return LUB;
    }

    
    private ReferenceType lub(Type... a) {
        List<ReferenceType> l = new ArrayList<ReferenceType>();
        for (Type t : a) {
            l.add((ReferenceType) t);
        }
        JL5TypeSystem ts = (JL5TypeSystem)this.ts;
        return ts.lub(this.position, l);
    }

    private Type lub_force() {
        JL5TypeSystem ts = (JL5TypeSystem)this.ts;
        Set<Type> st = new HashSet<Type>();
        Set<Type> est = null;
        for (Type u : lubElems) {
            List<Type> u_supers = new ArrayList<Type>(ts.allAncestorsOf((ReferenceType) u));
            st.addAll(u_supers);
            Set<Type> est_of_u = new HashSet<Type>();
            for (Type super_of_u : u_supers) {
                if (super_of_u instanceof JL5SubstClassType) {
                    JL5SubstClassType g = (JL5SubstClassType) super_of_u;
                    est_of_u.add(g.base());
                }
                else est_of_u.add(super_of_u);
            }
            if (est == null) {
                est = new HashSet<Type>();
                est.addAll(est_of_u);
            }<commit_msg>Use the erased version of raw classes in finding the lub.<commit_after>package polyglot.ext.jl5.types.inference;

import java.util.*;

import com.sun.codemodel.internal.ClassType;

import polyglot.ext.jl5.types.*;
import polyglot.frontend.Job;
import polyglot.types.*;
import polyglot.types.Package;
import polyglot.util.CollectionUtil;
import polyglot.util.InternalCompilerError;
import polyglot.util.Position;


public class LubType_c extends ClassType_c implements LubType {

    protected List<ReferenceType> lubElems;
    public LubType_c(TypeSystem ts, Position pos, List<ReferenceType> lubElems) {
        super(ts, pos);  
        // replace any raw classes with the erased version of the raw class.
        List<ReferenceType> l = null;
        for (int i = 0; i < lubElems.size(); i++) {
            ReferenceType t = lubElems.get(i);
            if (t instanceof RawClass) {
                t = ((RawClass)t).erased();
               if (l == null) {
                   l = new ArrayList<ReferenceType>(lubElems);                   
               }
               l.set(i, t);
            }
        }
        if (l == null) {
            l = lubElems;
        }
        this.lubElems = l;
    }

    public List<ReferenceType> lubElements() {
        return lubElems;
    }
    
    protected Type lubCalculated = null;
    public Type calculateLub() {
        if (lubCalculated == null) {
            lubCalculated = lub_force();
        }
        return lubCalculated;
    }
    
//    @Override
//    public List<ReferenceType> bounds() {
//        return calculateLub().bounds();
//    }

    @Override
    public Kind kind() {
        return LUB;
    }

    
    private ReferenceType lub(Type... a) {
        List<ReferenceType> l = new ArrayList<ReferenceType>();
        JL5TypeSystem ts = (JL5TypeSystem)this.ts;
        for (Type t : a) {
            l.add((ReferenceType) t);
        }
        return ts.lub(this.position, l);
    }

    private Type lub_force() {
        JL5TypeSystem ts = (JL5TypeSystem)this.ts;
        Set<Type> st = new HashSet<Type>();
        Set<Type> est = null;
        for (Type u : lubElems) {
            List<Type> u_supers = new ArrayList<Type>(ts.allAncestorsOf((ReferenceType) u));
            st.addAll(u_supers);
            Set<Type> est_of_u = new HashSet<Type>();
            for (Type super_of_u : u_supers) {
                if (super_of_u instanceof JL5SubstClassType) {
                    JL5SubstClassType g = (JL5SubstClassType) super_of_u;
                    est_of_u.add(g.base());
                }
                else est_of_u.add(super_of_u);
            }
            if (est == null) {
                est = new HashSet<Type>();
                est.addAll(est_of_u);
            }
{'fraction_non_alphanumeric': 0.1094003241491086, 'fraction_numerical': 0.0038492706645056724, 'mean_word_length': 1.981280193236715, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 33, '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': '5102168', 'n_tokens_mistral': 1579, 'n_tokens_neox': 1518, 'n_words': 336}