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

StockIcons.cs « MonoDevelop.Ide.TypeSystem « MonoDevelop.Ide « core « src « main - github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d52111e65f7aae50ddb4d6a7427db52d1cfd5346 (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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
// 
// StockIcons.cs
//  
// Author:
//       Mike Krüger <mkrueger@novell.com>
// 
// Copyright (c) 2011 Mike Krüger <mkrueger@novell.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;
using MonoDevelop.Core;
using Mono.Cecil;
using ICSharpCode.NRefactory6.CSharp;

namespace MonoDevelop.Ide.TypeSystem
{
	public static class Stock
	{
		static readonly IconId Class = "md-class";
		static readonly IconId Enum = "md-enum";
		static readonly IconId Event = "md-event";
		static readonly IconId Field = "md-field";
		static readonly IconId Interface = "md-interface";
		static readonly IconId Method = "md-method";
		static readonly IconId ExtensionMethod = "md-extensionmethod";
		static readonly IconId Property = "md-property";
		static readonly IconId Struct = "md-struct";
		static readonly IconId Delegate = "md-delegate";
		public static readonly IconId Namespace = "md-name-space";

		static readonly IconId InternalClass = "md-internal-class";
		static readonly IconId InternalDelegate = "md-internal-delegate";
		static readonly IconId InternalEnum = "md-internal-enum";
		static readonly IconId InternalEvent = "md-internal-event";
		static readonly IconId InternalField = "md-internal-field";
		static readonly IconId InternalInterface = "md-internal-interface";
		static readonly IconId InternalMethod = "md-internal-method";
		static readonly IconId InternalExtensionMethod = "md-internal-extensionmethod";
		static readonly IconId InternalProperty = "md-internal-property";
		static readonly IconId InternalStruct = "md-internal-struct";

		static readonly IconId InternalAndProtectedClass = "md-InternalAndProtected-class";
		static readonly IconId InternalAndProtectedDelegate = "md-InternalAndProtected-delegate";
		static readonly IconId InternalAndProtectedEnum = "md-InternalAndProtected-enum";
		static readonly IconId InternalAndProtectedEvent = "md-InternalAndProtected-event";
		static readonly IconId InternalAndProtectedField = "md-InternalAndProtected-field";
		static readonly IconId InternalAndProtectedInterface = "md-InternalAndProtected-interface";
		static readonly IconId InternalAndProtectedMethod = "md-InternalAndProtected-method";
		static readonly IconId InternalAndProtectedExtensionMethod = "md-InternalAndProtected-extensionmethod";
		static readonly IconId InternalAndProtectedProperty = "md-InternalAndProtected-property";
		static readonly IconId InternalAndProtectedStruct = "md-InternalAndProtected-struct";

		static readonly IconId PrivateClass = "md-private-class";
		static readonly IconId PrivateDelegate = "md-private-delegate";
		static readonly IconId PrivateEnum = "md-private-enum";
		static readonly IconId PrivateEvent = "md-private-event";
		static readonly IconId PrivateField = "md-private-field";
		static readonly IconId PrivateInterface = "md-private-interface";
		static readonly IconId PrivateMethod = "md-private-method";
		static readonly IconId PrivateExtensionMethod = "md-private-extensionmethod";
		static readonly IconId PrivateProperty = "md-private-property";
		static readonly IconId PrivateStruct = "md-private-struct";

		static readonly IconId ProtectedClass = "md-protected-class";
		static readonly IconId ProtectedDelegate = "md-protected-delegate";
		static readonly IconId ProtectedEnum = "md-protected-enum";
		static readonly IconId ProtectedEvent = "md-protected-event";
		static readonly IconId ProtectedField = "md-protected-field";
		static readonly IconId ProtectedInterface = "md-protected-interface";
		static readonly IconId ProtectedMethod = "md-protected-method";
		static readonly IconId ProtectedExtensionMethod = "md-protected-extensionmethod";
		static readonly IconId ProtectedProperty = "md-protected-property";
		static readonly IconId ProtectedStruct = "md-protected-struct";
		
		static readonly IconId ProtectedOrInternalClass = "md-ProtectedOrInternal-class";
		static readonly IconId ProtectedOrInternalDelegate = "md-ProtectedOrInternal-delegate";
		static readonly IconId ProtectedOrInternalEnum = "md-ProtectedOrInternal-enum";
		static readonly IconId ProtectedOrInternalEvent = "md-ProtectedOrInternal-event";
		static readonly IconId ProtectedOrInternalField = "md-ProtectedOrInternal-field";
		static readonly IconId ProtectedOrInternalInterface = "md-ProtectedOrInternal-interface";
		static readonly IconId ProtectedOrInternalMethod = "md-ProtectedOrInternal-method";
		static readonly IconId ProtectedOrInternalExtensionMethod = "md-ProtectedOrInternal-extensionmethod";
		static readonly IconId ProtectedOrInternalProperty = "md-ProtectedOrInternal-property";
		static readonly IconId ProtectedOrInternalStruct = "md-ProtectedOrInternal-struct";
		
		static IconId[,] typeIconTable = new IconId[,] {
			{Class,     PrivateClass,		Class,		ProtectedClass,     InternalClass,		ProtectedOrInternalClass, 		InternalAndProtectedClass},     // class
			{Enum,      PrivateEnum,		Enum,		ProtectedEnum,      InternalEnum,		ProtectedOrInternalEnum, 		InternalAndProtectedEnum},      // enum
			{Interface, PrivateInterface,	Interface,	ProtectedInterface, InternalInterface,	ProtectedOrInternalInterface,	InternalAndProtectedInterface}, // interface
			{Struct,    PrivateStruct,		Struct,   	ProtectedStruct,    InternalStruct,		ProtectedOrInternalStruct,		InternalAndProtectedStruct},    // struct
			{Delegate,  PrivateDelegate,	Delegate, 	ProtectedDelegate,  InternalDelegate,	ProtectedOrInternalDelegate,	InternalAndProtectedDelegate}   // delegate
		};
		static readonly IconId[] fieldIconTable = {
			Stock.Field, Stock.PrivateField, Stock.Field, Stock.ProtectedField, Stock.InternalField, Stock.ProtectedOrInternalField, Stock.InternalAndProtectedField
		};
		static readonly IconId[] methodIconTable = {
			Stock.Method, Stock.PrivateMethod, Stock.Method, Stock.ProtectedMethod, Stock.InternalMethod, Stock.ProtectedOrInternalMethod, Stock.InternalAndProtectedMethod
		};
		static readonly IconId[] extensionMethodIconTable = {
			Stock.ExtensionMethod, Stock.PrivateExtensionMethod, Stock.ExtensionMethod, Stock.ProtectedExtensionMethod, Stock.InternalExtensionMethod, Stock.ProtectedOrInternalExtensionMethod, Stock.InternalAndProtectedExtensionMethod
		};
		static readonly IconId[] propertyIconTable = {
			Stock.Property, Stock.PrivateProperty, Stock.Property, Stock.ProtectedProperty, Stock.InternalProperty, Stock.ProtectedOrInternalProperty, Stock.InternalAndProtectedProperty
		};
		static readonly IconId[] eventIconTable = {
			Stock.Event, Stock.PrivateEvent, Stock.Event, Stock.ProtectedEvent, Stock.InternalEvent, Stock.ProtectedOrInternalEvent, Stock.InternalAndProtectedEvent
		};

//		public static IconId GetStockIcon (this INamedElement element)
//		{
//			if (element is IType)
//				return ((IType)element).GetStockIcon ();
//			if (element is ITypeParameter)
//				return ((ITypeParameter)element).GetStockIcon ();
//			if (element is IUnresolvedEntity)
//				return ((IUnresolvedEntity)element).GetStockIcon ();
//			return ((IEntity)element).GetStockIcon ();
//		}
//		
//		public static IconId GetStockIcon (this ITypeDefinition entity)
//		{
//			return GetStockIcon ((IType)entity);
//		}
//
//		public static IconId GetStockIcon (this IType entity)
//		{
//			var def = entity.GetDefinition ();
//			if (def == null)
//				return Class;
//			switch (def.Kind) {
//			case TypeKind.Class:
//				return typeIconTable [0, (int)def.Accessibility];
//			case TypeKind.Enum:
//				return typeIconTable [1, (int)def.Accessibility];
//			case TypeKind.Interface:
//				return typeIconTable [2, (int)def.Accessibility];
//			case TypeKind.Struct:
//				return typeIconTable [3, (int)def.Accessibility];
//			case TypeKind.Delegate:
//				return typeIconTable [4, (int)def.Accessibility];
//			default:
//				return typeIconTable [0, (int)def.Accessibility];
//			}
//		}

		static int GetIndex (Microsoft.CodeAnalysis.Accessibility accessibility)
		{
			switch (accessibility) {
			case Microsoft.CodeAnalysis.Accessibility.NotApplicable:
				return 0;
			case Microsoft.CodeAnalysis.Accessibility.Private:
				return 1;
			case Microsoft.CodeAnalysis.Accessibility.ProtectedAndInternal:
				return 5;
			case Microsoft.CodeAnalysis.Accessibility.Protected:
				return 3;
			case Microsoft.CodeAnalysis.Accessibility.Internal:
				return 4;
			case Microsoft.CodeAnalysis.Accessibility.ProtectedOrInternal:
				return 5;
			case Microsoft.CodeAnalysis.Accessibility.Public:
				return 2;
			default:
				throw new ArgumentOutOfRangeException ();
			}
		}

		public static IconId GetStockIcon (this Microsoft.CodeAnalysis.ISymbol symbol)
		{
			switch (symbol.Kind) {
			case Microsoft.CodeAnalysis.SymbolKind.Alias:
			case Microsoft.CodeAnalysis.SymbolKind.ArrayType:
			case Microsoft.CodeAnalysis.SymbolKind.Assembly:
			case Microsoft.CodeAnalysis.SymbolKind.DynamicType:
			case Microsoft.CodeAnalysis.SymbolKind.ErrorType:
			case Microsoft.CodeAnalysis.SymbolKind.Label:
			case Microsoft.CodeAnalysis.SymbolKind.Local:
			case Microsoft.CodeAnalysis.SymbolKind.NetModule:
			case Microsoft.CodeAnalysis.SymbolKind.PointerType:
				return Field;
			case Microsoft.CodeAnalysis.SymbolKind.NamedType:
				var namedTypeSymbol = (Microsoft.CodeAnalysis.INamedTypeSymbol)symbol;
				return typeIconTable [GetTypeIndex(namedTypeSymbol.TypeKind ), GetIndex (namedTypeSymbol.DeclaredAccessibility)];
			case Microsoft.CodeAnalysis.SymbolKind.Event:
				var evtSymbol = (Microsoft.CodeAnalysis.IEventSymbol)symbol;
				return eventIconTable [GetIndex (evtSymbol.DeclaredAccessibility)];
			case Microsoft.CodeAnalysis.SymbolKind.Field:
				var fieldSymbol = (Microsoft.CodeAnalysis.IFieldSymbol)symbol;
				return fieldIconTable [GetIndex (fieldSymbol.DeclaredAccessibility)];
			case Microsoft.CodeAnalysis.SymbolKind.Method:
				var methodSymbol = (Microsoft.CodeAnalysis.IMethodSymbol)symbol;
				return methodIconTable [GetIndex (methodSymbol.DeclaredAccessibility)];
			case Microsoft.CodeAnalysis.SymbolKind.Namespace:
				return Namespace;
			case Microsoft.CodeAnalysis.SymbolKind.Parameter:
				return Field;
			case Microsoft.CodeAnalysis.SymbolKind.Property:
				var propertySymbol = (Microsoft.CodeAnalysis.IPropertySymbol)symbol;
				return propertyIconTable [GetIndex (propertySymbol.DeclaredAccessibility)];
			case Microsoft.CodeAnalysis.SymbolKind.RangeVariable:
				return Field;
			case Microsoft.CodeAnalysis.SymbolKind.TypeParameter:
				return Stock.typeIconTable [0, 0];
			case Microsoft.CodeAnalysis.SymbolKind.Preprocessing:
				return Field;
			default:
				throw new ArgumentOutOfRangeException ();
			}
		}

		static int GetTypeIndex (Microsoft.CodeAnalysis.TypeKind typeKind)
		{
			switch (typeKind) {
			case Microsoft.CodeAnalysis.TypeKind.Unknown:
			case Microsoft.CodeAnalysis.TypeKind.Array:
				return 0;
			case Microsoft.CodeAnalysis.TypeKind.Class:
				return 0;
			case Microsoft.CodeAnalysis.TypeKind.Delegate:
				return 4;
			case Microsoft.CodeAnalysis.TypeKind.Dynamic:
				return 0;
			case Microsoft.CodeAnalysis.TypeKind.Enum:
				return 1;
			case Microsoft.CodeAnalysis.TypeKind.Error:
				return 0;
			case Microsoft.CodeAnalysis.TypeKind.Interface:
				return 2;
			case Microsoft.CodeAnalysis.TypeKind.Module:
				return 0;
			case Microsoft.CodeAnalysis.TypeKind.Pointer:
				return 0;
			case Microsoft.CodeAnalysis.TypeKind.Struct:
				return 3;
			case Microsoft.CodeAnalysis.TypeKind.TypeParameter:
				return 0;
			case Microsoft.CodeAnalysis.TypeKind.Submission:
				return 0;
			default:
				throw new ArgumentOutOfRangeException ();
			}
		}

		internal static IconId GetStockIconForSymbolInfo (this DeclaredSymbolInfo symbol)
		{
			switch (symbol.Kind) {
			case DeclaredSymbolInfoKind.Class:
				return Stock.Class;
			case DeclaredSymbolInfoKind.Constant:
				return Stock.Field;
			case DeclaredSymbolInfoKind.Constructor:
				return Stock.Method;
			case DeclaredSymbolInfoKind.Delegate:
				return Stock.Delegate;
			case DeclaredSymbolInfoKind.Enum:
				return Stock.Enum;
			case DeclaredSymbolInfoKind.EnumMember:
				return Stock.Field;
			case DeclaredSymbolInfoKind.Event:
				return Stock.Event;
			case DeclaredSymbolInfoKind.Field:
				return Stock.Field;
			case DeclaredSymbolInfoKind.Indexer:
				return Stock.Method;
			case DeclaredSymbolInfoKind.Interface:
				return Stock.Interface;
			case DeclaredSymbolInfoKind.Method:
				return Stock.Method;
			case DeclaredSymbolInfoKind.Module:
				return Stock.Method;
			case DeclaredSymbolInfoKind.Property:
				return Stock.Property;
			case DeclaredSymbolInfoKind.Struct:
				return Stock.Struct;
			default:
				throw new ArgumentOutOfRangeException ();
			}
		}
	}
}