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

import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import ceylon.language.Anything;
import ceylon.language.Empty;
import ceylon.language.SequenceBuilder;
import ceylon.language.Sequential;
import ceylon.language.empty_;
import ceylon.language.meta.declaration.ClassOrInterfaceDeclaration$impl;
import ceylon.language.meta.declaration.GenericDeclaration$impl;
import ceylon.language.meta.declaration.OpenType;
import ceylon.language.meta.model.ClassOrInterface;
import ceylon.language.meta.model.Member;

import com.redhat.ceylon.compiler.java.Util;
import com.redhat.ceylon.compiler.java.metadata.Ceylon;
import com.redhat.ceylon.compiler.java.metadata.Ignore;
import com.redhat.ceylon.compiler.java.metadata.Name;
import com.redhat.ceylon.compiler.java.metadata.Sequenced;
import com.redhat.ceylon.compiler.java.metadata.TypeInfo;
import com.redhat.ceylon.compiler.java.metadata.TypeParameter;
import com.redhat.ceylon.compiler.java.metadata.TypeParameters;
import com.redhat.ceylon.compiler.java.metadata.Variance;
import com.redhat.ceylon.compiler.java.runtime.model.TypeDescriptor;
import com.redhat.ceylon.compiler.typechecker.model.Declaration;
import com.redhat.ceylon.compiler.typechecker.model.ProducedReference;
import com.redhat.ceylon.compiler.typechecker.model.ProducedType;
import com.redhat.ceylon.compiler.typechecker.model.TypeDeclaration;

@Ceylon(major = 7)
@com.redhat.ceylon.compiler.java.metadata.Class
public abstract class FreeClassOrInterface
    extends FreeNestableDeclaration
    implements ceylon.language.meta.declaration.ClassOrInterfaceDeclaration, AnnotationBearing {

    @Ignore
    public static final TypeDescriptor $TypeDescriptor$ = TypeDescriptor.klass(FreeClassOrInterface.class);
    
    @Ignore
    private static final TypeDescriptor $FunctionTypeDescriptor = TypeDescriptor.klass(ceylon.language.meta.declaration.FunctionDeclaration.class, Anything.$TypeDescriptor$, Empty.$TypeDescriptor$);
    @Ignore
    private static final TypeDescriptor $AttributeTypeDescriptor = TypeDescriptor.klass(ceylon.language.meta.declaration.ValueDeclaration.class, Anything.$TypeDescriptor$);
    @Ignore
    private static final TypeDescriptor $ClassOrInterfaceTypeDescriptor = TypeDescriptor.klass(ceylon.language.meta.declaration.ClassOrInterfaceDeclaration.class, Anything.$TypeDescriptor$);
    
    private volatile boolean initialised = false;
    private ceylon.language.meta.declaration.OpenClassType superclass;
    private Sequential<ceylon.language.meta.declaration.OpenInterfaceType> interfaces;
    private Sequential<? extends ceylon.language.meta.declaration.TypeParameter> typeParameters;

    private List<ceylon.language.meta.declaration.NestableDeclaration> declaredDeclarations;
    private List<ceylon.language.meta.declaration.NestableDeclaration> declarations;

    private Sequential<? extends ceylon.language.meta.declaration.OpenType> caseTypes;

    public FreeClassOrInterface(com.redhat.ceylon.compiler.typechecker.model.ClassOrInterface declaration) {
        super(declaration);
    }

    @Override
    @Ignore
    public ClassOrInterfaceDeclaration$impl $ceylon$language$meta$declaration$ClassOrInterfaceDeclaration$impl() {
        return null;
    }

    @Override
    @Ignore
    public GenericDeclaration$impl $ceylon$language$meta$declaration$GenericDeclaration$impl() {
        return null;
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    protected void init(){
        com.redhat.ceylon.compiler.typechecker.model.ClassOrInterface declaration = (com.redhat.ceylon.compiler.typechecker.model.ClassOrInterface) this.declaration;
        
        ProducedType superType = declaration.getExtendedType();
        if(superType != null)
            this.superclass = (ceylon.language.meta.declaration.OpenClassType) Metamodel.getMetamodel(superType);
        
        List<ProducedType> satisfiedTypes = declaration.getSatisfiedTypes();
        ceylon.language.meta.declaration.OpenInterfaceType[] interfaces = new ceylon.language.meta.declaration.OpenInterfaceType[satisfiedTypes.size()];
        int i=0;
        for(ProducedType pt : satisfiedTypes){
            interfaces[i++] = (ceylon.language.meta.declaration.OpenInterfaceType) Metamodel.getMetamodel(pt);
        }
        this.interfaces = Util.sequentialInstance(ceylon.language.meta.declaration.OpenInterfaceType.$TypeDescriptor$, interfaces);

        if(declaration.getCaseTypes() != null)
            this.caseTypes = Metamodel.getMetamodelSequential(declaration.getCaseTypes());
        else
            this.caseTypes = (Sequential<? extends ceylon.language.meta.declaration.OpenType>)(Sequential)empty_.get_();

        this.typeParameters = Metamodel.getTypeParameters(declaration);
        
        List<com.redhat.ceylon.compiler.typechecker.model.Declaration> memberModelDeclarations = declaration.getMembers();
        this.declaredDeclarations = new LinkedList<ceylon.language.meta.declaration.NestableDeclaration>();
        for(com.redhat.ceylon.compiler.typechecker.model.Declaration memberModelDeclaration : memberModelDeclarations){
            if(isSupportedType(memberModelDeclaration))
                declaredDeclarations.add(Metamodel.getOrCreateMetamodel(memberModelDeclaration));
        }

        Collection<com.redhat.ceylon.compiler.typechecker.model.Declaration> inheritedModelDeclarations = 
                collectMembers(declaration);
        this.declarations = new LinkedList<ceylon.language.meta.declaration.NestableDeclaration>();
        for(com.redhat.ceylon.compiler.typechecker.model.Declaration memberModelDeclaration : inheritedModelDeclarations){
            if(isSupportedType(memberModelDeclaration))
                declarations.add(Metamodel.getOrCreateMetamodel(memberModelDeclaration));
        }
    }

    private boolean isSupportedType(Declaration memberModelDeclaration) {
        return memberModelDeclaration instanceof com.redhat.ceylon.compiler.typechecker.model.Value
                || memberModelDeclaration instanceof com.redhat.ceylon.compiler.typechecker.model.Method
                || memberModelDeclaration instanceof com.redhat.ceylon.compiler.typechecker.model.TypeAlias
                || memberModelDeclaration instanceof com.redhat.ceylon.compiler.typechecker.model.ClassOrInterface;
    }

    private Collection<com.redhat.ceylon.compiler.typechecker.model.Declaration> collectMembers(com.redhat.ceylon.compiler.typechecker.model.TypeDeclaration base){
        Map<String, com.redhat.ceylon.compiler.typechecker.model.Declaration> byName = 
                new HashMap<String, com.redhat.ceylon.compiler.typechecker.model.Declaration>();
        collectMembers(base, byName);
        return byName.values();<commit_msg>FreeClassOrInterface ceylon/ceylon-compiler#1572: skip overloaded abstractions for now<commit_after>package com.redhat.ceylon.compiler.java.runtime.metamodel;

import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import ceylon.language.Anything;
import ceylon.language.Empty;
import ceylon.language.SequenceBuilder;
import ceylon.language.Sequential;
import ceylon.language.empty_;
import ceylon.language.meta.declaration.ClassOrInterfaceDeclaration$impl;
import ceylon.language.meta.declaration.GenericDeclaration$impl;
import ceylon.language.meta.declaration.OpenType;
import ceylon.language.meta.model.ClassOrInterface;
import ceylon.language.meta.model.Member;

import com.redhat.ceylon.compiler.java.Util;
import com.redhat.ceylon.compiler.java.metadata.Ceylon;
import com.redhat.ceylon.compiler.java.metadata.Ignore;
import com.redhat.ceylon.compiler.java.metadata.Name;
import com.redhat.ceylon.compiler.java.metadata.Sequenced;
import com.redhat.ceylon.compiler.java.metadata.TypeInfo;
import com.redhat.ceylon.compiler.java.metadata.TypeParameter;
import com.redhat.ceylon.compiler.java.metadata.TypeParameters;
import com.redhat.ceylon.compiler.java.metadata.Variance;
import com.redhat.ceylon.compiler.java.runtime.model.TypeDescriptor;
import com.redhat.ceylon.compiler.typechecker.model.Declaration;
import com.redhat.ceylon.compiler.typechecker.model.ProducedReference;
import com.redhat.ceylon.compiler.typechecker.model.ProducedType;
import com.redhat.ceylon.compiler.typechecker.model.TypeDeclaration;

@Ceylon(major = 7)
@com.redhat.ceylon.compiler.java.metadata.Class
public abstract class FreeClassOrInterface
    extends FreeNestableDeclaration
    implements ceylon.language.meta.declaration.ClassOrInterfaceDeclaration, AnnotationBearing {

    @Ignore
    public static final TypeDescriptor $TypeDescriptor$ = TypeDescriptor.klass(FreeClassOrInterface.class);
    
    @Ignore
    private static final TypeDescriptor $FunctionTypeDescriptor = TypeDescriptor.klass(ceylon.language.meta.declaration.FunctionDeclaration.class, Anything.$TypeDescriptor$, Empty.$TypeDescriptor$);
    @Ignore
    private static final TypeDescriptor $AttributeTypeDescriptor = TypeDescriptor.klass(ceylon.language.meta.declaration.ValueDeclaration.class, Anything.$TypeDescriptor$);
    @Ignore
    private static final TypeDescriptor $ClassOrInterfaceTypeDescriptor = TypeDescriptor.klass(ceylon.language.meta.declaration.ClassOrInterfaceDeclaration.class, Anything.$TypeDescriptor$);
    
    private volatile boolean initialised = false;
    private ceylon.language.meta.declaration.OpenClassType superclass;
    private Sequential<ceylon.language.meta.declaration.OpenInterfaceType> interfaces;
    private Sequential<? extends ceylon.language.meta.declaration.TypeParameter> typeParameters;

    private List<ceylon.language.meta.declaration.NestableDeclaration> declaredDeclarations;
    private List<ceylon.language.meta.declaration.NestableDeclaration> declarations;

    private Sequential<? extends ceylon.language.meta.declaration.OpenType> caseTypes;

    public FreeClassOrInterface(com.redhat.ceylon.compiler.typechecker.model.ClassOrInterface declaration) {
        super(declaration);
    }

    @Override
    @Ignore
    public ClassOrInterfaceDeclaration$impl $ceylon$language$meta$declaration$ClassOrInterfaceDeclaration$impl() {
        return null;
    }

    @Override
    @Ignore
    public GenericDeclaration$impl $ceylon$language$meta$declaration$GenericDeclaration$impl() {
        return null;
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    protected void init(){
        com.redhat.ceylon.compiler.typechecker.model.ClassOrInterface declaration = (com.redhat.ceylon.compiler.typechecker.model.ClassOrInterface) this.declaration;
        
        ProducedType superType = declaration.getExtendedType();
        if(superType != null)
            this.superclass = (ceylon.language.meta.declaration.OpenClassType) Metamodel.getMetamodel(superType);
        
        List<ProducedType> satisfiedTypes = declaration.getSatisfiedTypes();
        ceylon.language.meta.declaration.OpenInterfaceType[] interfaces = new ceylon.language.meta.declaration.OpenInterfaceType[satisfiedTypes.size()];
        int i=0;
        for(ProducedType pt : satisfiedTypes){
            interfaces[i++] = (ceylon.language.meta.declaration.OpenInterfaceType) Metamodel.getMetamodel(pt);
        }
        this.interfaces = Util.sequentialInstance(ceylon.language.meta.declaration.OpenInterfaceType.$TypeDescriptor$, interfaces);

        if(declaration.getCaseTypes() != null)
            this.caseTypes = Metamodel.getMetamodelSequential(declaration.getCaseTypes());
        else
            this.caseTypes = (Sequential<? extends ceylon.language.meta.declaration.OpenType>)(Sequential)empty_.get_();

        this.typeParameters = Metamodel.getTypeParameters(declaration);
        
        List<com.redhat.ceylon.compiler.typechecker.model.Declaration> memberModelDeclarations = declaration.getMembers();
        this.declaredDeclarations = new LinkedList<ceylon.language.meta.declaration.NestableDeclaration>();
        for(com.redhat.ceylon.compiler.typechecker.model.Declaration memberModelDeclaration : memberModelDeclarations){
            if(isSupportedType(memberModelDeclaration))
                declaredDeclarations.add(Metamodel.getOrCreateMetamodel(memberModelDeclaration));
        }

        Collection<com.redhat.ceylon.compiler.typechecker.model.Declaration> inheritedModelDeclarations = 
                collectMembers(declaration);
        this.declarations = new LinkedList<ceylon.language.meta.declaration.NestableDeclaration>();
        for(com.redhat.ceylon.compiler.typechecker.model.Declaration memberModelDeclaration : inheritedModelDeclarations){
            if(isSupportedType(memberModelDeclaration))
                declarations.add(Metamodel.getOrCreateMetamodel(memberModelDeclaration));
        }
    }

    private boolean isSupportedType(Declaration memberModelDeclaration) {
        return memberModelDeclaration instanceof com.redhat.ceylon.compiler.typechecker.model.Value
                || (memberModelDeclaration instanceof com.redhat.ceylon.compiler.typechecker.model.Method
                        && !((com.redhat.ceylon.compiler.typechecker.model.Method)memberModelDeclaration).isAbstraction())
                || memberModelDeclaration instanceof com.redhat.ceylon.compiler.typechecker.model.TypeAlias
                || memberModelDeclaration instanceof com.redhat.ceylon.compiler.typechecker.model.Interface
                || (memberModelDeclaration instanceof com.redhat.ceylon.compiler.typechecker.model.Class
                        && !((com.redhat.ceylon.compiler.typechecker.model.Class)memberModelDeclaration).isAbstraction());
    }

    private Collection<com.redhat.ceylon.compiler.typechecker.model.Declaration> collectMembers(com.redhat.ceylon.compiler.typechecker.model.TypeDeclaration base){
        Map<String, com.redhat.ceylon.compiler.typechecker.model.Declaration> byName = 
                new HashMap<String, com.redhat.ceylon.compiler.typechecker.model.Declaration>();
        collectMembers(base, byName);
        return byName.values();
{'fraction_non_alphanumeric': 0.09525822588600014, 'fraction_numerical': 0.000563658141337279, 'mean_word_length': 4.612495057334915, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, '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': '7253582', 'n_tokens_mistral': 3920, 'n_tokens_neox': 3815, 'n_words': 508}