本文整理汇总了C#中MonoDevelop.Refactoring.RefactoringOptions类的典型用法代码示例。如果您正苦于以下问题:C# RefactoringOptions类的具体用法?C# RefactoringOptions怎么用?C# RefactoringOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RefactoringOptions类属于MonoDevelop.Refactoring命名空间,在下文中一共展示了RefactoringOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AnalyzeTargetExpression
bool AnalyzeTargetExpression (RefactoringOptions options, MonoDevelop.CSharp.Ast.CompilationUnit unit)
{
var data = options.GetTextEditorData ();
var target = unit.GetNodeAt (data.Caret.Line, data.Caret.Column);
if (target == null)
return false;
if (target.Parent is MemberReferenceExpression && ((MemberReferenceExpression)target.Parent).GetChildByRole (MemberReferenceExpression.Roles.Identifier) == target) {
var memberReference = (MemberReferenceExpression)target.Parent;
target = memberReference.Target;
var targetResult = options.GetResolver ().Resolve (new ExpressionResult (data.GetTextBetween (target.StartLocation.Line, target.StartLocation.Column, target.EndLocation.Line, target.EndLocation.Column)), resolvePosition);
if (targetResult.StaticResolve)
modifiers = MonoDevelop.Projects.Dom.Modifiers.Static;
declaringType = options.Dom.GetType (targetResult.ResolvedType);
methodName = memberReference.MemberName;
} else if (target is Identifier) {
declaringType = options.ResolveResult.CallingType;
methodName = data.GetTextBetween (target.StartLocation.Line, target.StartLocation.Column, target.EndLocation.Line, target.EndLocation.Column);
}
if (declaringType != null && !HasCompatibleMethod (declaringType, methodName, invocation)) {
if (declaringType.HasParts)
declaringType = declaringType.Parts.FirstOrDefault (t => t.CompilationUnit.FileName == options.Document.FileName) ?? declaringType;
var doc = ProjectDomService.GetParsedDocument (declaringType.SourceProjectDom, declaringType.CompilationUnit.FileName);
declaringType = doc.CompilationUnit.GetTypeAt (declaringType.Location) ?? declaringType;
return true;
}
return false;
}
示例2: GetFixes
//FIXME: why is this invalid on the parseddocuments loaded when the doc is first loaded?
//maybe the item's type's SourceProject is null?
public IEnumerable<IAnalysisFixAction> GetFixes (MonoDevelop.Ide.Gui.Document doc, object fix)
{
var renameFix = (RenameMemberFix) fix;
var refactoring = new RenameRefactoring ();
var options = new RefactoringOptions () {
Document = doc,
Dom = doc.Dom,
SelectedItem = renameFix.Item,
};
if (!refactoring.IsValid (options))
yield break;
var prop = new RenameRefactoring.RenameProperties () {
NewName = renameFix.NewName,
};
yield return new RenameFixAction () {
Label = GettextCatalog.GetString ("Rename '{0}' to '{1}'", renameFix.Item.Name, renameFix.NewName),
Refactoring = refactoring,
Options = options,
Properties = prop,
Preview = false,
};
yield return new RenameFixAction () {
Label = GettextCatalog.GetString ("Rename '{0}' to '{1}' with preview",
renameFix.Item.Name, renameFix.NewName),
Refactoring = refactoring,
Options = options,
Properties = prop,
Preview = true,
};
}
示例3: PerformChanges
public override List<Change> PerformChanges(RefactoringOptions options, object properties)
{
List<Change> changes = new List<Change>();
var resolveResult = options.ResolveResult;
if (resolveResult == null) throw new InvalidOperationException("Cannot generate class here");
var resType = resolveResult.ResolvedType;
var doc = options.Document;
var editor = doc.Editor;
var currentDir = doc.FileName.ParentDirectory;
var nspace = resType.Namespace;
string typeName = resolveResult.ResolvedExpression.Expression;
var body = resType.Type.BodyRegion;
var content = editor.GetTextBetween(body.Start.Line, 1, body.End.Line, body.End.Column);
var contentLength = content.Length;
content = fileFormatResolver.GetNewTypeFileContent(content, nspace, editor.EolMarker);
CreateFileChange createFileChange = new CreateFileChange(@"{0}\{1}.cs".ToFormat(currentDir, typeName), content);
changes.Add(createFileChange);
TextReplaceChange textReplaceChange = new TextReplaceChange();
textReplaceChange.FileName = context.GetCurrentFilePath();
textReplaceChange.RemovedChars = contentLength + 1;
int num = editor.Document.LocationToOffset(body.Start.Line, 1);
textReplaceChange.Offset = num - 1;
textReplaceChange.InsertedText = string.Empty;
changes.Add (textReplaceChange);
return changes;
}
示例4: Run
protected override void Run(RefactoringOptions options)
{
RefactoringOperation operation = new CreateIVarOperation ();
if (operation.IsValid (options)) {
operation.Run (options);
}
}
示例5: DRenameNameDialog
public DRenameNameDialog(RefactoringOptions options,DRenameRefactoring rename)
{
this.rename = rename;
this.options = options;
this.Build ();
var ds = (INode)options.SelectedItem;
#region Adjust dialog title
var app = "Renaming ";
if (ds is DClassLike)
{
var dc = (DClassLike)ds;
app+=dc.ClassType.ToString();
}
else if (ds is DMethod)
app += "method";
else if (ds is DVariable)
app += ((DVariable)ds).IsAlias ? "alias" : "variable";
else
app += "item";
Title = app;
#endregion
text_NewId.Text = ds.Name;
buttonPreview.Sensitive = buttonOk.Sensitive = false;
buttonOk.Clicked += OnOKClicked;
buttonPreview.Clicked += OnPreviewClicked;
text_NewId.Changed += delegate { setNotifyIcon(buttonPreview.Sensitive = buttonOk.Sensitive = ValidateName()); };
ValidateName();
}
示例6: Run
protected override void Run(RefactoringOptions options)
{
if (renameRefactoring.IsValid (options))
{
renameRefactoring.Run (options);
}
}
示例7: PerformChanges
public override List<Change> PerformChanges(RefactoringOptions options, object prop)
{
#region Init
var renameProperties = prop as RenameProperties;
if (renameProperties == null) return null;
var changes = new List<Change>();
var doc = options.Document;
if (doc == null) return null;
var ddoc = doc.ParsedDocument as ParsedDModule;
if (ddoc == null) return null;
var n = options.SelectedItem as INode;
if (n == null) return null;
var project = doc.HasProject ? doc.Project as DProject : null;
var parseCache = project != null ?
project.ParseCache :
ParseCacheList.Create(DCompilerService.Instance.GetDefaultCompiler().ParseCache);
var modules = project == null ?
(IEnumerable<DModule>)new[] { (Ide.IdeApp.Workbench.ActiveDocument.ParsedDocument as ParsedDModule).DDom } :
project.LocalFileCache;
var ctxt = ResolutionContext.Create(parseCache, null,null);
#endregion
// Enumerate references
foreach (var mod in modules)
{
if (mod == null)
continue;
var references = D_Parser.Refactoring.ReferencesFinder.Scan(mod, n, ctxt).ToList();
if (((DModule)n.NodeRoot).FileName == mod.FileName)
references.Insert(0, new IdentifierDeclaration(n.Name) { Location = n.NameLocation });
if (references.Count < 1)
continue;
var txt = TextFileProvider.Instance.GetEditableTextFile(new FilePath(mod.FileName));
foreach (ISyntaxRegion reference in references)
{
changes.Add(new TextReplaceChange {
FileName = mod.FileName,
InsertedText = renameProperties.NewName,
RemovedChars = n.Name.Length,
Description = string.Format (GettextCatalog.GetString ("Replace '{0}' with '{1}'"), n.Name, renameProperties.NewName),
Offset = txt.GetPositionFromLineColumn(reference.Location.Line, reference.Location.Column)
});
}
}
return changes;
}
示例8: ProcessSelection
public void ProcessSelection(IEnumerable<IRefactorTask> tasks, RefactoringOptions options)
{
Options = options;
var displayableTasks = tasks.ToList();
displayableTasks.Add(new CancelRefactoring());
displayableTasks.Reverse ();
selectionDisplay.GetSelectedFix(displayableTasks);
}
示例9: IsValid
public override bool IsValid (RefactoringOptions options)
{
try {
return Analyze (options);
} catch (Exception e) {
LoggingService.LogError ("Exception while create method analyzation", e);
return false;
}
}
示例10: Run
protected override void Run (RefactoringOptions options)
{
RemoveUnusedImportsRefactoring removeUnusedImportsRefactoring = new RemoveUnusedImportsRefactoring ();
SortImportsRefactoring sortImportsRefactoring = new SortImportsRefactoring ();
if (removeUnusedImportsRefactoring.IsValid (options) && sortImportsRefactoring.IsValid (options)) {
sortImportsRefactoring.Run (options);
removeUnusedImportsRefactoring.Run (options);
}
}
示例11: IsValid
public override bool IsValid(RefactoringOptions options)
{
if (options == null)
return false;
var n = options.SelectedItem as INode;
//TODO: Any further node types that cannot be renamed?
return n != null && CanRenameNode(n);
}
示例12: QuickFixDialog
public QuickFixDialog(RefactoringOptions options, RefactoringOperation refactoring)
{
this.refactoring = refactoring;
this.options = options;
this.Build ();
buttonOk.Clicked += OnOKClicked;
this.Title = "Quick Fix";
this.label1.Text = "Are you sure you want to move this type to a new file?";
this.GdkWindow.Opacity = 0.75;
}
示例13: IsValid
public override bool IsValid(RefactoringOptions options)
{
if (context.IsCurrentPositionTypeDeclarationUnmatchingFileName()) {
var types = context.GetTypes ();
if (types == null)
return false;
return types.Count () > 1;
}
return false;
}
示例14: Run
public override void Run (RefactoringOptions options)
{
ExtractMethodParameters param = CreateParameters (options);
if (param == null)
return;
if (!Analyze (options, param, false)) {
MessageService.ShowError (GettextCatalog.GetString ("Invalid selection for method extraction."));
return;
}
MessageService.ShowCustomDialog (new ExtractMethodDialog (options, this, param));
}
示例15: CreateIVarDialog
public CreateIVarDialog(RefactoringOperation refactoring, RefactoringOptions options, MonobjcProject project)
: base(refactoring, options, project)
{
this.Build ();
this.buttonOk.Sensitive = false;
this.entryName.Changed += delegate { this.buttonOk.Sensitive = this.Validate (); };
this.entryType.Changed += delegate { this.buttonOk.Sensitive = this.Validate (); };
this.Validate ();
this.buttonOk.Clicked += OnOKClicked;
}