internal IEnumerable<CodeIssue> ToMonoDevelopRepresentation (CancellationToken cancellationToken, MDRefactoringContext context, IEnumerable<ICSharpCode.NRefactory.CSharp.Refactoring.CodeIssue> issues)
		{
			var actionGroups = new Dictionary<object, IList<ICSharpCode.NRefactory.CSharp.Refactoring.CodeAction>> ();
			foreach (var issue in issues) {
				if (cancellationToken.IsCancellationRequested)
					yield break;
				if (issue.Actions == null) {
					LoggingService.LogError ("NRefactory actions == null in :" + Title);
					continue;
				}
				var actions = new List<NRefactoryCodeAction> ();
				foreach (var act in GetActions(issue, context)) {
					if (cancellationToken.IsCancellationRequested)
						yield break;
					if (act == null) {
						LoggingService.LogError ("NRefactory issue action was null in :" + Title);
						continue;
					}
					var nrefactoryCodeAction = new NRefactoryCodeAction (IdString, act.Description, act, act.SiblingKey);
					if (act.SiblingKey != null) {
						// make sure the action has a list of its siblings
						IList<ICSharpCode.NRefactory.CSharp.Refactoring.CodeAction> siblingGroup;
						if (!actionGroups.TryGetValue (act.SiblingKey, out siblingGroup)) {
							siblingGroup = new List<ICSharpCode.NRefactory.CSharp.Refactoring.CodeAction> ();
							actionGroups.Add (act.SiblingKey, siblingGroup);
						}
						siblingGroup.Add (act);
						nrefactoryCodeAction.SiblingActions = siblingGroup;
					}
					actions.Add (nrefactoryCodeAction);
				}
				yield return new CodeIssue (issue.IssueMarker, GettextCatalog.GetString (issue.Description ?? ""), context.TextEditor.FileName, issue.Start, issue.End, IdString, actions);
			}
		}	
Пример #2
0
		public override IEnumerable<CodeIssue> GetIssues (object ctx, CancellationToken cancellationToken)
		{
			var context = ctx as MDRefactoringContext;
			if (context == null || context.IsInvalid || context.RootNode == null || context.ParsedDocument.HasErrors)
				yield break;
				
			// Holds all the actions in a particular sibling group.
			var actionGroups = new Dictionary<object, IList<ICSharpCode.NRefactory.CSharp.Refactoring.CodeAction>> ();
			IList<ICSharpCode.NRefactory.CSharp.Refactoring.CodeIssue> issues;
			using (var timer = counter.BeginTiming ()) {
				// We need to enumerate here in order to time it. 
				// This shouldn't be a problem since there are current very few (if any) lazy providers.
				var _issues = issueProvider.GetIssues (context);
				issues = _issues as IList<ICSharpCode.NRefactory.CSharp.Refactoring.CodeIssue> ?? _issues.ToList ();
			}
			foreach (var action in issues) {
				if (cancellationToken.IsCancellationRequested)
					yield break;
				if (action.Actions == null) {
					LoggingService.LogError ("NRefactory actions == null in :" + Title);
					continue;
				}
				var actions = new List<NRefactoryCodeAction> ();
				foreach (var act in action.Actions) {
					if (cancellationToken.IsCancellationRequested)
						yield break;
					if (act == null) {
						LoggingService.LogError ("NRefactory issue action was null in :" + Title);
						continue;
					}
					var nrefactoryCodeAction = new NRefactoryCodeAction (IdString, act.Description, act, act.SiblingKey);
					if (act.SiblingKey != null) {
						// make sure the action has a list of its siblings
						IList<ICSharpCode.NRefactory.CSharp.Refactoring.CodeAction> siblingGroup;
						if (!actionGroups.TryGetValue (act.SiblingKey, out siblingGroup)) {
							siblingGroup = new List<ICSharpCode.NRefactory.CSharp.Refactoring.CodeAction> ();
							actionGroups.Add (act.SiblingKey, siblingGroup);
						}
						siblingGroup.Add (act);
						nrefactoryCodeAction.SiblingActions = siblingGroup;
					}
					actions.Add (nrefactoryCodeAction);
				}
				var issue = new CodeIssue (
					GettextCatalog.GetString (action.Description ?? ""),
					context.TextEditor.FileName,
					action.Start,
					action.End,
					IdString,
					actions
				);
				yield return issue;
			}
		}