<commit_before>package com.redhat.ceylon.compiler.typechecker.util;

import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import com.redhat.ceylon.common.Backend;
import com.redhat.ceylon.compiler.typechecker.tree.Tree;
import com.redhat.ceylon.model.typechecker.model.Declaration;
import com.redhat.ceylon.model.typechecker.model.FunctionOrValue;
import com.redhat.ceylon.model.typechecker.model.ModelUtil;

/** Certain convenience methods related to native types.
 * 
 * @author <NAME>
 */
public class NativeUtil {

    public static List<Tree.Statement> mergeStatements(Tree.Body body, Tree.Declaration header) {
        // And if the header exists we go through the declarations in
        // its body and add them to our list of statements as if they
        // were part of the native implementation when a) it has a
        // default implementation and b) we can't find a matching
        // declaration in our (original) list of statements
        List<Tree.Statement> hdrstmts;
        if (header instanceof Tree.ClassDefinition) {
            hdrstmts = ((Tree.ClassDefinition)header).getClassBody().getStatements();
        } else if (header instanceof Tree.ObjectDefinition) {
            hdrstmts = ((Tree.ObjectDefinition)header).getClassBody().getStatements();
        } else {
            hdrstmts = null;
        }
        List<Tree.Statement> stmts = body.getStatements();
        if (hdrstmts != null && !hdrstmts.isEmpty()) {
            Set<String> names = getDeclarationNames(stmts);
            LinkedList<Tree.Statement> newstmts = new LinkedList<Tree.Statement>(stmts);
            for (Tree.Statement stmt : hdrstmts) {
                if (stmt instanceof Tree.Declaration) {
                    Tree.Declaration decl = (Tree.Declaration)stmt;
                    if (isImplemented(decl)
                            && !names.contains(decl.getDeclarationModel().getName())) {
                        newstmts.addFirst(decl);
                    }
                }
            }
            stmts = newstmts;
        }
        return stmts;
    }

    public static Set<String> getDeclarationNames(java.util.List<Tree.Statement> stmts) {
        java.util.HashSet<String> names = new java.util.HashSet<String>();
        for (Tree.Statement stmt : stmts) {
            if (stmt instanceof Tree.Declaration) {
                Tree.Declaration decl = (Tree.Declaration)stmt;<commit_msg>only declarations were being merged<commit_after>package com.redhat.ceylon.compiler.typechecker.util;

import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import com.redhat.ceylon.common.Backend;
import com.redhat.ceylon.compiler.typechecker.tree.Tree;
import com.redhat.ceylon.model.typechecker.model.Declaration;
import com.redhat.ceylon.model.typechecker.model.FunctionOrValue;
import com.redhat.ceylon.model.typechecker.model.ModelUtil;

/** Certain convenience methods related to native types.
 * 
 * @author <NAME>
 */
public class NativeUtil {

    public static List<Tree.Statement> mergeStatements(Tree.Body body, Tree.Declaration header) {
        // And if the header exists we go through the declarations in
        // its body and add them to our list of statements as if they
        // were part of the native implementation when a) it has a
        // default implementation and b) we can't find a matching
        // declaration in our (original) list of statements
        List<Tree.Statement> hdrstmts;
        if (header instanceof Tree.ClassDefinition) {
            hdrstmts = ((Tree.ClassDefinition)header).getClassBody().getStatements();
        } else if (header instanceof Tree.ObjectDefinition) {
            hdrstmts = ((Tree.ObjectDefinition)header).getClassBody().getStatements();
        } else {
            hdrstmts = null;
        }
        List<Tree.Statement> stmts = body.getStatements();
        if (hdrstmts != null && !hdrstmts.isEmpty()) {
            Set<String> names = getDeclarationNames(stmts);
            LinkedList<Tree.Statement> newstmts = new LinkedList<Tree.Statement>(stmts);
            for (Tree.Statement stmt : hdrstmts) {
                if (stmt instanceof Tree.Declaration) {
                    Tree.Declaration decl = (Tree.Declaration)stmt;
                    if (isImplemented(decl)
                            && !names.contains(decl.getDeclarationModel().getName())) {
                        newstmts.addFirst(decl);
                    }
                } else {
                    newstmts.addFirst(stmt);
                }
            }
            stmts = newstmts;
        }
        return stmts;
    }

    public static Set<String> getDeclarationNames(java.util.List<Tree.Statement> stmts) {
        java.util.HashSet<String> names = new java.util.HashSet<String>();
        for (Tree.Statement stmt : stmts) {
            if (stmt instanceof Tree.Declaration) {
                Tree.Declaration decl = (Tree.Declaration)stmt;
{'fraction_non_alphanumeric': 0.10080645161290322, 'fraction_numerical': 0.0, 'mean_word_length': 2.397945205479452, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '980659', 'n_tokens_mistral': 1373, 'n_tokens_neox': 1344, 'n_words': 323}