diff options
Diffstat (limited to 'main/src/addins/CSharpBinding/MonoDevelop.CSharp/AstStockIcons.cs')
-rw-r--r-- | main/src/addins/CSharpBinding/MonoDevelop.CSharp/AstStockIcons.cs | 124 |
1 files changed, 71 insertions, 53 deletions
diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp/AstStockIcons.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp/AstStockIcons.cs index aec03f9f17..d8b09e4689 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp/AstStockIcons.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp/AstStockIcons.cs @@ -25,10 +25,12 @@ // THE SOFTWARE. using System; -using ICSharpCode.NRefactory.TypeSystem; +using System.Linq; using MonoDevelop.Ide.TypeSystem; using MonoDevelop.Core; -using ICSharpCode.NRefactory.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; namespace MonoDevelop.CSharp { @@ -41,7 +43,6 @@ namespace MonoDevelop.CSharp 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"; @@ -54,7 +55,6 @@ namespace MonoDevelop.CSharp 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"; @@ -65,7 +65,6 @@ namespace MonoDevelop.CSharp 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"; @@ -76,7 +75,6 @@ namespace MonoDevelop.CSharp 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"; @@ -87,7 +85,6 @@ namespace MonoDevelop.CSharp 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"; @@ -98,7 +95,6 @@ namespace MonoDevelop.CSharp 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"; @@ -115,9 +111,6 @@ namespace MonoDevelop.CSharp static readonly IconId[] methodIconTable = { AstStockIcons.Method, AstStockIcons.PrivateMethod, AstStockIcons.Method, AstStockIcons.ProtectedMethod, AstStockIcons.InternalMethod, AstStockIcons.ProtectedOrInternalMethod, AstStockIcons.InternalAndProtectedMethod }; - static readonly IconId[] extensionMethodIconTable = { - AstStockIcons.ExtensionMethod, AstStockIcons.PrivateExtensionMethod, AstStockIcons.ExtensionMethod, AstStockIcons.ProtectedExtensionMethod, AstStockIcons.InternalExtensionMethod, AstStockIcons.ProtectedOrInternalExtensionMethod, AstStockIcons.InternalAndProtectedExtensionMethod - }; static readonly IconId[] propertyIconTable = { AstStockIcons.Property, AstStockIcons.PrivateProperty, AstStockIcons.Property, AstStockIcons.ProtectedProperty, AstStockIcons.InternalProperty, AstStockIcons.ProtectedOrInternalProperty, AstStockIcons.InternalAndProtectedProperty }; @@ -125,86 +118,111 @@ namespace MonoDevelop.CSharp AstStockIcons.Event, AstStockIcons.PrivateEvent, AstStockIcons.Event, AstStockIcons.ProtectedEvent, AstStockIcons.InternalEvent, AstStockIcons.ProtectedOrInternalEvent, AstStockIcons.InternalAndProtectedEvent }; - static bool GetAccessibility (EntityDeclaration element, out Accessibility acc) + static void AdjustAccessibility (SyntaxTokenList modifiers, ref Accessibility acc, ref bool result) + { + if (modifiers.Any (mod => mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.ProtectedKeyword) && + modifiers.Any (mod => mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.InternalKeyword)) { + acc = Accessibility.ProtectedOrInternal; + result = true; + return; + } + + foreach (var mod in modifiers) { + if (mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.PublicKeyword) { + acc = Accessibility.Public; + result = true; + return; + } + if (mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.PrivateKeyword) { + acc = Accessibility.Private; + result = true; + return; + } + if (mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.ProtectedKeyword) { + acc = Accessibility.Protected; + result = true; + return; + } + if (mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.InternalKeyword) { + acc = Accessibility.Internal; + result = true; + return; + } + } + } + + static bool GetAccessibility (SyntaxNode element, out Accessibility acc) { - if (element.Parent is TypeDeclaration && ((TypeDeclaration)element.Parent).ClassType == ClassType.Interface) { + if (element.Parent is TypeDeclarationSyntax && element.Parent is InterfaceDeclarationSyntax) { acc = Accessibility.Public; return true; } bool result = false; acc = Accessibility.Private; - if (element is TypeDeclaration && !(element.Parent is TypeDeclaration)) - acc = Accessibility.Internal; - if (element.HasModifier (Modifiers.Public)) { - acc = Accessibility.Public; - result = true; - } else if (element.HasModifier (Modifiers.Private)) { - acc = Accessibility.Private; - result = true; - } else if (element.HasModifier (Modifiers.Protected | Modifiers.Internal)) { - acc = Accessibility.ProtectedOrInternal; - result = true; - } else if (element.HasModifier (Modifiers.Protected)) { - acc = Accessibility.Protected; - result = true; - } else if (element.HasModifier (Modifiers.Internal)) { + if (element is TypeDeclarationSyntax && !(element.Parent is TypeDeclarationSyntax)) acc = Accessibility.Internal; - result = true; - } + + if (element is TypeDeclarationSyntax) + AdjustAccessibility (((TypeDeclarationSyntax)element).Modifiers, ref acc, ref result); + if (element is BaseFieldDeclarationSyntax) + AdjustAccessibility (((BaseFieldDeclarationSyntax)element).Modifiers, ref acc, ref result); + if (element is BasePropertyDeclarationSyntax) + AdjustAccessibility (((BasePropertyDeclarationSyntax)element).Modifiers, ref acc, ref result); + if (element is BaseMethodDeclarationSyntax) + AdjustAccessibility (((BaseMethodDeclarationSyntax)element).Modifiers, ref acc, ref result); return result; } - - public static string GetStockIcon (this EntityDeclaration element) + public static string GetStockIcon (this SyntaxNode element) { Accessibility acc = Accessibility.Public; + if (element is NamespaceDeclarationSyntax) + return Namespace; - if (element is Accessor) { - if (!GetAccessibility (element, out acc)) - GetAccessibility (element.Parent as EntityDeclaration, out acc); + if (element is AccessorDeclarationSyntax) { + if (!GetAccessibility ((MemberDeclarationSyntax)element, out acc)) + GetAccessibility (element.Parent as MemberDeclarationSyntax, out acc); return methodIconTable [(int) (acc)]; } GetAccessibility (element, out acc); - if (element is TypeDeclaration) { - var type = element as TypeDeclaration; - - switch (type.ClassType) { - case ClassType.Class: + if (element is TypeDeclarationSyntax) { + var type = element as TypeDeclarationSyntax; + switch (type.Keyword.Kind ()) { + case SyntaxKind.ClassKeyword: return typeIconTable [0, (int) (acc)]; - case ClassType.Struct: + case SyntaxKind.StructKeyword: return typeIconTable [3, (int) (acc)]; - case ClassType.Interface: + case SyntaxKind.InterfaceKeyword: return typeIconTable [2, (int) (acc)]; - case ClassType.Enum: + case SyntaxKind.EnumKeyword: return typeIconTable [1, (int) (acc)]; default: throw new ArgumentOutOfRangeException (); } } - if (element is DelegateDeclaration) + if (element is DelegateDeclarationSyntax) return typeIconTable [4, (int) (acc)]; // member accessibility GetAccessibility (element, out acc); - if (element is MethodDeclaration) { - var method = element as MethodDeclaration; - if (method.IsExtensionMethod) - return extensionMethodIconTable [(int) (acc)]; + if (element is BaseMethodDeclarationSyntax) { + // TODO! + // var method = element as MethodDeclarationSyntax; + // if (method.ParameterList.Parameters.First ()) + // return extensionMethodIconTable [(int) (acc)]; return methodIconTable [(int) (acc)]; } - if (element is OperatorDeclaration || element is ConstructorDeclaration || element is DestructorDeclaration || element is Accessor) - return methodIconTable [(int) (acc)]; - if (element is PropertyDeclaration || element is IndexerDeclaration) + if (element is PropertyDeclarationSyntax || element is IndexerDeclarationSyntax) return propertyIconTable [(int) (acc)]; - if (element is EventDeclaration || element is CustomEventDeclaration) + if (element is EventDeclarationSyntax || element is EventFieldDeclarationSyntax) return eventIconTable [(int) (acc)]; - if (element.Parent is TypeDeclaration && ((TypeDeclaration)element.Parent).ClassType == ClassType.Enum) + if (element.Parent is EnumDeclarationSyntax) acc = Accessibility.Public; return fieldIconTable [(int) (acc)]; } |