本文整理汇总了C#中RefactoringOptions类的典型用法代码示例。如果您正苦于以下问题:C# RefactoringOptions类的具体用法?C# RefactoringOptions怎么用?C# RefactoringOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RefactoringOptions类属于命名空间,在下文中一共展示了RefactoringOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
}
示例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 ());
}
示例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)));
}
示例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;
}
示例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);
}
}
}
示例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;
}
示例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));
}
};
}
示例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));
}
};
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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 ();
}