diff options
author | Mike Krüger <mkrueger@xamarin.com> | 2015-11-23 16:10:44 +0300 |
---|---|---|
committer | Mike Krüger <mkrueger@xamarin.com> | 2015-11-23 16:10:51 +0300 |
commit | 31a6bd9d2464cdcc80ca97ef31874d4dce6808e7 (patch) | |
tree | 86e70c68163cd05a7194ed02e257da5c3dea4ce9 /main | |
parent | e7835909ffa08536761def7377a8a7d53aaa88a1 (diff) |
[Ide] Implemented static overlay icon.
For completion, assembly browser and breadcrumb.
Diffstat (limited to 'main')
3 files changed, 231 insertions, 500 deletions
diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp/AstStockIcons.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp/AstStockIcons.cs index 932a5127b7..e2aab565b5 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp/AstStockIcons.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp/AstStockIcons.cs @@ -49,78 +49,9 @@ namespace MonoDevelop.CSharp 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 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 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 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 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 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 = { - AstStockIcons.Field, AstStockIcons.PrivateField, AstStockIcons.Field, AstStockIcons.ProtectedField, AstStockIcons.InternalField, AstStockIcons.ProtectedOrInternalField, AstStockIcons.InternalAndProtectedField - }; - static readonly IconId[] methodIconTable = { - AstStockIcons.Method, AstStockIcons.PrivateMethod, AstStockIcons.Method, AstStockIcons.ProtectedMethod, AstStockIcons.InternalMethod, AstStockIcons.ProtectedOrInternalMethod, AstStockIcons.InternalAndProtectedMethod - }; - static readonly IconId[] propertyIconTable = { - AstStockIcons.Property, AstStockIcons.PrivateProperty, AstStockIcons.Property, AstStockIcons.ProtectedProperty, AstStockIcons.InternalProperty, AstStockIcons.ProtectedOrInternalProperty, AstStockIcons.InternalAndProtectedProperty - }; - static readonly IconId[] eventIconTable = { - AstStockIcons.Event, AstStockIcons.PrivateEvent, AstStockIcons.Event, AstStockIcons.ProtectedEvent, AstStockIcons.InternalEvent, AstStockIcons.ProtectedOrInternalEvent, AstStockIcons.InternalAndProtectedEvent - }; - - static void AdjustAccessibility (SyntaxTokenList modifiers, ref Accessibility acc, ref bool result) + static void AdjustAccessibility (SyntaxTokenList modifiers, ref Accessibility acc, ref bool isStatic, ref bool result) { + isStatic = modifiers.Any (mod => mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.StaticKeyword); if (modifiers.Any (mod => mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.ProtectedKeyword) && modifiers.Any (mod => mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.InternalKeyword)) { acc = Accessibility.ProtectedOrInternal; @@ -139,7 +70,7 @@ namespace MonoDevelop.CSharp result = true; return; } - if (mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.ProtectedKeyword) { + if (mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.ProtectedKeyword) { acc = Accessibility.Protected; result = true; return; @@ -152,8 +83,9 @@ namespace MonoDevelop.CSharp } } - static bool GetAccessibility (SyntaxNode element, out Accessibility acc) + static bool GetAccessibility (SyntaxNode element, out Accessibility acc, out bool isStatic) { + isStatic = false; if (element.Parent is TypeDeclarationSyntax && element.Parent is InterfaceDeclarationSyntax) { acc = Accessibility.Public; return true; @@ -164,110 +96,121 @@ namespace MonoDevelop.CSharp acc = Accessibility.Internal; if (element is TypeDeclarationSyntax) - AdjustAccessibility (((TypeDeclarationSyntax)element).Modifiers, ref acc, ref result); + AdjustAccessibility (((TypeDeclarationSyntax)element).Modifiers, ref acc, ref isStatic, ref result); if (element is BaseFieldDeclarationSyntax) - AdjustAccessibility (((BaseFieldDeclarationSyntax)element).Modifiers, ref acc, ref result); + AdjustAccessibility (((BaseFieldDeclarationSyntax)element).Modifiers, ref acc, ref isStatic, ref result); if (element is BasePropertyDeclarationSyntax) - AdjustAccessibility (((BasePropertyDeclarationSyntax)element).Modifiers, ref acc, ref result); + AdjustAccessibility (((BasePropertyDeclarationSyntax)element).Modifiers, ref acc, ref isStatic, ref result); if (element is BaseMethodDeclarationSyntax) - AdjustAccessibility (((BaseMethodDeclarationSyntax)element).Modifiers, ref acc, ref result); + AdjustAccessibility (((BaseMethodDeclarationSyntax)element).Modifiers, ref acc, ref isStatic, ref result); return result; } public static string GetStockIcon (this SyntaxNode element) { Accessibility acc = Accessibility.Public; + bool isStatic = false; if (element is NamespaceDeclarationSyntax) return Namespace; if (element is AccessorDeclarationSyntax) { - if (!GetAccessibility ((MemberDeclarationSyntax)element, out acc)) - GetAccessibility (element.Parent as MemberDeclarationSyntax, out acc); + if (!GetAccessibility ((MemberDeclarationSyntax)element, out acc, out isStatic)) + GetAccessibility (element.Parent as MemberDeclarationSyntax, out acc, out isStatic); - return methodIconTable [(int) (acc)]; + return "md-" + GetAccess (acc) + "method"; } - GetAccessibility (element, out acc); + GetAccessibility (element, out acc, out isStatic); if (element is EnumDeclarationSyntax) { - return typeIconTable [1, (int) (acc)]; + return "md-" + GetAccess (acc) + "enum"; } if (element is TypeDeclarationSyntax) { var type = element as TypeDeclarationSyntax; switch (type.Keyword.Kind ()) { case SyntaxKind.ClassKeyword: - return typeIconTable [0, (int) (acc)]; + return "md-" + GetAccess (acc) + "class"; case SyntaxKind.StructKeyword: - return typeIconTable [3, (int) (acc)]; + return "md-" + GetAccess (acc) + "struct"; case SyntaxKind.InterfaceKeyword: - return typeIconTable [2, (int) (acc)]; + return "md-" + GetAccess (acc) + "interface"; case SyntaxKind.EnumKeyword: - return typeIconTable [1, (int) (acc)]; + return "md-" + GetAccess (acc) + "enum"; default: throw new ArgumentOutOfRangeException (); } } if (element is DelegateDeclarationSyntax) - return typeIconTable [4, (int) (acc)]; + return "md-" + GetAccess (acc) + "delegate"; // member accessibility - GetAccessibility (element, out acc); + GetAccessibility (element, out acc, out isStatic); if (element is BaseMethodDeclarationSyntax) { // TODO! // var method = element as MethodDeclarationSyntax; // if (method.ParameterList.Parameters.First ()) // return extensionMethodIconTable [(int) (acc)]; - return methodIconTable [(int) (acc)]; + + + return "md-" + GetAccess (acc) + GetGlobal (isStatic) + "method"; } if (element is PropertyDeclarationSyntax || element is IndexerDeclarationSyntax) - return propertyIconTable [(int) (acc)]; + return "md-" + GetAccess (acc) + GetGlobal (isStatic) + "property"; if (element is EventDeclarationSyntax || element is EventFieldDeclarationSyntax) - return eventIconTable [(int) (acc)]; + return "md-" + GetAccess (acc) + GetGlobal (isStatic) + "event"; if (element.Parent is EnumDeclarationSyntax) - acc = Accessibility.Public; - return fieldIconTable [(int) (acc)]; + return "md-" + GetAccess (acc) + "enum"; + return "md-" + GetAccess (acc) + GetGlobal (isStatic) + "field"; + } + + static string GetGlobal (bool isStatic) + { + return isStatic ? "static-" : ""; + } + + static string GetAccess (Accessibility acc) + { + return MonoDevelop.Ide.TypeSystem.Stock.GetAccess (acc); } internal static IconId GetStockIconForSymbolInfo (this DeclaredSymbolInfo symbol) { switch (symbol.Kind) { - case DeclaredSymbolInfoKind.Class: + case DeclaredSymbolInfoKind.Class: return AstStockIcons.Class; - case DeclaredSymbolInfoKind.Constant: + case DeclaredSymbolInfoKind.Constant: return AstStockIcons.Field; - case DeclaredSymbolInfoKind.Constructor: + case DeclaredSymbolInfoKind.Constructor: return AstStockIcons.Method; - case DeclaredSymbolInfoKind.Delegate: + case DeclaredSymbolInfoKind.Delegate: return AstStockIcons.Delegate; - case DeclaredSymbolInfoKind.Enum: + case DeclaredSymbolInfoKind.Enum: return AstStockIcons.Enum; - case DeclaredSymbolInfoKind.EnumMember: + case DeclaredSymbolInfoKind.EnumMember: return AstStockIcons.Field; - case DeclaredSymbolInfoKind.Event: + case DeclaredSymbolInfoKind.Event: return AstStockIcons.Event; - case DeclaredSymbolInfoKind.Field: + case DeclaredSymbolInfoKind.Field: return AstStockIcons.Field; - case DeclaredSymbolInfoKind.Indexer: + case DeclaredSymbolInfoKind.Indexer: return AstStockIcons.Method; - case DeclaredSymbolInfoKind.Interface: + case DeclaredSymbolInfoKind.Interface: return AstStockIcons.Interface; - case DeclaredSymbolInfoKind.Method: + case DeclaredSymbolInfoKind.Method: return AstStockIcons.Method; - case DeclaredSymbolInfoKind.Module: + case DeclaredSymbolInfoKind.Module: return AstStockIcons.Method; - case DeclaredSymbolInfoKind.Property: + case DeclaredSymbolInfoKind.Property: return AstStockIcons.Property; - case DeclaredSymbolInfoKind.Struct: + case DeclaredSymbolInfoKind.Struct: return AstStockIcons.Struct; - default: - throw new ArgumentOutOfRangeException (); + default: + throw new ArgumentOutOfRangeException (); } } - } - } diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/NRefactoryStock.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/NRefactoryStock.cs index 9d4624c339..f06aab28df 100644 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/NRefactoryStock.cs +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/NRefactoryStock.cs @@ -31,96 +31,9 @@ namespace MonoDevelop.AssemblyBrowser { static class NRefactoryStock { - 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 = { - NRefactoryStock.Field, NRefactoryStock.PrivateField, NRefactoryStock.Field, NRefactoryStock.ProtectedField, NRefactoryStock.InternalField, NRefactoryStock.ProtectedOrInternalField, NRefactoryStock.InternalAndProtectedField - }; - static readonly IconId[] methodIconTable = { - NRefactoryStock.Method, NRefactoryStock.PrivateMethod, NRefactoryStock.Method, NRefactoryStock.ProtectedMethod, NRefactoryStock.InternalMethod, NRefactoryStock.ProtectedOrInternalMethod, NRefactoryStock.InternalAndProtectedMethod - }; - static readonly IconId[] extensionMethodIconTable = { - NRefactoryStock.ExtensionMethod, NRefactoryStock.PrivateExtensionMethod, NRefactoryStock.ExtensionMethod, NRefactoryStock.ProtectedExtensionMethod, NRefactoryStock.InternalExtensionMethod, NRefactoryStock.ProtectedOrInternalExtensionMethod, NRefactoryStock.InternalAndProtectedExtensionMethod - }; - static readonly IconId[] propertyIconTable = { - NRefactoryStock.Property, NRefactoryStock.PrivateProperty, NRefactoryStock.Property, NRefactoryStock.ProtectedProperty, NRefactoryStock.InternalProperty, NRefactoryStock.ProtectedOrInternalProperty, NRefactoryStock.InternalAndProtectedProperty - }; - static readonly IconId[] eventIconTable = { - NRefactoryStock.Event, NRefactoryStock.PrivateEvent, NRefactoryStock.Event, NRefactoryStock.ProtectedEvent, NRefactoryStock.InternalEvent, NRefactoryStock.ProtectedOrInternalEvent, NRefactoryStock.InternalAndProtectedEvent - }; - public static IconId GetStockIcon (this INamedElement element) { if (element is IType) @@ -137,77 +50,6 @@ namespace MonoDevelop.AssemblyBrowser 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]; - } - } - public static IconId GetStockIcon (this IUnresolvedTypeDefinition def) - { - 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 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 (); - } - } - public static IconId GetStockIcon (this IField field) { return GetStockIcon ((IEntity)field); @@ -230,73 +72,152 @@ namespace MonoDevelop.AssemblyBrowser public static IconId GetStockIcon (this IEntity entity, bool showAccessibility = true) { + return "md-" + GetAccess (entity) + GetGlobal (entity) + GetSource (entity); + } + + static string GetAccess (IEntity entity) + { + switch (entity.Accessibility) { + case Accessibility.None: + return ""; + case Accessibility.Private: + return "private-"; + case Accessibility.Public: + return ""; + case Accessibility.Protected: + return "protected-"; + case Accessibility.Internal: + return "internal-"; + case Accessibility.ProtectedOrInternal: + case Accessibility.ProtectedAndInternal: + return "ProtectedOrInternal-"; + default: + throw new ArgumentOutOfRangeException (); + } + } + + static string GetGlobal (IEntity entity) + { + switch (entity.SymbolKind) { + case SymbolKind.Field: + case SymbolKind.Method: + case SymbolKind.Constructor: + case SymbolKind.Destructor: + case SymbolKind.Operator: + case SymbolKind.Property: + case SymbolKind.Indexer: + return entity.IsStatic ? "static-" : ""; + } + return ""; + + } + + static string GetSource (IEntity entity) + { switch (entity.SymbolKind) { case SymbolKind.TypeDefinition: - return GetStockIcon ((IType)entity); + var type = (IType)entity; + switch (type.Kind) { + case TypeKind.Class: + return "class"; + case TypeKind.Interface: + return "interface"; + case TypeKind.Struct: + return "struct"; + case TypeKind.Delegate: + return "delegate"; + case TypeKind.Enum: + return "enum"; + } + return "class"; case SymbolKind.Field: - if (showAccessibility) - return fieldIconTable [(int)entity.Accessibility]; - else - return fieldIconTable [0]; + case SymbolKind.Event: + return "field"; case SymbolKind.Method: case SymbolKind.Constructor: case SymbolKind.Destructor: case SymbolKind.Operator: - if (showAccessibility) { - if (((IMethod)entity).IsExtensionMethod) - return extensionMethodIconTable [(int)entity.Accessibility]; - return methodIconTable [(int)entity.Accessibility]; - } else { - if (((IMethod)entity).IsExtensionMethod) - return extensionMethodIconTable [0]; - return methodIconTable [0]; - } + return "method"; case SymbolKind.Property: case SymbolKind.Indexer: - if (showAccessibility) - return propertyIconTable [(int)entity.Accessibility]; - else - return propertyIconTable [0]; - case SymbolKind.Event: - if (showAccessibility) - return eventIconTable [(int)entity.Accessibility]; - else - return eventIconTable [0]; + return "property"; } return ""; } + public static IconId GetStockIcon (this IUnresolvedEntity entity, bool showAccessibility = true) { + return "md-" + GetAccess (entity) + GetGlobal (entity) + GetSource (entity); + } + + static string GetAccess (IUnresolvedEntity entity) + { + switch (entity.Accessibility) { + case Accessibility.None: + return ""; + case Accessibility.Private: + return "private-"; + case Accessibility.Public: + return ""; + case Accessibility.Protected: + return "protected-"; + case Accessibility.Internal: + return "internal-"; + case Accessibility.ProtectedOrInternal: + case Accessibility.ProtectedAndInternal: + return "ProtectedOrInternal-"; + default: + throw new ArgumentOutOfRangeException (); + } + } + + static string GetGlobal (IUnresolvedEntity entity) + { + switch (entity.SymbolKind) { + case SymbolKind.Field: + case SymbolKind.Method: + case SymbolKind.Constructor: + case SymbolKind.Destructor: + case SymbolKind.Operator: + case SymbolKind.Property: + case SymbolKind.Indexer: + return entity.IsStatic ? "static-" : ""; + } + return ""; + } + + static string GetSource (IUnresolvedEntity entity) + { switch (entity.SymbolKind) { case SymbolKind.TypeDefinition: - return GetStockIcon ((IUnresolvedTypeDefinition)entity); + var type = (IUnresolvedTypeDefinition)entity; + switch (type.Kind) { + case TypeKind.Class: + return "class"; + case TypeKind.Interface: + return "interface"; + case TypeKind.Struct: + return "struct"; + case TypeKind.Delegate: + return "delegate"; + case TypeKind.Enum: + return "enum"; + } + return "class"; case SymbolKind.Field: - if (showAccessibility) - return fieldIconTable [(int)entity.Accessibility]; - else - return fieldIconTable [0]; + return "field"; + case SymbolKind.Event: + return "event"; case SymbolKind.Method: case SymbolKind.Constructor: case SymbolKind.Destructor: case SymbolKind.Operator: - if (showAccessibility) - return methodIconTable [(int)entity.Accessibility]; - else - return methodIconTable [0]; + return "method"; case SymbolKind.Property: case SymbolKind.Indexer: - if (showAccessibility) - return propertyIconTable [(int)entity.Accessibility]; - else - return propertyIconTable [0]; - case SymbolKind.Event: - if (showAccessibility) - return eventIconTable [(int)entity.Accessibility]; - else - return eventIconTable [0]; + return "property"; } return ""; } } -} - +}
\ No newline at end of file diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.TypeSystem/StockIcons.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.TypeSystem/StockIcons.cs index fd902c3baa..94208220a0 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.TypeSystem/StockIcons.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.TypeSystem/StockIcons.cs @@ -26,161 +26,57 @@ using System; using MonoDevelop.Core; using Mono.Cecil; +using Microsoft.CodeAnalysis; 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]; -// } -// } + public static IconId GetStockIcon (this Microsoft.CodeAnalysis.ISymbol symbol) + { + return "md-" + GetAccess (symbol.DeclaredAccessibility) + GetGlobal (symbol) + GetSource (symbol); + } - static int GetIndex (Microsoft.CodeAnalysis.Accessibility accessibility) + internal static string GetAccess (Accessibility accessibility) { switch (accessibility) { case Microsoft.CodeAnalysis.Accessibility.NotApplicable: - return 0; + return ""; case Microsoft.CodeAnalysis.Accessibility.Private: - return 1; + return "private-"; case Microsoft.CodeAnalysis.Accessibility.ProtectedAndInternal: - return 5; + return "ProtectedOrInternal-"; case Microsoft.CodeAnalysis.Accessibility.Protected: - return 3; + return "protected-"; case Microsoft.CodeAnalysis.Accessibility.Internal: - return 4; + return "internal-"; case Microsoft.CodeAnalysis.Accessibility.ProtectedOrInternal: - return 5; + return "ProtectedOrInternal-"; case Microsoft.CodeAnalysis.Accessibility.Public: - return 2; + return ""; default: throw new ArgumentOutOfRangeException (); + } + } + + static string GetGlobal (ISymbol symbol) + { + switch (symbol.Kind) { + case Microsoft.CodeAnalysis.SymbolKind.NamedType: + return ""; + case Microsoft.CodeAnalysis.SymbolKind.Event: + case Microsoft.CodeAnalysis.SymbolKind.Field: + case Microsoft.CodeAnalysis.SymbolKind.Method: + case Microsoft.CodeAnalysis.SymbolKind.Property: + return symbol.IsStatic ? "static-" : ""; + default: + return ""; } } - public static IconId GetStockIcon (this Microsoft.CodeAnalysis.ISymbol symbol) + static string GetSource(Microsoft.CodeAnalysis.ISymbol symbol) { switch (symbol.Kind) { case Microsoft.CodeAnalysis.SymbolKind.Alias: @@ -192,69 +88,40 @@ namespace MonoDevelop.Ide.TypeSystem 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; + return "field"; + case Microsoft.CodeAnalysis.SymbolKind.NamedType: + var namedTypeSymbol = (Microsoft.CodeAnalysis.INamedTypeSymbol)symbol; + switch (namedTypeSymbol.TypeKind) { + case Microsoft.CodeAnalysis.TypeKind.Class: + return "class"; + case Microsoft.CodeAnalysis.TypeKind.Delegate: + return "delegate"; + case Microsoft.CodeAnalysis.TypeKind.Enum: + return "enum"; + case Microsoft.CodeAnalysis.TypeKind.Interface: + return "interface"; + case Microsoft.CodeAnalysis.TypeKind.Struct: + return "struct"; + default: + return "class"; + } + + case Microsoft.CodeAnalysis.SymbolKind.Method: + return "method"; + case Microsoft.CodeAnalysis.SymbolKind.Namespace: + return "name-space"; + case Microsoft.CodeAnalysis.SymbolKind.Property: + return "property"; + case Microsoft.CodeAnalysis.SymbolKind.Event: + return "event"; default: throw new ArgumentOutOfRangeException (); } } - } } |