function getDocumentForPath(fullPath) {
        var doc             = _openDocuments[fullPath],
            pendingPromise  = getDocumentForPath._pendingDocumentPromises[fullPath];

        if (doc) {
            // use existing document
            return new $.Deferred().resolve(doc).promise();
        } else if (pendingPromise) {
            // wait for the result of a previous request
            return pendingPromise;
        } else {
            var result = new $.Deferred(),
                promise = result.promise();
            
            // log this document's Promise as pending
            getDocumentForPath._pendingDocumentPromises[fullPath] = promise;

            // create a new document
            var fileEntry = new NativeFileSystem.FileEntry(fullPath),
                perfTimerName = PerfUtils.markStart("getDocumentForPath:\t" + fullPath);

            result.done(function () {
                PerfUtils.addMeasurement(perfTimerName);
            }).fail(function () {
                PerfUtils.finalizeMeasurement(perfTimerName);
            });

            FileUtils.readAsText(fileEntry)
                .always(function () {
                    // document is no longer pending
                    delete getDocumentForPath._pendingDocumentPromises[fullPath];
                })
                .done(function (rawText, readTimestamp) {
                    doc = new Document(fileEntry, readTimestamp, rawText);
                    result.resolve(doc);
                })
                .fail(function (fileError) {
                    result.reject(fileError);
                });
            
            return promise;
        }
    }
Gets an existing open Document for the given file, or creates a new one if the Document is
not currently open ('open' means referenced by the UI somewhere). Always use this method to
get Documents; do not call the Document constructor directly. This method is safe to call
in parallel.

If you are going to hang onto the Document for more than just the duration of a command - e.g.
if you are going to display its contents in a piece of UI - then you must addRef() the Document
and listen for changes on it. (Note: opening the Document in an Editor automatically manages
refs and listeners for that Editor UI).

@param {!string} fullPath
@return {$.Promise} A promise object that will be resolved with the Document, or rejected
     with a FileError if the file is not yet open and can't be read from disk.