src/resource.js
function buildIndex(model) {
    var index = {},
        contents = model.get('contents').array();

    if (contents.length) {
        var build = function(object, idx) {
            var eContents = object.eContents();
            index[idx] = object;

            _.each(eContents, function(e) { build(e, e.fragment()); });
        };

        var root, iD;
        if (contents.length === 1) {
            root = contents[0];
            if (root._id) {
                build(root, root._id);
            } else {
                iD = root.eClass.get('eIDAttribute') || null;
                if (iD) {
                    build(root, root.get(iD.get('name')));
                } else {
                    build(root, '/');
                }
            }
        } else {
            for (var i = 0; i < contents.length; i++) {
                root = contents[i];
                if (root._id) {
                    build(root, root._id);
                } else {
                    iD = root.eClass.get('eIDAttribute') || null;
                    if (iD) {
                        build(root, root.get(iD.get('name')));
                    } else {
                        build(root, '/' + i);
                    }
                }
            }
        }
    }

    return index;
}
function buildIndex(model) {
    var index = {},
        contents = model.get('contents').array();

    if (contents.length) {
        var build = function(object, idx) {
            var eContents = object.eContents();
            index[idx] = object;

            _.each(eContents, function(e) { build(e, e.fragment()); });
        };

        var root, iD;
        if (contents.length === 1) {
            root = contents[0];
            if (root._id) {
                build(root, root._id);
            } else {
                iD = root.eClass.get('eIDAttribute') || null;
                if (iD) {
                    build(root, root.get(iD.get('name')));
                } else {
                    build(root, '/');
                }
            }
        } else {
            for (var i = 0; i < contents.length; i++) {
                root = contents[i];
                if (root._id) {
                    build(root, root._id);
                } else {
                    iD = root.eClass.get('eIDAttribute') || null;
                    if (iD) {
                        build(root, root.get(iD.get('name')));
                    } else {
                        build(root, '/' + i);
                    }
                }
            }
        }
    }

    return index;
}
function buildIndex ( model ) { var index = { } , contents = model . get ( 'contents' ) . array ( ) ; if ( contents . length ) { var build = function ( object , idx ) { var eContents = object . eContents ( ) ; index [ idx ] = object ; _ . each ( eContents , function ( e ) { build ( e , e . fragment ( ) ) ; } ) ; } ; var root , iD ; if ( contents . length === 1 ) { root = contents [ 0 ] ; if ( root . _id ) { build ( root , root . _id ) ; } else { iD = root . eClass . get ( 'eIDAttribute' ) || null ; if ( iD ) { build ( root , root . get ( iD . get ( 'name' ) ) ) ; } else { build ( root , '/' ) ; } } } else { for ( var i = 0 ; i < contents . length ; i ++ ) { root = contents [ i ] ; if ( root . _id ) { build ( root , root . _id ) ; } else { iD = root . eClass . get ( 'eIDAttribute' ) || null ; if ( iD ) { build ( root , root . get ( iD . get ( 'name' ) ) ) ; } else { build ( root , '/' + i ) ; } } } } } return index ; }
Build index of EObjects contained in a Resource.  The index keys are the EObject's fragment identifier, the values are the EObjects.
Build index of EObjects contained in a Resource . The index keys are the EObject s fragment identifier the values are the EObjects .