本文整理汇总了C#中RefactoringOptions类的典型用法代码示例。如果您正苦于以下问题:C# RefactoringOptions类的具体用法?C# RefactoringOptions怎么用?C# RefactoringOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RefactoringOptions类属于命名空间,在下文中一共展示了RefactoringOptions类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Run
public override void Run (RefactoringOptions options)
{
base.Run (options);
TextEditorData data = options.GetTextEditorData ();
Mono.TextEditor.TextEditor editor = data.Parent;
List<TextLink> links = new List<TextLink> ();
TextLink link = new TextLink ("name");
int referenceCount = 1;
MemberResolveResult resolveResult = options.ResolveResult as MemberResolveResult;
IProperty property = resolveResult.ResolvedMember as IProperty;
if (property.HasGet)
referenceCount++;
if (property.HasSet)
referenceCount++;
for (int i = refactoringStartOffset; i < data.Document.Length - backingStoreName.Length; i++) {
if (data.Document.GetTextAt (i, backingStoreName.Length) == backingStoreName) {
link.AddLink (new Segment (i - refactoringStartOffset, backingStoreName.Length));
if (link.Count == referenceCount)
break;
}
}
links.Add (link);
TextLinkEditMode tle = new TextLinkEditMode (editor, refactoringStartOffset, links);
tle.SetCaretPosition = false;
if (tle.ShouldStartTextLinkMode) {
tle.OldMode = data.CurrentMode;
tle.StartMode ();
data.CurrentMode = tle;
}
}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:33,代码来源:CreateBackingStore.cs
示例2: InternalIsValid
internal static bool InternalIsValid (RefactoringOptions options, out IType interfaceType)
{
var unit = options.Document.ParsedDocument.GetAst<CompilationUnit> ();
interfaceType = null;
if (unit == null)
return false;
var loc = options.Document.Editor.Caret.Location;
var declaration = unit.GetNodeAt<TypeDeclaration> (loc.Line, loc.Column);
if (declaration == null)
return false;
if (!declaration.BaseTypes.Any (bt => bt.Contains (loc.Line, loc.Column)))
return false;
if (options.ResolveResult == null)
return false;
interfaceType = options.ResolveResult.Type;
var def = interfaceType.GetDefinition ();
if (def == null)
return false;
if (def.Kind != TypeKind.Interface)
return false;
var declaringType = options.Document.ParsedDocument.GetInnermostTypeDefinition (loc);
var type = declaringType.Resolve (options.Document.ParsedDocument.ParsedFile.GetTypeResolveContext (options.Document.Compilation, loc)).GetDefinition ();
return interfaceType.GetAllBaseTypes ().Any (bt => CodeGenerator.CollectMembersToImplement (type, bt, false).Any ());
}
开发者ID:head-thrash,项目名称:monodevelop,代码行数:25,代码来源:ImplementExplicit.cs
示例3: GetMenuDescription
public override string GetMenuDescription (RefactoringOptions options)
{
IType type = options.SelectedItem as IType;
if (type.CompilationUnit.Types.Count == 1)
return String.Format (GettextCatalog.GetString ("_Rename file to '{0}'"), Path.GetFileName (GetCorrectFileName (type)));
return String.Format (GettextCatalog.GetString ("_Move type to file '{0}'"), Path.GetFileName (GetCorrectFileName (type)));
}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:7,代码来源:MoveTypeToFileRefactoring.cs
示例4: IsValid
public override bool IsValid (RefactoringOptions options)
{
MemberResolveResult resolveResult = options.ResolveResult as MemberResolveResult;
if (resolveResult == null)
return false;
IProperty property = resolveResult.ResolvedMember as IProperty;
if (property == null || resolveResult.CallingMember == null || resolveResult.CallingMember.FullName != property.FullName || !property.HasGet || property.DeclaringType == null)
return false;
TextEditorData data = options.GetTextEditorData ();
if (property.HasGet && data.Document.GetCharAt (data.Document.LocationToOffset (property.GetRegion.End.Line, property.GetRegion.End.Column - 1)) == ';')
return false;
if (property.HasSet && data.Document.GetCharAt (data.Document.LocationToOffset (property.SetRegion.End.Line, property.SetRegion.End.Column - 1)) == ';')
return false;
INRefactoryASTProvider astProvider = options.GetASTProvider ();
string backingStoreName = RetrieveBackingStore (options, astProvider, property);
if (string.IsNullOrEmpty (backingStoreName))
return false;
// look if there is a valid backing store field that doesn't have any attributes.
int backinStoreStart;
int backinStoreEnd;
IField backingStore = GetBackingStoreField (options, backingStoreName, out backinStoreStart, out backinStoreEnd);
if (backingStore == null || backingStore.Attributes.Any ())
return false;
return true;
}
开发者ID:stewartwhaley,项目名称:monodevelop,代码行数:27,代码来源:RemoveBackingStore.cs
示例5: Rename
public static void Rename (IEntity entity, string newName)
{
if (newName == null) {
var options = new RefactoringOptions () {
SelectedItem = entity
};
new RenameRefactoring ().Run (options);
return;
}
using (var monitor = new NullProgressMonitor ()) {
var col = ReferenceFinder.FindReferences (entity, true, monitor);
List<Change> result = new List<Change> ();
foreach (var memberRef in col) {
var change = new TextReplaceChange ();
change.FileName = memberRef.FileName;
change.Offset = memberRef.Offset;
change.RemovedChars = memberRef.Length;
change.InsertedText = newName;
change.Description = string.Format (GettextCatalog.GetString ("Replace '{0}' with '{1}'"), memberRef.GetName (), newName);
result.Add (change);
}
if (result.Count > 0) {
RefactoringService.AcceptChanges (monitor, result);
}
}
}
开发者ID:RainsSoft,项目名称:playscript-monodevelop,代码行数:27,代码来源:RenameRefactoring.cs
示例6: RenameCommand_Update
public void RenameCommand_Update(CommandInfo ci)
{
var doc = IdeApp.Workbench.ActiveDocument;
if (doc == null)
return;
var editor = doc.GetContent<ITextBuffer>();
if (editor == null)
return;
var dom = doc.Dom;
ResolveResult result;
INode item;
CurrentRefactoryOperationsHandler.GetItem(dom, doc, editor, out result, out item);
var options = new RefactoringOptions()
{
Document = doc,
Dom = dom,
ResolveResult = result,
SelectedItem = item is InstantiatedType ? ((InstantiatedType)item).UninstantiatedType : item
};
// If not a valid operation, allow command to be handled by others
if (!new RenameRefactoring().IsValid(options))
ci.Bypass = true;
}
开发者ID:awatertree,项目名称:monodevelop,代码行数:28,代码来源:RenameTextEditorExtension.cs
示例7: Run
public override void Run (RefactoringOptions options)
{
DocumentLocation location = options.GetTextEditorData ().Caret.Location;
IType interfaceType = options.Dom.GetType (options.ResolveResult.ResolvedType);
IType declaringType = options.Document.CompilationUnit.GetTypeAt (location.Line, location.Column);
var editor = options.GetTextEditorData ().Parent;
InsertionCursorEditMode mode = new InsertionCursorEditMode (editor, HelperMethods.GetInsertionPoints (editor.Document, declaringType));
ModeHelpWindow helpWindow = new ModeHelpWindow ();
helpWindow.TransientFor = IdeApp.Workbench.RootWindow;
helpWindow.TitleText = GettextCatalog.GetString ("<b>Implement Interface -- Targeting</b>");
helpWindow.Items.Add (new KeyValuePair<string, string> (GettextCatalog.GetString ("<b>Key</b>"), GettextCatalog.GetString ("<b>Behavior</b>")));
helpWindow.Items.Add (new KeyValuePair<string, string> (GettextCatalog.GetString ("<b>Up</b>"), GettextCatalog.GetString ("Move to <b>previous</b> target point.")));
helpWindow.Items.Add (new KeyValuePair<string, string> (GettextCatalog.GetString ("<b>Down</b>"), GettextCatalog.GetString ("Move to <b>next</b> target point.")));
helpWindow.Items.Add (new KeyValuePair<string, string> (GettextCatalog.GetString ("<b>Enter</b>"), GettextCatalog.GetString ("<b>Declare interface implementation</b> at target point.")));
helpWindow.Items.Add (new KeyValuePair<string, string> (GettextCatalog.GetString ("<b>Esc</b>"), GettextCatalog.GetString ("<b>Cancel</b> this refactoring.")));
mode.HelpWindow = helpWindow;
mode.CurIndex = mode.InsertionPoints.Count - 1;
mode.StartMode ();
mode.Exited += delegate(object s, InsertionCursorEventArgs args) {
if (args.Success) {
CodeGenerator generator = options.Document.CreateCodeGenerator ();
args.InsertionPoint.Insert (editor, generator.CreateInterfaceImplementation (declaringType, interfaceType, false));
}
};
}
开发者ID:pgoron,项目名称:monodevelop,代码行数:27,代码来源:ImplementImplicit.cs
示例8: InternalRun
internal static void InternalRun (RefactoringOptions options, bool implementExplicit)
{
IType interfaceType;
if (!InternalIsValid (options, out interfaceType))
return;
var loc = options.Document.Editor.Caret.Location;
var declaringType = options.Document.ParsedDocument.GetInnermostTypeDefinition (loc);
if (declaringType == null)
return;
var editor = options.GetTextEditorData ().Parent;
var mode = new InsertionCursorEditMode (editor, CodeGenerationService.GetInsertionPoints (options.Document, declaringType));
var helpWindow = new InsertionCursorLayoutModeHelpWindow ();
helpWindow.TransientFor = IdeApp.Workbench.RootWindow;
helpWindow.TitleText = GettextCatalog.GetString ("Implement Interface");
mode.HelpWindow = helpWindow;
mode.CurIndex = mode.InsertionPoints.Count - 1;
mode.StartMode ();
mode.Exited += delegate(object s, InsertionCursorEventArgs args) {
if (args.Success) {
var generator = options.CreateCodeGenerator ();
if (generator == null)
return;
var type = declaringType.Resolve (options.Document.ParsedDocument.GetTypeResolveContext (options.Document.Compilation, loc)).GetDefinition ();
args.InsertionPoint.Insert (options.GetTextEditorData (), generator.CreateInterfaceImplementation (type, declaringType, interfaceType, implementExplicit));
}
};
}
开发者ID:nocache,项目名称:monodevelop,代码行数:30,代码来源:ImplementExplicit.cs
示例9: IsValid
public override bool IsValid (RefactoringOptions options)
{
INRefactoryASTProvider provider = options.GetASTProvider ();
IResolver resolver = options.GetResolver ();
if (provider == null || resolver == null)
return false;
if (invoke == null)
invoke = GetInvocationExpression (options);
if (invoke == null)
return false;
returnType = DomReturnType.Void;
modifiers = ICSharpCode.NRefactory.Ast.Modifiers.None;
resolvePosition = new DomLocation (options.Document.Editor.Caret.Line + 1, options.Document.Editor.Caret.Column + 1);
ResolveResult resolveResult = resolver.Resolve (new ExpressionResult (provider.OutputNode (options.Dom, invoke)), resolvePosition);
if (resolveResult is MethodResolveResult) {
MethodResolveResult mrr = (MethodResolveResult)resolveResult ;
if (mrr.ExactMethodMatch)
return false;
returnType = mrr.MostLikelyMethod.ReturnType;
modifiers = (ICSharpCode.NRefactory.Ast.Modifiers)mrr.MostLikelyMethod.Modifiers;
}
if (invoke.TargetObject is MemberReferenceExpression) {
string callingObject = provider.OutputNode (options.Dom, ((MemberReferenceExpression)invoke.TargetObject).TargetObject);
resolveResult = resolver.Resolve (new ExpressionResult (callingObject), resolvePosition);
if (resolveResult == null || resolveResult.ResolvedType == null || resolveResult.CallingType == null)
return false;
IType type = options.Dom.GetType (resolveResult.ResolvedType);
return type != null && type.CompilationUnit != null && File.Exists (type.CompilationUnit.FileName) && RefactoringService.GetASTProvider (DesktopService.GetMimeTypeForUri (type.CompilationUnit.FileName)) != null;
}
return invoke.TargetObject is IdentifierExpression;
}
开发者ID:acken,项目名称:monodevelop,代码行数:33,代码来源:CreateMethodCodeGenerator.cs
示例10: IsValid
public override bool IsValid (RefactoringOptions options)
{
IResolver resolver = options.GetResolver ();
INRefactoryASTProvider provider = options.GetASTProvider ();
if (resolver == null || provider == null)
return false;
TextEditorData data = options.GetTextEditorData ();
if (data == null)
return false;
ResolveResult resolveResult;
if (data.IsSomethingSelected) {
ExpressionResult expressionResult = new ExpressionResult (data.SelectedText.Trim ());
if (expressionResult.Expression.Contains (" ") || expressionResult.Expression.Contains ("\t"))
expressionResult.Expression = "(" + expressionResult.Expression + ")";
resolveResult = resolver.Resolve (expressionResult, new DomLocation (data.Caret.Line, data.Caret.Column));
if (resolveResult == null)
return false;
return true;
}
LineSegment lineSegment = data.Document.GetLine (data.Caret.Line);
string line = data.Document.GetTextAt (lineSegment);
Expression expression = provider.ParseExpression (line);
BlockStatement block = provider.ParseText (line) as BlockStatement;
if (expression == null || (block != null && block.Children[0] is LocalVariableDeclaration))
return false;
resolveResult = resolver.Resolve (new ExpressionResult (line), new DomLocation (options.Document.Editor.Caret.Line, options.Document.Editor.Caret.Column));
return resolveResult.ResolvedType != null && !string.IsNullOrEmpty (resolveResult.ResolvedType.FullName) && resolveResult.ResolvedType.FullName != DomReturnType.Void.FullName;
}
开发者ID:pgoron,项目名称:monodevelop,代码行数:29,代码来源:DeclareLocalCodeGenerator.cs
示例11: IsValid
public override bool IsValid (RefactoringOptions options)
{
TextEditorData data = options.GetTextEditorData ();
LineSegment line = data.Document.GetLine (data.Caret.Line);
if (!data.IsSomethingSelected && line != null) {
var stack = line.StartSpan.Clone ();
Mono.TextEditor.Highlighting.SyntaxModeService.ScanSpans (data.Document, data.Document.SyntaxMode, data.Document.SyntaxMode, stack, line.Offset, data.Caret.Offset);
foreach (Span span in stack) {
if (span.Color == "string.single" || span.Color == "string.double")
return options.Document.CompilationUnit.GetMemberAt (data.Caret.Line, data.Caret.Column) != null;
}
}
INRefactoryASTProvider provider = options.GetASTProvider ();
if (provider == null)
return false;
string expressionText = null;
if (options.ResolveResult != null && options.ResolveResult.ResolvedExpression != null)
expressionText = options.ResolveResult.ResolvedExpression.Expression;
if (string.IsNullOrEmpty (expressionText)) {
int start, end;
expressionText = SearchNumber (data, out start, out end);
}
Expression expression = provider.ParseExpression (expressionText);
return expression is PrimitiveExpression;
}
开发者ID:Tak,项目名称:monodevelop-novell,代码行数:28,代码来源:IntroduceConstantRefactoring.cs
示例12: IsValid
public override bool IsValid (RefactoringOptions options)
{
IType type = options.SelectedItem as IType;
string fileName = GetCorrectFileName (type);
if (type == null || string.IsNullOrEmpty (fileName) || File.Exists (fileName) || type.DeclaringType != null)
return false;
return Path.GetFileNameWithoutExtension (type.CompilationUnit.FileName) != type.Name;
}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:8,代码来源:MoveTypeToFileRefactoring.cs
示例13: IsValid
public override bool IsValid (RefactoringOptions options)
{
if (options.ResolveResult == null || options.ResolveResult.ResolvedExpression == null)
return false;
if (options.Dom.GetType (options.ResolveResult.ResolvedType) != null)
return false;
createExpression = GetCreateExpression (options);
return createExpression != null;
}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:9,代码来源:CreateClassCodeGenerator.cs
示例14: IsValid
public override bool IsValid (RefactoringOptions options)
{
if (options.ResolveResult == null)
return false;
IType type = options.Dom.GetType (options.ResolveResult.ResolvedType);
if (type == null || type.ClassType != MonoDevelop.Projects.Dom.ClassType.Class)
return false;
return CurrentRefactoryOperationsHandler.ContainsAbstractMembers (type);
}
开发者ID:okrmartin,项目名称:monodevelop,代码行数:10,代码来源:ImplementAbstractMembers.cs
示例15: Run
public override void Run (RefactoringOptions options)
{
DocumentLocation location = options.GetTextEditorData ().Caret.Location;
IType interfaceType = options.Dom.GetType (options.ResolveResult.ResolvedType);
IType declaringType = options.Document.CompilationUnit.GetTypeAt (location.Line, location.Column);
options.Document.Editor.Document.BeginAtomicUndo ();
var missingAbstractMembers = interfaceType.Members.Where (member => member.IsAbstract && !declaringType.Members.Any (m => member.Name == m.Name));
CodeGenerationService.AddNewMembers (declaringType, missingAbstractMembers, "implemented abstract members of " + interfaceType.FullName);
options.Document.Editor.Document.EndAtomicUndo ();
}
开发者ID:okrmartin,项目名称:monodevelop,代码行数:11,代码来源:ImplementAbstractMembers.cs
示例16: Run
public override void Run (RefactoringOptions options)
{
if (options.SelectedItem is LocalVariable || options.SelectedItem is IParameter) {
var col = ReferenceFinder.FindReferences (options.SelectedItem);
if (col == null)
return;
TextEditorData data = options.GetTextEditorData ();
Mono.TextEditor.TextEditor editor = data.Parent;
if (editor == null) {
MessageService.ShowCustomDialog (new RenameItemDialog (options, this));
return;
}
List<TextLink> links = new List<TextLink> ();
TextLink link = new TextLink ("name");
int baseOffset = Int32.MaxValue;
foreach (MemberReference r in col) {
baseOffset = Math.Min (baseOffset, data.Document.LocationToOffset (r.Line, r.Column));
}
foreach (MemberReference r in col) {
Segment segment = new Segment (data.Document.LocationToOffset (r.Line, r.Column) - baseOffset, r.Name.Length);
if (segment.Offset <= data.Caret.Offset - baseOffset && data.Caret.Offset - baseOffset <= segment.EndOffset) {
link.Links.Insert (0, segment);
} else {
link.AddLink (segment);
}
}
links.Add (link);
if (editor.CurrentMode is TextLinkEditMode)
((TextLinkEditMode)editor.CurrentMode).ExitTextLinkMode ();
TextLinkEditMode tle = new TextLinkEditMode (editor, baseOffset, links);
tle.SetCaretPosition = false;
tle.SelectPrimaryLink = true;
if (tle.ShouldStartTextLinkMode) {
ModeHelpWindow helpWindow = new ModeHelpWindow ();
helpWindow.TransientFor = IdeApp.Workbench.RootWindow;
helpWindow.TitleText = options.SelectedItem is LocalVariable ? GettextCatalog.GetString ("<b>Local Variable -- Renaming</b>") : GettextCatalog.GetString ("<b>Parameter -- Renaming</b>");
helpWindow.Items.Add (new KeyValuePair<string, string> (GettextCatalog.GetString ("<b>Key</b>"), GettextCatalog.GetString ("<b>Behavior</b>")));
helpWindow.Items.Add (new KeyValuePair<string, string> (GettextCatalog.GetString ("<b>Return</b>"), GettextCatalog.GetString ("<b>Accept</b> this refactoring.")));
helpWindow.Items.Add (new KeyValuePair<string, string> (GettextCatalog.GetString ("<b>Esc</b>"), GettextCatalog.GetString ("<b>Cancel</b> this refactoring.")));
tle.HelpWindow = helpWindow;
tle.Cancel += delegate {
if (tle.HasChangedText)
editor.Document.Undo ();
};
tle.OldMode = data.CurrentMode;
tle.StartMode ();
data.CurrentMode = tle;
}
} else {
MessageService.ShowCustomDialog (new RenameItemDialog (options, this));
}
}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:54,代码来源:RenameRefactoring.cs
示例17: IsValid
public override bool IsValid (RefactoringOptions options)
{
if (!(options.SelectedItem is LocalVariable)) {
// Console.WriteLine ("!!! Item is not LocalVariable");
return false;
}
ICSharpCode.NRefactory.Ast.INode result = GetMemberBodyNode (options);
if (result == null)
return false;
return true;
}
开发者ID:Tak,项目名称:monodevelop-novell,代码行数:11,代码来源:IntegrateTemporaryVariableRefactoring.cs
示例18: Run
public override void Run (RefactoringOptions options)
{
ExtractMethodParameters param = CreateParameters (options);
if (param == null)
return;
if (Analyze (options, param, false) == null || param.VariablesToGenerate == null) {
MessageService.ShowError (GettextCatalog.GetString ("Invalid selection for method extraction."));
return;
}
MessageService.ShowCustomDialog (new ExtractMethodDialog (options, this, param));
}
开发者ID:pgoron,项目名称:monodevelop,代码行数:11,代码来源:ExtractMethodRefactoring.cs
示例19: IsValid
public override bool IsValid (RefactoringOptions options)
{
if (options.ResolveResult == null)
return false;
IType type = options.Dom.GetType (options.ResolveResult.ResolvedType);
if (type == null || type.ClassType != MonoDevelop.Projects.Dom.ClassType.Interface)
return false;
DocumentLocation location = options.GetTextEditorData ().Caret.Location;
IType declaringType = options.Document.CompilationUnit.GetTypeAt (location.Line + 1, location.Column + 1);
return declaringType != null && options.ResolveResult.ResolvedExpression.IsInInheritableTypeContext;
}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:12,代码来源:ImplementExplicit.cs
示例20: IsValid
public override bool IsValid (RefactoringOptions options)
{
if (options.SelectedItem is IVariable || options.SelectedItem is IParameter)
return true;
if (options.SelectedItem is ITypeDefinition)
return !string.IsNullOrEmpty (((ITypeDefinition)options.SelectedItem).Region.FileName);
if (options.SelectedItem is IMember) {
var cls = ((IMember)options.SelectedItem).DeclaringTypeDefinition;
return cls != null;
}
return false;
}
开发者ID:nocache,项目名称:monodevelop,代码行数:13,代码来源:RenameRefactoring.cs
注:本文中的RefactoringOptions类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论