<commit_before>var _ = require("underscore"),
    path = require("path");

var builtins = {
    "object": "object",
    "map": "object",
    "dictionary": "object",
    "array": "array",
    "int": "int",
    "integer": "int",
    "float": "float",
    "double": "double",
    "short": "short",
    "boolean": "boolean",
    "string": "string",
    "long": "long",
    "any": "any"
};

function Transformer (classes, ordering) {
    this.classes = classes || {};
    this.classOrder = ordering || [];
}
exports.Transformer = Transformer;

Transformer.prototype.findClass = function (className) {
    var self = this,
        c;
    if (builtins[className]) {
        c = builtins[className];
    } else {
        c = self.classes[className];
        if (!c) {
            self.classes[className] = c = {};
            self.classOrder.push(c);
        }
    }
    
    if (self.currentClass) {
        var imports = self.currentClass.imports;
        if (!imports) {
            self.currentClass.imports = imports = {};
        }
        imports[className] = c;
    }
    
    return c;
};

Transformer.prototype.transformParameter = function (idlParam) {
    var self = this, 
        param = {};
    _.each(idlParam, function (i, key) {
        var value = idlParam[key];
        if (key === "docs") {
            param.docs = value;
        } else {
            param.name = key;
            param.type = self.findClass(value);
        }
    });
    return param;
};

Transformer.prototype.transformParams = function (idlParams) {
    var self = this;
    if (!_.isArray(idlParams)) {
        throw new Error("Method's argument list must be an array. Currently it is: " + JSON.stringify(idlParams));
    }
    return _.map(idlParams, function (idlParam) {
        return self.transformParameter(idlParam);
    });
    
};

function optional (object, path) {
    if (_.isString(path)) {
        path = path.split(".");
    }
    if (_.isArray(path)) {
        _.each(path, function (p) {
            if (_.isUndefined(object)) {
                return;
            }
            object = object[p];
        });
        return object;
    }
}

Transformer.prototype.transformProperties = function (idlProperties, idlClass, irClass) {
    var self = this, 
        properties = [],
        defaults = optional(idlClass, "validation.defaults");
    
    
    _.each(idlProperties, function (i, key) {
        var value = idlProperties[key];
        var p;
        if (_.isString(value)) {
            p = {
                name: key,       
                type: self.findClass(value)
            };
        } else if (_.isObject(value)) {
            p = self.transformParameter(value);
        }
        if (defaults && defaults[key]) {
            p["default"] = defaults[key];
        } 
        properties.push(p);
    });
    return properties;
};

Transformer.prototype.transformMethods = function (idlMethods) {
    var self = this,
        methods = [];
    
    _.each(idlMethods, function (i, methodName) {
        var params = self.transformParams(idlMethods[methodName]);
        var m = {
            params: params,
            name: methodName
        };
        methods.push(m);
    });
    return methods;
};

var commonLanguages = {
    "javascript": 1,
    "gwt": 1
};

var bridgeTypes = {
    "request": 1,
    "response": 1
};

Transformer.prototype.checkClass = function (name, idlClass) {
    var type = idlClass.implementedBy || idlClass.role,
        hasProperties = idlClass.properties && !_.isEmpty(idlClass.properties),
        hasMethods = idlClass.methods && !_.isEmpty(idlClass.methods);
    
    
    if (type === "response" && hasMethods) {
        throw new Error("Objects with a response role are not allowed methods. '" + name + "' is not.");
    }
    
    if (hasProperties && !bridgeTypes[type]) {
        throw new Error("Only objects backed by an object/map/dictionary are allowed properties. '" + name + "' is not.");
    }
    
    idlClass.role = type;
};

Transformer.prototype.transformValidation = function (idlClass, irClass) {
    var deps = optional(idlClass, "validation.dependencies") || {},
        acceptable = optional(idlClass, "validation.acceptableForms") || [],
        defaults = optional(idlClass, "validation.defaults") || optional(idlClass, "defaults") || {},
        mandatory = optional(idlClass, "validation.mandatory") || [];
    
    var properties = optional(idlClass, "properties") || {},
        methods = optional(idlClass, "methods");
    
    function isMember (member) {
        return _.isString(member) && (properties[member] || methods[member]);
    }
    
    function isNotMember (member) {<commit_msg>Make declaredBy a synonym of implementedBy.<commit_after>var _ = require("underscore"),
    path = require("path");

var builtins = {
    "object": "object",
    "map": "object",
    "dictionary": "object",
    "array": "array",
    "int": "int",
    "integer": "int",
    "float": "float",
    "double": "double",
    "short": "short",
    "boolean": "boolean",
    "string": "string",
    "long": "long",
    "any": "any"
};

function Transformer (classes, ordering) {
    this.classes = classes || {};
    this.classOrder = ordering || [];
}
exports.Transformer = Transformer;

Transformer.prototype.findClass = function (className) {
    var self = this,
        c;
    if (builtins[className]) {
        c = builtins[className];
    } else {
        c = self.classes[className];
        if (!c) {
            self.classes[className] = c = {};
            self.classOrder.push(c);
        }
    }
    
    if (self.currentClass) {
        var imports = self.currentClass.imports;
        if (!imports) {
            self.currentClass.imports = imports = {};
        }
        imports[className] = c;
    }
    
    return c;
};

Transformer.prototype.transformParameter = function (idlParam) {
    var self = this, 
        param = {};
    _.each(idlParam, function (i, key) {
        var value = idlParam[key];
        if (key === "docs") {
            param.docs = value;
        } else {
            param.name = key;
            param.type = self.findClass(value);
        }
    });
    return param;
};

Transformer.prototype.transformParams = function (idlParams) {
    var self = this;
    if (!_.isArray(idlParams)) {
        throw new Error("Method's argument list must be an array. Currently it is: " + JSON.stringify(idlParams));
    }
    return _.map(idlParams, function (idlParam) {
        return self.transformParameter(idlParam);
    });
    
};

function optional (object, path) {
    if (_.isString(path)) {
        path = path.split(".");
    }
    if (_.isArray(path)) {
        _.each(path, function (p) {
            if (_.isUndefined(object)) {
                return;
            }
            object = object[p];
        });
        return object;
    }
}

Transformer.prototype.transformProperties = function (idlProperties, idlClass, irClass) {
    var self = this, 
        properties = [],
        defaults = optional(idlClass, "validation.defaults");
    
    
    _.each(idlProperties, function (i, key) {
        var value = idlProperties[key];
        var p;
        if (_.isString(value)) {
            p = {
                name: key,       
                type: self.findClass(value)
            };
        } else if (_.isObject(value)) {
            p = self.transformParameter(value);
        }
        if (defaults && defaults[key]) {
            p["default"] = defaults[key];
        } 
        properties.push(p);
    });
    return properties;
};

Transformer.prototype.transformMethods = function (idlMethods) {
    var self = this,
        methods = [];
    
    _.each(idlMethods, function (i, methodName) {
        var params = self.transformParams(idlMethods[methodName]);
        var m = {
            params: params,
            name: methodName
        };
        methods.push(m);
    });
    return methods;
};

var commonLanguages = {
    "javascript": 1,
    "gwt": 1
};

var bridgeTypes = {
    "request": 1,
    "response": 1
};

Transformer.prototype.checkClass = function (name, idlClass) {
    var type = idlClass.declaredBy || idlClass.implementedBy || idlClass.role,
        hasProperties = idlClass.properties && !_.isEmpty(idlClass.properties),
        hasMethods = idlClass.methods && !_.isEmpty(idlClass.methods);
    
    
    if (type === "response" && hasMethods) {
        throw new Error("Objects with a response role are not allowed methods. '" + name + "' is not.");
    }
    
    if (hasProperties && !bridgeTypes[type]) {
        throw new Error("Only objects backed by an object/map/dictionary are allowed properties. '" + name + "' is not.");
    }
    
    idlClass.role = type;
};

Transformer.prototype.transformValidation = function (idlClass, irClass) {
    var deps = optional(idlClass, "validation.dependencies") || {},
        acceptable = optional(idlClass, "validation.acceptableForms") || [],
        defaults = optional(idlClass, "validation.defaults") || optional(idlClass, "defaults") || {},
        mandatory = optional(idlClass, "validation.mandatory") || [];
    
    var properties = optional(idlClass, "properties") || {},
        methods = optional(idlClass, "methods");
    
    function isMember (member) {
        return _.isString(member) && (properties[member] || methods[member]);
    }
    
    function isNotMember (member) {
{'fraction_non_alphanumeric': 0.14378252097270894, 'fraction_numerical': 0.0008495274503557397, 'mean_word_length': 2.2342032967032965, 'pattern_counts': {'":': 34, '<': 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': '1645401', 'n_tokens_mistral': 2779, 'n_tokens_neox': 2754, 'n_words': 626}