Extract method confuses input parameter with return value #382

Open
opened 2014-02-18 16:44:59 -06:00 by dgrunwald · 0 comments
dgrunwald commented 2014-02-18 16:44:59 -06:00 (Migrated from github.com)

For context of this code snippet: Grab commit 157a745ba04a9cbdfce7144726fd3fae15f57943 of the SharpDevelop repository, file TextDocumentFileModelProvider.cs

Extract the 'true' branch of the if (// Reload document).

    public TextDocument Load(OpenedFile file)
    {
        TextDocument document = file.GetModel(this, GetModelOptions.AllowStale | GetModelOptions.DoNotLoad);
        var info = document != null ? document.GetFileModelInfo() : new DocumentFileModelInfo();
        string textContent;
        using (Stream stream = file.GetModel(FileModels.Binary).OpenRead()) {
            using (StreamReader reader = FileReader.OpenStream(stream, SD.FileService.DefaultFileEncoding)) {
                textContent = reader.ReadToEnd();
                info.Encoding = reader.CurrentEncoding;
            }
        }
        if (document != null) {
            // Reload document
            var diff = new MyersDiffAlgorithm(new StringSequence(document.Text), new StringSequence(textContent));
            info.isLoading = true;
            try {
                document.Replace(0, document.TextLength, textContent, ToOffsetChangeMap(diff.GetEdits()));
                document.UndoStack.ClearAll();
                info.IsStale = false;
            } finally {
                info.isLoading = false;
            }
        } else {
            document = new TextDocument(textContent);
            // Store info for the new document (necessary so that we don't forget the encoding we just used)
            document.GetRequiredService<IServiceContainer>().AddService(typeof(DocumentFileModelInfo), info);
        }
        return document;
    }

Expected signature: void ReloadDocument(TextDocument document, DocumentFileModelInfo info, string textContent)
Actual signature: TextDocument ReloadDocument(DocumentFileModelInfo info, string textContent)

For context of this code snippet: Grab commit 157a745ba04a9cbdfce7144726fd3fae15f57943 of the SharpDevelop repository, file [TextDocumentFileModelProvider.cs](https://github.com/icsharpcode/SharpDevelop/blob/157a745ba04a9cbdfce7144726fd3fae15f57943/src/Main/Base/Project/Workbench/File/TextDocumentFileModelProvider.cs) Extract the 'true' branch of the if (// Reload document). ``` public TextDocument Load(OpenedFile file) { TextDocument document = file.GetModel(this, GetModelOptions.AllowStale | GetModelOptions.DoNotLoad); var info = document != null ? document.GetFileModelInfo() : new DocumentFileModelInfo(); string textContent; using (Stream stream = file.GetModel(FileModels.Binary).OpenRead()) { using (StreamReader reader = FileReader.OpenStream(stream, SD.FileService.DefaultFileEncoding)) { textContent = reader.ReadToEnd(); info.Encoding = reader.CurrentEncoding; } } if (document != null) { // Reload document var diff = new MyersDiffAlgorithm(new StringSequence(document.Text), new StringSequence(textContent)); info.isLoading = true; try { document.Replace(0, document.TextLength, textContent, ToOffsetChangeMap(diff.GetEdits())); document.UndoStack.ClearAll(); info.IsStale = false; } finally { info.isLoading = false; } } else { document = new TextDocument(textContent); // Store info for the new document (necessary so that we don't forget the encoding we just used) document.GetRequiredService<IServiceContainer>().AddService(typeof(DocumentFileModelInfo), info); } return document; } ``` Expected signature: `void ReloadDocument(TextDocument document, DocumentFileModelInfo info, string textContent)` Actual signature: `TextDocument ReloadDocument(DocumentFileModelInfo info, string textContent)`
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-icsharpcode/NRefactory#382
No description provided.