NRefactory icon indicating copy to clipboard operation
NRefactory copied to clipboard

Extract method confuses input parameter with return value

Open dgrunwald opened this issue 11 years ago • 0 comments

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)

dgrunwald avatar Feb 18 '14 22:02 dgrunwald