<commit_before>package com.redhat.ceylon.compiler.java.runtime.model;

import java.util.ArrayList;
import java.util.List;

import ceylon.language.Anything;
import ceylon.language.AssertionException;
import ceylon.language.Basic;
import ceylon.language.Identifiable;
import ceylon.language.Null;

import com.redhat.ceylon.compiler.loader.ModelLoader.DeclarationType;
import com.redhat.ceylon.compiler.typechecker.model.IntersectionType;
import com.redhat.ceylon.compiler.typechecker.model.Module;
import com.redhat.ceylon.compiler.typechecker.model.NothingType;
import com.redhat.ceylon.compiler.typechecker.model.ProducedType;
import com.redhat.ceylon.compiler.typechecker.model.TypeDeclaration;
import com.redhat.ceylon.compiler.typechecker.model.UnionType;
import com.redhat.ceylon.compiler.typechecker.model.Unit;
import com.redhat.ceylon.compiler.typechecker.model.Util;

public abstract class TypeDescriptor {

    public static final TypeDescriptor NothingType = new Nothing();

    //
    // Methods

    public abstract ProducedType toProducedType(RuntimeModuleManager moduleManager);
    
    public abstract java.lang.Class<?> getArrayElementClass();
    
    
    public abstract boolean containsNull();
	

    //
    // Subtypes
    
    public static class Class extends TypeDescriptor {
        private java.lang.Class<?> klass;
        private TypeDescriptor[] typeArguments;

        public Class(java.lang.Class<?> klass, TypeDescriptor[] typeArguments){
            this.klass = klass;
            this.typeArguments = typeArguments;
        }

        public java.lang.Class<?> getKlass() {
            return klass;
        }

        public TypeDescriptor[] getTypeArguments() {
            return typeArguments;
        }

        @Override
        public boolean equals(Object obj) {
            if(this == obj)
                return true;
            if(obj == null || obj instanceof Class == false)
                return false;
            Class other = (Class) obj;
            if(klass != other.klass)
                return false;
            if(typeArguments.length != other.typeArguments.length)
                return false;
            for(int i=0;i<typeArguments.length;i++){
                if(!typeArguments[i].equals(other.typeArguments[i]))
                    return false;
            }
            return true;
        }
        
        @Override
        public String toString() {
            StringBuilder b = new StringBuilder();
            b.append(klass);
            if(typeArguments.length > 0){
                b.append("<");
                for(int i=0;i<typeArguments.length;i++){
                    if(i>0)
                        b.append(",");
                    b.append(typeArguments[i]);
                }
                b.append(">");
            }
            return b.toString();
        }

        @Override
        public ProducedType toProducedType(RuntimeModuleManager moduleManager){
            return toProducedType(null, moduleManager);
        }
        
        public ProducedType toProducedType(ProducedType qualifyingType, RuntimeModuleManager moduleManager){
            // FIXME: is this really enough?
            String typeName = klass.getName();
            Module module = moduleManager.findModuleForClass(klass);
            TypeDeclaration decl = (TypeDeclaration) moduleManager.getModelLoader().getDeclaration(module, typeName, DeclarationType.TYPE);
            List<ProducedType> typeArgs = new ArrayList<ProducedType>(typeArguments.length);
            for(TypeDescriptor typeArg : typeArguments){
                typeArgs.add(typeArg.toProducedType(moduleManager));
            }
            return decl.getProducedType(qualifyingType, typeArgs);
        }

		@Override
        public java.lang.Class<?> getArrayElementClass() {
			if (klass==Null.class ||
				klass==Object.class ||
				klass==Anything.class ||
				klass==Basic.class ||
				klass==Identifiable.class) {
				return java.lang.Object.class;
			}
			if (klass==Exception.class) {
				return java.lang.Throwable.class;
			}
	        return klass;
        }

		@Override
        public boolean containsNull() {
	        return klass==Null.class;
        }
    }

    public static class Member extends TypeDescriptor {

        private TypeDescriptor container;
        private TypeDescriptor member;

        public Member(TypeDescriptor container, TypeDescriptor member) {
            this.member = member;
            this.container = container;
        }

        public TypeDescriptor getContainer() {
            return container;
        }

        public TypeDescriptor getMember() {
            return member;
        }
        
        @Override
        public boolean equals(Object obj) {<commit_msg>more special cases (Java arrays)<commit_after>package com.redhat.ceylon.compiler.java.runtime.model;

import java.util.ArrayList;
import java.util.List;

import ceylon.language.Anything;
import ceylon.language.AssertionException;
import ceylon.language.Basic;
import ceylon.language.Identifiable;
import ceylon.language.Null;

import com.redhat.ceylon.compiler.java.language.BooleanArray;
import com.redhat.ceylon.compiler.java.language.ByteArray;
import com.redhat.ceylon.compiler.java.language.CharArray;
import com.redhat.ceylon.compiler.java.language.DoubleArray;
import com.redhat.ceylon.compiler.java.language.FloatArray;
import com.redhat.ceylon.compiler.java.language.IntArray;
import com.redhat.ceylon.compiler.java.language.LongArray;
import com.redhat.ceylon.compiler.java.language.ObjectArray;
import com.redhat.ceylon.compiler.java.language.ShortArray;
import com.redhat.ceylon.compiler.loader.ModelLoader.DeclarationType;
import com.redhat.ceylon.compiler.typechecker.model.IntersectionType;
import com.redhat.ceylon.compiler.typechecker.model.Module;
import com.redhat.ceylon.compiler.typechecker.model.NothingType;
import com.redhat.ceylon.compiler.typechecker.model.ProducedType;
import com.redhat.ceylon.compiler.typechecker.model.TypeDeclaration;
import com.redhat.ceylon.compiler.typechecker.model.UnionType;
import com.redhat.ceylon.compiler.typechecker.model.Unit;
import com.redhat.ceylon.compiler.typechecker.model.Util;

public abstract class TypeDescriptor {

    public static final TypeDescriptor NothingType = new Nothing();

    //
    // Methods

    public abstract ProducedType toProducedType(RuntimeModuleManager moduleManager);
    
    public abstract java.lang.Class<?> getArrayElementClass();
    
    
    public abstract boolean containsNull();
	

    //
    // Subtypes
    
    public static class Class extends TypeDescriptor {
        private java.lang.Class<?> klass;
        private TypeDescriptor[] typeArguments;

        public Class(java.lang.Class<?> klass, TypeDescriptor[] typeArguments){
            this.klass = klass;
            this.typeArguments = typeArguments;
        }

        public java.lang.Class<?> getKlass() {
            return klass;
        }

        public TypeDescriptor[] getTypeArguments() {
            return typeArguments;
        }

        @Override
        public boolean equals(Object obj) {
            if(this == obj)
                return true;
            if(obj == null || obj instanceof Class == false)
                return false;
            Class other = (Class) obj;
            if(klass != other.klass)
                return false;
            if(typeArguments.length != other.typeArguments.length)
                return false;
            for(int i=0;i<typeArguments.length;i++){
                if(!typeArguments[i].equals(other.typeArguments[i]))
                    return false;
            }
            return true;
        }
        
        @Override
        public String toString() {
            StringBuilder b = new StringBuilder();
            b.append(klass);
            if(typeArguments.length > 0){
                b.append("<");
                for(int i=0;i<typeArguments.length;i++){
                    if(i>0)
                        b.append(",");
                    b.append(typeArguments[i]);
                }
                b.append(">");
            }
            return b.toString();
        }

        @Override
        public ProducedType toProducedType(RuntimeModuleManager moduleManager){
            return toProducedType(null, moduleManager);
        }
        
        public ProducedType toProducedType(ProducedType qualifyingType, RuntimeModuleManager moduleManager){
            // FIXME: is this really enough?
            String typeName = klass.getName();
            Module module = moduleManager.findModuleForClass(klass);
            TypeDeclaration decl = (TypeDeclaration) moduleManager.getModelLoader().getDeclaration(module, typeName, DeclarationType.TYPE);
            List<ProducedType> typeArgs = new ArrayList<ProducedType>(typeArguments.length);
            for(TypeDescriptor typeArg : typeArguments){
                typeArgs.add(typeArg.toProducedType(moduleManager));
            }
            return decl.getProducedType(qualifyingType, typeArgs);
        }

		@Override
        public java.lang.Class<?> getArrayElementClass() {
			if (klass==Null.class ||
				klass==Object.class ||
				klass==Anything.class ||
				klass==Basic.class ||
				klass==Identifiable.class) {
				return java.lang.Object.class;
			}
			if (klass==Exception.class) {
				return java.lang.Throwable.class;
			}
			if (klass==ObjectArray.class) {
				return java.lang.Object[].class;
			}
			if (klass==BooleanArray.class) {
				return boolean[].class;
			}
			if (klass==LongArray.class) {
				return long[].class;
			}
			if (klass==IntArray.class) {
				return int[].class;
			}
			if (klass==ShortArray.class) {
				return short[].class;
			}
			if (klass==ByteArray.class) {
				return byte[].class;
			}
			if (klass==DoubleArray.class) {
				return double[].class;
			}
			if (klass==FloatArray.class) {
				return float[].class;
			}
			if (klass==CharArray.class) {
				return char[].class;
			}
	        return klass;
        }

		@Override
        public boolean containsNull() {
	        return klass==Null.class;
        }
    }

    public static class Member extends TypeDescriptor {

        private TypeDescriptor container;
        private TypeDescriptor member;

        public Member(TypeDescriptor container, TypeDescriptor member) {
            this.member = member;
            this.container = container;
        }

        public TypeDescriptor getContainer() {
            return container;
        }

        public TypeDescriptor getMember() {
            return member;
        }
        
        @Override
        public boolean equals(Object obj) {
{'fraction_non_alphanumeric': 0.09957884885353299, 'fraction_numerical': 0.0007487131492746841, 'mean_word_length': 2.330009348706762, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '4046675', 'n_tokens_mistral': 2964, 'n_tokens_neox': 2818, 'n_words': 556}