Browse Source

made IsAutomaticProperty static and internal, removed dependency on ITextEditor, works now with any IProperty in any class, even partial classes

pull/1/head
Siegfried Pammer 15 years ago
parent
commit
5315c0e2ba
  1. 37
      src/AddIns/Misc/SharpRefactoring/Project/Src/PropertyRefactoringMenuBuilder.cs

37
src/AddIns/Misc/SharpRefactoring/Project/Src/PropertyRefactoringMenuBuilder.cs

@ -10,7 +10,7 @@ using System.Collections.Generic; @@ -10,7 +10,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Documents;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.Core.Presentation;
using ICSharpCode.Core.WinForms;
using ICSharpCode.NRefactory;
@ -48,7 +48,7 @@ namespace SharpRefactoring @@ -48,7 +48,7 @@ namespace SharpRefactoring
ITextEditor editor = FindReferencesAndRenameHelper.OpenDefinitionFile(property, false);
string field = null;
PropertyDeclaration astProp = null;
if (IsAutomaticProperty(editor, property)) {
if (IsAutomaticProperty(property)) {
cmd = new MenuCommand("${res:SharpDevelop.Refactoring.ExpandAutomaticProperty}", ExpandAutomaticProperty);
cmd.Tag = property;
items.Add(cmd);
@ -68,21 +68,38 @@ namespace SharpRefactoring @@ -68,21 +68,38 @@ namespace SharpRefactoring
return items.ToArray();
}
bool IsAutomaticProperty(ITextEditor editor, IProperty property)
internal static bool IsAutomaticProperty(IProperty property)
{
if (editor == null)
string fileName = property.CompilationUnit.FileName;
if (fileName == null)
return false;
IDocument document;
ITextEditorProvider provider = FileService.GetOpenFile(fileName) as ITextEditorProvider;
if (provider == null) {
if (!File.Exists(fileName))
return false;
try {
document = DocumentUtilitites.LoadDocumentFromBuffer(new StringTextBuffer(File.ReadAllText(fileName)));
} catch (IOException) {
return false;
}
} else {
document = provider.TextEditor.Document;
}
bool isAutomatic = false;
if (property.CanGet) {
if (property.GetterRegion.IsEmpty)
isAutomatic = true;
else {
int getterStartOffset = editor.Document.PositionToOffset(property.GetterRegion.BeginLine, property.GetterRegion.BeginColumn);
int getterEndOffset = editor.Document.PositionToOffset(property.GetterRegion.EndLine, property.GetterRegion.EndColumn);
int getterStartOffset = document.PositionToOffset(property.GetterRegion.BeginLine, property.GetterRegion.BeginColumn);
int getterEndOffset = document.PositionToOffset(property.GetterRegion.EndLine, property.GetterRegion.EndColumn);
string text = editor.Document.GetText(getterStartOffset, getterEndOffset - getterStartOffset)
string text = document.GetText(getterStartOffset, getterEndOffset - getterStartOffset)
.Replace(" ", "").Replace("\t", "").Replace("\n", "").Replace("\r", "");
isAutomatic = text == "get;";
@ -93,10 +110,10 @@ namespace SharpRefactoring @@ -93,10 +110,10 @@ namespace SharpRefactoring
if (property.SetterRegion.IsEmpty)
isAutomatic |= true;
else {
int setterStartOffset = editor.Document.PositionToOffset(property.SetterRegion.BeginLine, property.SetterRegion.BeginColumn);
int setterEndOffset = editor.Document.PositionToOffset(property.SetterRegion.EndLine, property.SetterRegion.EndColumn);
int setterStartOffset = document.PositionToOffset(property.SetterRegion.BeginLine, property.SetterRegion.BeginColumn);
int setterEndOffset = document.PositionToOffset(property.SetterRegion.EndLine, property.SetterRegion.EndColumn);
string text = editor.Document.GetText(setterStartOffset, setterEndOffset - setterStartOffset)
string text = document.GetText(setterStartOffset, setterEndOffset - setterStartOffset)
.Replace(" ", "").Replace("\t", "").Replace("\n", "").Replace("\r", "");
isAutomatic |= text == "set;";

Loading…
Cancel
Save