function getDocumentForPath(fullPath, fileObj) {
        var doc = getOpenDocumentForPath(fullPath);

        if (doc) {
            // use existing document
            return new $.Deferred().resolve(doc).promise();
        } else {
            var result = new $.Deferred(),
                promise = result.promise();

            // return null in case of untitled documents
            if (fullPath.indexOf(_untitledDocumentPath) === 0) {
                result.resolve(null);
                return promise;
            }

            var file            = fileObj || FileSystem.getFileForPath(fullPath),
                pendingPromise  = getDocumentForPath._pendingDocumentPromises[file.id];

            if (pendingPromise) {
                // wait for the result of a previous request
                return pendingPromise;
            } else {
                // log this document's Promise as pending
                getDocumentForPath._pendingDocumentPromises[file.id] = promise;

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

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

                FileUtils.readAsText(file)
                    .always(function () {
                        // document is no longer pending
                        delete getDocumentForPath._pendingDocumentPromises[file.id];
                    })
                    .done(function (rawText, readTimestamp) {
                        doc = new DocumentModule.Document(file, readTimestamp, rawText);

                        // This is a good point to clean up any old dangling Documents
                        _gcDocuments();

                        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).

If all you need is the Document's getText() value, use the faster getDocumentText() instead.

@param {!string} fullPath
@param {!object} fileObj actual File|RemoteFile or some other protocol adapter handle
@return {$.Promise} A promise object that will be resolved with the Document, or rejected
     with a FileSystemError if the file is not yet open and can't be read from disk.