From ba0bb353af3f75f9bbee4a7b595d97b88ceb3120 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 6 Jan 2013 14:39:22 +0100 Subject: [PATCH] make Document in SDRefactoringContext accessible from outside --- .../Project/Src/Refactoring/IssueManager.cs | 2 +- .../Src/Refactoring/SDRefactoringContext.cs | 22 +++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/IssueManager.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/IssueManager.cs index 27c5a37e83..945b78e12e 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/IssueManager.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/IssueManager.cs @@ -162,7 +162,7 @@ namespace CSharpBinding.Refactoring { int startOffset = InspectedVersion.MoveOffsetTo(document.Version, this.StartOffset, AnchorMovementType.Default); int endOffset = InspectedVersion.MoveOffsetTo(document.Version, this.EndOffset, AnchorMovementType.Default); - if (startOffset >= endOffset) + if (this.StartOffset != this.EndOffset && startOffset >= endOffset) return; marker = markerService.Create(startOffset, endOffset - startOffset); marker.ToolTip = this.Description; diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/SDRefactoringContext.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/SDRefactoringContext.cs index 1ecd29007d..d67b82c8e5 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/SDRefactoringContext.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/SDRefactoringContext.cs @@ -5,6 +5,7 @@ using System; using System.ComponentModel.Design; using System.Threading; +using ICSharpCode.NRefactory.Utils; using CSharpBinding.Parser; using ICSharpCode.Core; using ICSharpCode.NRefactory; @@ -100,6 +101,15 @@ namespace CSharpBinding.Refactoring return new DocumentScript(document, formattingOptions, this.TextEditorOptions); } + public IDocument Document { + get { + IDocument result = LazyInit.VolatileRead(ref document); + if (result != null) + return result; + return LazyInit.GetOrSet(ref document, new ReadOnlyDocument(textSource, resolver.UnresolvedFile.FileName)); + } + } + public override TextLocation Location { get { return location; } } @@ -142,23 +152,17 @@ namespace CSharpBinding.Refactoring public override IDocumentLine GetLineByOffset(int offset) { - if (document == null) - document = new ReadOnlyDocument(textSource, resolver.UnresolvedFile.FileName); - return document.GetLineByOffset(offset); + return Document.GetLineByOffset(offset); } public override int GetOffset(TextLocation location) { - if (document == null) - document = new ReadOnlyDocument(textSource, resolver.UnresolvedFile.FileName); - return document.GetOffset(location); + return Document.GetOffset(location); } public override TextLocation GetLocation(int offset) { - if (document == null) - document = new ReadOnlyDocument(textSource, resolver.UnresolvedFile.FileName); - return document.GetLocation(offset); + return Document.GetLocation(offset); } public override AstType CreateShortType(IType fullType)