Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CodeIssueProvider.cs « MonoDevelop.CodeIssues « MonoDevelop.Refactoring « addins « src « main - github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d9a2abe2ef6987543d3a24354ae13a70720ffcfd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
// 
// IInspector.cs
//  
// Author:
//       Mike Krüger <mkrueger@xamarin.com>
// 
// Copyright (c) 2012 Xamarin <http://xamarin.com>
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System.Collections.Generic;
using System.Threading;
using MonoDevelop.Core;
using ICSharpCode.NRefactory.Refactoring;
using Mono.TextEditor;
using System;

namespace MonoDevelop.CodeIssues
{
	public abstract class BaseCodeIssueProvider
	{
		public virtual CodeIssueProvider Parent {
			get {
				return null;
			}
		}
		/// <summary>
		/// Gets or sets the type of the MIME the provider is attached to.
		/// </summary>
		public abstract string MimeType {
			get;
		}

		/// <summary>
		/// Gets or sets the title of the issue provider (used in the option panel).
		/// </summary>
		public string Title { get; set; }

		/// <summary>
		/// Gets or sets the description of the issue provider (used in the option panel).
		/// </summary>
		public string Description { get; set; }

		
		/// <summary>
		/// Gets the identifier string used as property ID tag.
		/// </summary>
		public virtual string IdString {
			get {
				return "refactoring.codeissues." + MimeType + "." + GetType ().FullName;
			}
		}

		/// <summary>
		/// Gets or sets the default severity. Note that GetSeverity () should be called to get the valid value inside the IDE.
		/// </summary>
		public Severity DefaultSeverity { get; set; }

		/// <summary>
		/// Gets or sets a value indicating whether this issue is enabled. Note that GetIsEnabled () should be called to get the valid value inside the IDE.
		/// </summary>
		/// <value><c>true</c> if this instance is enabled; otherwise, <c>false</c>.</value>
		public bool IsEnabledByDefault { get; set; }

		/// <summary>
		/// Gets the current (user defined) severity.
		/// </summary>
		protected Severity severity;

		public Severity GetSeverity ()
		{
			return severity;
		}

		/// <summary>
		/// Sets the user defined severity.
		/// </summary>
		public void SetSeverity (Severity severity)
		{
			if (this.severity == severity)
				return;
			this.severity = severity;
			PropertyService.Set (IdString, severity);
		}


		protected bool isEnabled;
		
		public bool GetIsEnabled ()
		{
			return isEnabled;
		}
		
		/// <summary>
		/// Sets the user defined severity.
		/// </summary>
		public void SetIsEnabled (bool isEnabled)
		{
			if (this.isEnabled == isEnabled)
				return;
			this.isEnabled = isEnabled;
			PropertyService.Set (IdString + ".isEnabled", isEnabled);
		}

		protected void UpdateSeverity ()
		{
			severity = PropertyService.Get<Severity> (IdString, DefaultSeverity);
			isEnabled = PropertyService.Get<bool> (IdString+ ".isEnabled", IsEnabledByDefault);
		}

		/// <summary>
		/// Gets all the code issues inside a document.
		/// </summary>
		public abstract IEnumerable<CodeIssue> GetIssues (object refactoringContext, CancellationToken cancellationToken);

		public virtual bool CanDisableOnce { get { return false; } }

		public virtual bool CanDisableAndRestore { get { return false; } }

		public virtual bool CanDisableWithPragma { get { return false; } }

		public virtual bool CanSuppressWithAttribute { get { return false; } }

		public virtual void DisableOnce (MonoDevelop.Ide.Gui.Document document, DocumentRegion loc)
		{
			throw new NotSupportedException ();
		}

		public virtual void DisableAndRestore (MonoDevelop.Ide.Gui.Document document, DocumentRegion loc)
		{
			throw new NotSupportedException ();
		}

		public virtual void DisableWithPragma (MonoDevelop.Ide.Gui.Document document, DocumentRegion loc)
		{
			throw new NotSupportedException ();
		}

		public virtual void SuppressWithAttribute (MonoDevelop.Ide.Gui.Document document, DocumentRegion loc)
		{
			throw new NotSupportedException ();
		}
	}


	/// <summary>
	/// A code issue provider is a factory that creates code issues of a given document.
	/// </summary>
	public abstract class CodeIssueProvider : BaseCodeIssueProvider
	{
		string mimeType;
		public override string MimeType {
			get {
				return mimeType;
			}
		}

		public void SetMimeType (string mimeType)
		{
			this.mimeType = mimeType;
			UpdateSeverity ();
		}

		/// <summary>
		/// Gets or sets the category of the issue provider (used in the option panel).
		/// </summary>
		public string Category { get; set; }

		/// <summary>
		/// If true this issue has sub issues.
		/// </summary>
		public abstract bool HasSubIssues { get; }

		/// <summary>
		/// Gets the sub issues of this issue. If HasSubIssus == false an InvalidOperationException is thrown.
		/// </summary>
		public virtual IEnumerable<BaseCodeIssueProvider> SubIssues { get { throw new InvalidOperationException (); } }

		/// <summary>
		/// Gets the effective set of providers. The effective set of providers
		/// is either the sub issues (if it has sub issues) or simply itself (otherwise).
		/// </summary>
		/// <returns>The effective provider set.</returns>
		public IEnumerable<BaseCodeIssueProvider> GetEffectiveProviderSet()
		{
			if (HasSubIssues)
				return SubIssues;
			return new[] { this };
		}
	}
}