1 | // |
---|
2 | // InspectionIssue.cs |
---|
3 | // |
---|
4 | // Author: |
---|
5 | // Mike Krüger <mkrueger@xamarin.com> |
---|
6 | // |
---|
7 | // Copyright (c) 2012 Xamarin <http://xamarin.com> |
---|
8 | // |
---|
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
10 | // of this software and associated documentation files (the "Software"), to deal |
---|
11 | // in the Software without restriction, including without limitation the rights |
---|
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
13 | // copies of the Software, and to permit persons to whom the Software is |
---|
14 | // furnished to do so, subject to the following conditions: |
---|
15 | // |
---|
16 | // The above copyright notice and this permission notice shall be included in |
---|
17 | // all copies or substantial portions of the Software. |
---|
18 | // |
---|
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
25 | // THE SOFTWARE. |
---|
26 | using System; |
---|
27 | using System.Collections.Generic; |
---|
28 | using System.Linq; |
---|
29 | using ICSharpCode.NRefactory.Refactoring; |
---|
30 | |
---|
31 | namespace ICSharpCode.NRefactory.CSharp.Refactoring |
---|
32 | { |
---|
33 | /// <summary> |
---|
34 | /// A code issue marks a region of text with an issue and can provide solution actions for this issue. |
---|
35 | /// </summary> |
---|
36 | public class CodeIssue |
---|
37 | { |
---|
38 | /// <summary> |
---|
39 | /// Gets the description of the issue. |
---|
40 | /// </summary> |
---|
41 | public string Description { |
---|
42 | get; |
---|
43 | private set; |
---|
44 | } |
---|
45 | |
---|
46 | /// <summary> |
---|
47 | /// Gets the issue start location. |
---|
48 | /// </summary> |
---|
49 | public TextLocation Start { |
---|
50 | get; |
---|
51 | private set; |
---|
52 | } |
---|
53 | |
---|
54 | /// <summary> |
---|
55 | /// Gets the issue end location. |
---|
56 | /// </summary> |
---|
57 | public TextLocation End { |
---|
58 | get; |
---|
59 | private set; |
---|
60 | } |
---|
61 | |
---|
62 | /// <summary> |
---|
63 | /// Gets a list of potential solutions for the issue. |
---|
64 | /// </summary> |
---|
65 | public IList<CodeAction> Actions { |
---|
66 | get; |
---|
67 | private set; |
---|
68 | } |
---|
69 | |
---|
70 | List<Type> actionProvider = new List<Type>(); |
---|
71 | public List<Type> ActionProvider { |
---|
72 | get { |
---|
73 | return actionProvider; |
---|
74 | } |
---|
75 | set { |
---|
76 | actionProvider = value; |
---|
77 | } |
---|
78 | } |
---|
79 | |
---|
80 | /// <summary> |
---|
81 | /// Gets or sets the Issue marker which should be used to mark this issue in the editor. |
---|
82 | /// It's up to the editor implementation if and how this info is used. |
---|
83 | /// </summary> |
---|
84 | public IssueMarker IssueMarker { |
---|
85 | get; |
---|
86 | set; |
---|
87 | } |
---|
88 | |
---|
89 | /// <summary> |
---|
90 | /// Initializes a new instance of the <see cref="ICSharpCode.NRefactory.CSharp.Refactoring.CodeIssue"/> class. |
---|
91 | /// </summary> |
---|
92 | public CodeIssue(TextLocation start, TextLocation end, string issueDescription) |
---|
93 | { |
---|
94 | if (issueDescription == null) |
---|
95 | throw new ArgumentNullException("issueDescription"); |
---|
96 | Description = issueDescription; |
---|
97 | Start = start; |
---|
98 | End = end; |
---|
99 | Actions = EmptyList<CodeAction>.Instance; |
---|
100 | IssueMarker = IssueMarker.WavedLine; |
---|
101 | } |
---|
102 | |
---|
103 | /// <summary> |
---|
104 | /// Initializes a new instance of the <see cref="ICSharpCode.NRefactory.CSharp.Refactoring.CodeIssue"/> class. |
---|
105 | /// </summary> |
---|
106 | public CodeIssue(TextLocation start, TextLocation end, string issueDescription, IEnumerable<CodeAction> actions) : this(start, end, issueDescription) |
---|
107 | { |
---|
108 | if (actions != null) |
---|
109 | Actions = actions.ToArray(); |
---|
110 | } |
---|
111 | |
---|
112 | /// <summary> |
---|
113 | /// Initializes a new instance of the <see cref="ICSharpCode.NRefactory.CSharp.Refactoring.CodeIssue"/> class. |
---|
114 | /// </summary> |
---|
115 | public CodeIssue(TextLocation start, TextLocation end, string issueDescription, params CodeAction[] actions) : this(start, end, issueDescription) |
---|
116 | { |
---|
117 | if (actions != null) |
---|
118 | Actions = actions; |
---|
119 | } |
---|
120 | |
---|
121 | /// <summary> |
---|
122 | /// Initializes a new instance of the <see cref="ICSharpCode.NRefactory.CSharp.Refactoring.CodeIssue"/> class. |
---|
123 | /// </summary> |
---|
124 | public CodeIssue(TextLocation start, TextLocation end, string issueDescription, string actionDescription, Action<Script> fix) : this(start, end, issueDescription) |
---|
125 | { |
---|
126 | if (actionDescription == null) |
---|
127 | throw new ArgumentNullException("actionDescription"); |
---|
128 | if (fix == null) |
---|
129 | throw new ArgumentNullException("fix"); |
---|
130 | this.Actions = new [] { new CodeAction(actionDescription, fix, start, end) }; |
---|
131 | } |
---|
132 | |
---|
133 | /// <summary> |
---|
134 | /// Initializes a new instance of the <see cref="ICSharpCode.NRefactory.CSharp.Refactoring.CodeIssue"/> class. |
---|
135 | /// </summary> |
---|
136 | public CodeIssue(AstNode node, string issueDescription) |
---|
137 | { |
---|
138 | if (node == null) |
---|
139 | throw new ArgumentNullException("node"); |
---|
140 | if (issueDescription == null) |
---|
141 | throw new ArgumentNullException("issueDescription"); |
---|
142 | Description = issueDescription; |
---|
143 | Start = node.StartLocation; |
---|
144 | End = node.EndLocation; |
---|
145 | Actions = EmptyList<CodeAction>.Instance; |
---|
146 | IssueMarker = IssueMarker.WavedLine; |
---|
147 | } |
---|
148 | |
---|
149 | /// <summary> |
---|
150 | /// Initializes a new instance of the <see cref="ICSharpCode.NRefactory.CSharp.Refactoring.CodeIssue"/> class. |
---|
151 | /// </summary> |
---|
152 | public CodeIssue(AstNode node, string issueDescription, IEnumerable<CodeAction> actions) : this(node, issueDescription) |
---|
153 | { |
---|
154 | if (actions != null) |
---|
155 | Actions = actions.ToArray(); |
---|
156 | } |
---|
157 | |
---|
158 | /// <summary> |
---|
159 | /// Initializes a new instance of the <see cref="ICSharpCode.NRefactory.CSharp.Refactoring.CodeIssue"/> class. |
---|
160 | /// </summary> |
---|
161 | public CodeIssue(AstNode node, string issueDescription, params CodeAction[] actions) : this(node, issueDescription) |
---|
162 | { |
---|
163 | if (actions != null) |
---|
164 | Actions = actions; |
---|
165 | } |
---|
166 | |
---|
167 | /// <summary> |
---|
168 | /// Initializes a new instance of the <see cref="ICSharpCode.NRefactory.CSharp.Refactoring.CodeIssue"/> class. |
---|
169 | /// </summary> |
---|
170 | public CodeIssue(AstNode node, string issueDescription, string actionDescription, Action<Script> fix) : this(node, issueDescription) |
---|
171 | { |
---|
172 | if (actionDescription == null) |
---|
173 | throw new ArgumentNullException("actionDescription"); |
---|
174 | if (fix == null) |
---|
175 | throw new ArgumentNullException("fix"); |
---|
176 | this.Actions = new [] { new CodeAction(actionDescription, fix, node) }; |
---|
177 | } |
---|
178 | |
---|
179 | } |
---|
180 | } |
---|
181 | |
---|