1 | // |
---|
2 | // CodeAction.cs |
---|
3 | // |
---|
4 | // Author: |
---|
5 | // Mike KrÃŒger <mkrueger@xamarin.com> |
---|
6 | // |
---|
7 | // Copyright (c) 2012 Xamarin Inc. (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 ICSharpCode.NRefactory.Refactoring; |
---|
28 | |
---|
29 | namespace ICSharpCode.NRefactory.CSharp.Refactoring |
---|
30 | { |
---|
31 | /// <summary> |
---|
32 | /// A code action provides a code transformation with a description. |
---|
33 | /// </summary> |
---|
34 | public class CodeAction |
---|
35 | { |
---|
36 | /// <summary> |
---|
37 | /// Gets the description. |
---|
38 | /// </summary> |
---|
39 | public string Description { |
---|
40 | get; |
---|
41 | private set; |
---|
42 | } |
---|
43 | |
---|
44 | /// <summary> |
---|
45 | /// Gets the code transformation. |
---|
46 | /// </summary> |
---|
47 | public Action<Script> Run { |
---|
48 | get; |
---|
49 | private set; |
---|
50 | } |
---|
51 | |
---|
52 | /// <summary> |
---|
53 | /// Gets the action start location. |
---|
54 | /// </summary> |
---|
55 | public TextLocation Start { |
---|
56 | get; |
---|
57 | private set; |
---|
58 | } |
---|
59 | |
---|
60 | /// <summary> |
---|
61 | /// Gets the action end location. |
---|
62 | /// </summary> |
---|
63 | public TextLocation End { |
---|
64 | get; |
---|
65 | private set; |
---|
66 | } |
---|
67 | |
---|
68 | /// <summary> |
---|
69 | /// This property is used to identify which actions are "siblings", ie which actions |
---|
70 | /// are the same kind of fix. This is used to group issues when batch fixing them. |
---|
71 | /// </summary> |
---|
72 | /// <remarks> |
---|
73 | /// Although the type is <see cref="object"/>, there is a restriction: The instance |
---|
74 | /// used must behave well as a key (for instance in a hash table). Additionaly, this |
---|
75 | /// value must be independent of the specific <see cref="CodeIssueProvider"/> instance |
---|
76 | /// which created it. In other words two different instances of the same issue provider |
---|
77 | /// implementation should use the same sibling keys for the same kinds of issues. |
---|
78 | /// </remarks> |
---|
79 | /// <value>The non-null sibling key if this type of action is batchable, null otherwise.</value> |
---|
80 | public object SiblingKey { |
---|
81 | get; |
---|
82 | private set; |
---|
83 | } |
---|
84 | |
---|
85 | Severity severity = Severity.Suggestion; |
---|
86 | |
---|
87 | /// <summary> |
---|
88 | /// Gets or sets the severity of the code action. |
---|
89 | /// Actions are sorted according to their Severity. |
---|
90 | /// </summary> |
---|
91 | /// <value>The severity.</value> |
---|
92 | public Severity Severity { |
---|
93 | get { |
---|
94 | return severity; |
---|
95 | } |
---|
96 | set { |
---|
97 | severity = value; |
---|
98 | } |
---|
99 | } |
---|
100 | |
---|
101 | const string defaultSiblingKey = "default"; |
---|
102 | |
---|
103 | /// <summary> |
---|
104 | /// Initializes a new instance of the <see cref="ICSharpCode.NRefactory.CSharp.Refactoring.CodeAction"/> class, |
---|
105 | /// using a non-null default value for <see cref="SiblingKey"/>. |
---|
106 | /// </summary> |
---|
107 | /// <param name='description'> |
---|
108 | /// The description. |
---|
109 | /// </param> |
---|
110 | /// <param name='action'> |
---|
111 | /// The code transformation. |
---|
112 | /// </param> |
---|
113 | /// <param name='astNode'> |
---|
114 | /// A node that specifies the start/end positions for the code action. |
---|
115 | /// </param> |
---|
116 | public CodeAction (string description, Action<Script> action, AstNode astNode) |
---|
117 | : this (description, action, astNode, defaultSiblingKey) |
---|
118 | { |
---|
119 | } |
---|
120 | |
---|
121 | /// <summary> |
---|
122 | /// Initializes a new instance of the <see cref="ICSharpCode.NRefactory.CSharp.Refactoring.CodeAction"/> class. |
---|
123 | /// </summary> |
---|
124 | /// <param name='description'> |
---|
125 | /// The description. |
---|
126 | /// </param> |
---|
127 | /// <param name='action'> |
---|
128 | /// The code transformation. |
---|
129 | /// </param> |
---|
130 | /// <param name='astNode'> |
---|
131 | /// A node that specifies the start/end positions for the code action. |
---|
132 | /// </param> |
---|
133 | /// <param name="siblingKey> |
---|
134 | /// The key used to associate this action with other actions that should be fixed together in batch mode. |
---|
135 | /// </param> |
---|
136 | public CodeAction (string description, Action<Script> action, AstNode astNode, object siblingKey) |
---|
137 | { |
---|
138 | if (action == null) |
---|
139 | throw new ArgumentNullException ("action"); |
---|
140 | if (description == null) |
---|
141 | throw new ArgumentNullException ("description"); |
---|
142 | if (astNode == null) |
---|
143 | throw new ArgumentNullException("astNode"); |
---|
144 | Description = description; |
---|
145 | Run = action; |
---|
146 | Start = astNode.StartLocation; |
---|
147 | End = astNode.EndLocation; |
---|
148 | SiblingKey = siblingKey; |
---|
149 | } |
---|
150 | |
---|
151 | /// <summary> |
---|
152 | /// Initializes a new instance of the <see cref="ICSharpCode.NRefactory.CSharp.Refactoring.CodeAction"/> class, |
---|
153 | /// using a non-null default value for <see cref="SiblingKey"/>. |
---|
154 | /// </summary> |
---|
155 | /// <param name='description'> |
---|
156 | /// The description. |
---|
157 | /// </param> |
---|
158 | /// <param name='action'> |
---|
159 | /// The code transformation. |
---|
160 | /// </param> |
---|
161 | /// <param name='start'>Start position for the code action.</param> |
---|
162 | /// <param name='end'>End position for the code action.</param> |
---|
163 | public CodeAction (string description, Action<Script> action, TextLocation start, TextLocation end) |
---|
164 | : this (description, action, start, end, defaultSiblingKey) |
---|
165 | { |
---|
166 | SiblingKey = defaultSiblingKey; |
---|
167 | } |
---|
168 | |
---|
169 | /// <summary> |
---|
170 | /// Initializes a new instance of the <see cref="ICSharpCode.NRefactory.CSharp.Refactoring.CodeAction"/> class. |
---|
171 | /// </summary> |
---|
172 | /// <param name='description'> |
---|
173 | /// The description. |
---|
174 | /// </param> |
---|
175 | /// <param name='action'> |
---|
176 | /// The code transformation. |
---|
177 | /// </param> |
---|
178 | /// <param name='start'>Start position for the code action.</param> |
---|
179 | /// <param name='end'>End position for the code action.</param> |
---|
180 | /// <param name="siblingKey> |
---|
181 | /// The key used to associate this action with other actions that should be fixed together in batch mode. |
---|
182 | /// </param> |
---|
183 | public CodeAction (string description, Action<Script> action, TextLocation start, TextLocation end, object siblingKey) |
---|
184 | { |
---|
185 | if (action == null) |
---|
186 | throw new ArgumentNullException ("action"); |
---|
187 | if (description == null) |
---|
188 | throw new ArgumentNullException ("description"); |
---|
189 | Description = description; |
---|
190 | Run = action; |
---|
191 | this.Start = start; |
---|
192 | this.End = end; |
---|
193 | SiblingKey = siblingKey; |
---|
194 | } |
---|
195 | } |
---|
196 | } |
---|
197 | |
---|