~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to src/addins/CSharpBinding/MonoDevelop.CSharp/AstStockIcons.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
        // Copied from StockIcons.cs and extended for the c# ast (c# AST shouldn't be in Ide)
36
36
        public static class AstStockIcons
37
37
        {
38
 
//              static readonly IconId Error = "gtk-dialog-error";
39
38
                static readonly IconId Class = "md-class";
40
39
                static readonly IconId Enum = "md-enum";
41
40
                static readonly IconId Event = "md-event";
47
46
                static readonly IconId Struct = "md-struct";
48
47
                static readonly IconId Delegate = "md-delegate";
49
48
                public static readonly IconId Namespace = "md-name-space";
 
49
 
50
50
                static readonly IconId InternalClass = "md-internal-class";
51
51
                static readonly IconId InternalDelegate = "md-internal-delegate";
52
52
                static readonly IconId InternalEnum = "md-internal-enum";
57
57
                static readonly IconId InternalExtensionMethod = "md-internal-extensionmethod";
58
58
                static readonly IconId InternalProperty = "md-internal-property";
59
59
                static readonly IconId InternalStruct = "md-internal-struct";
 
60
 
 
61
                static readonly IconId InternalAndProtectedClass = "md-InternalAndProtected-class";
 
62
                static readonly IconId InternalAndProtectedDelegate = "md-InternalAndProtected-delegate";
 
63
                static readonly IconId InternalAndProtectedEnum = "md-InternalAndProtected-enum";
 
64
                static readonly IconId InternalAndProtectedEvent = "md-InternalAndProtected-event";
 
65
                static readonly IconId InternalAndProtectedField = "md-InternalAndProtected-field";
 
66
                static readonly IconId InternalAndProtectedInterface = "md-InternalAndProtected-interface";
 
67
                static readonly IconId InternalAndProtectedMethod = "md-InternalAndProtected-method";
 
68
                static readonly IconId InternalAndProtectedExtensionMethod = "md-InternalAndProtected-extensionmethod";
 
69
                static readonly IconId InternalAndProtectedProperty = "md-InternalAndProtected-property";
 
70
                static readonly IconId InternalAndProtectedStruct = "md-InternalAndProtected-struct";
 
71
 
60
72
                static readonly IconId PrivateClass = "md-private-class";
61
73
                static readonly IconId PrivateDelegate = "md-private-delegate";
62
74
                static readonly IconId PrivateEnum = "md-private-enum";
67
79
                static readonly IconId PrivateExtensionMethod = "md-private-extensionmethod";
68
80
                static readonly IconId PrivateProperty = "md-private-property";
69
81
                static readonly IconId PrivateStruct = "md-private-struct";
 
82
 
70
83
                static readonly IconId ProtectedClass = "md-protected-class";
71
84
                static readonly IconId ProtectedDelegate = "md-protected-delegate";
72
85
                static readonly IconId ProtectedEnum = "md-protected-enum";
78
91
                static readonly IconId ProtectedProperty = "md-protected-property";
79
92
                static readonly IconId ProtectedStruct = "md-protected-struct";
80
93
                
 
94
                static readonly IconId ProtectedOrInternalClass = "md-ProtectedOrInternal-class";
 
95
                static readonly IconId ProtectedOrInternalDelegate = "md-ProtectedOrInternal-delegate";
 
96
                static readonly IconId ProtectedOrInternalEnum = "md-ProtectedOrInternal-enum";
 
97
                static readonly IconId ProtectedOrInternalEvent = "md-ProtectedOrInternal-event";
 
98
                static readonly IconId ProtectedOrInternalField = "md-ProtectedOrInternal-field";
 
99
                static readonly IconId ProtectedOrInternalInterface = "md-ProtectedOrInternal-interface";
 
100
                static readonly IconId ProtectedOrInternalMethod = "md-ProtectedOrInternal-method";
 
101
                static readonly IconId ProtectedOrInternalExtensionMethod = "md-ProtectedOrInternal-extensionmethod";
 
102
                static readonly IconId ProtectedOrInternalProperty = "md-ProtectedOrInternal-property";
 
103
                static readonly IconId ProtectedOrInternalStruct = "md-ProtectedOrInternal-struct";
 
104
                
81
105
                static IconId[,] typeIconTable = new IconId[,] {
82
 
                        {Class,     PrivateClass,     ProtectedClass,     InternalClass},     // class
83
 
                        {Enum,      PrivateEnum,      ProtectedEnum,      InternalEnum},      // enum
84
 
                        {Interface, PrivateInterface, ProtectedInterface, InternalInterface}, // interface
85
 
                        {Struct,    PrivateStruct,    ProtectedStruct,    InternalStruct},    // struct
86
 
                        {Delegate,  PrivateDelegate,  ProtectedDelegate,  InternalDelegate}   // delegate
87
 
                };
88
 
                static readonly IconId[] fieldIconTable = {AstStockIcons.Field, AstStockIcons.PrivateField, AstStockIcons.ProtectedField, AstStockIcons.InternalField};
89
 
                static readonly IconId[] methodIconTable = {AstStockIcons.Method, AstStockIcons.PrivateMethod, AstStockIcons.ProtectedMethod, AstStockIcons.InternalMethod};
90
 
                static readonly IconId[] extensionMethodIconTable = {AstStockIcons.ExtensionMethod, AstStockIcons.PrivateExtensionMethod, AstStockIcons.ProtectedExtensionMethod, AstStockIcons.InternalExtensionMethod};
91
 
                static readonly IconId[] propertyIconTable = {AstStockIcons.Property, AstStockIcons.PrivateProperty, AstStockIcons.ProtectedProperty, AstStockIcons.InternalProperty};
92
 
                static readonly IconId[] eventIconTable = {AstStockIcons.Event, AstStockIcons.PrivateEvent, AstStockIcons.ProtectedEvent, AstStockIcons.InternalEvent};
93
 
                
94
 
                static int ModifierToOffset (Accessibility acc)
95
 
                {
96
 
                        if ((acc & Accessibility.Private) == Accessibility.Private)
97
 
                                return 1;
98
 
                        if ((acc & Accessibility.Protected) == Accessibility.Protected)
99
 
                                return 2;
100
 
                        if ((acc & Accessibility.Internal) == Accessibility.Internal)
101
 
                                return 3;
102
 
                        return 0;
103
 
                }
104
 
                
105
 
                public static string GetStockIcon (this EntityDeclaration element)
106
 
                {
107
 
                        Accessibility acc = Accessibility.None;
108
 
                        // type accessibility
109
 
                        acc = Accessibility.Internal;
 
106
                        {Class,     PrivateClass,               Class,          ProtectedClass,     InternalClass,              ProtectedOrInternalClass,               InternalAndProtectedClass},     // class
 
107
                        {Enum,      PrivateEnum,                Enum,           ProtectedEnum,      InternalEnum,               ProtectedOrInternalEnum,                InternalAndProtectedEnum},      // enum
 
108
                        {Interface, PrivateInterface,   Interface,      ProtectedInterface, InternalInterface,  ProtectedOrInternalInterface,   InternalAndProtectedInterface}, // interface
 
109
                        {Struct,    PrivateStruct,              Struct,         ProtectedStruct,    InternalStruct,             ProtectedOrInternalStruct,              InternalAndProtectedStruct},    // struct
 
110
                        {Delegate,  PrivateDelegate,    Delegate,       ProtectedDelegate,  InternalDelegate,   ProtectedOrInternalDelegate,    InternalAndProtectedDelegate}   // delegate
 
111
                };
 
112
                static readonly IconId[] fieldIconTable = {
 
113
                        AstStockIcons.Field, AstStockIcons.PrivateField, AstStockIcons.Field, AstStockIcons.ProtectedField, AstStockIcons.InternalField, AstStockIcons.ProtectedOrInternalField, AstStockIcons.InternalAndProtectedField
 
114
                };
 
115
                static readonly IconId[] methodIconTable = {
 
116
                        AstStockIcons.Method, AstStockIcons.PrivateMethod, AstStockIcons.Method, AstStockIcons.ProtectedMethod, AstStockIcons.InternalMethod, AstStockIcons.ProtectedOrInternalMethod, AstStockIcons.InternalAndProtectedMethod
 
117
                };
 
118
                static readonly IconId[] extensionMethodIconTable = {
 
119
                        AstStockIcons.ExtensionMethod, AstStockIcons.PrivateExtensionMethod, AstStockIcons.ExtensionMethod, AstStockIcons.ProtectedExtensionMethod, AstStockIcons.InternalExtensionMethod, AstStockIcons.ProtectedOrInternalExtensionMethod, AstStockIcons.InternalAndProtectedExtensionMethod
 
120
                };
 
121
                static readonly IconId[] propertyIconTable = {
 
122
                        AstStockIcons.Property, AstStockIcons.PrivateProperty, AstStockIcons.Property, AstStockIcons.ProtectedProperty, AstStockIcons.InternalProperty, AstStockIcons.ProtectedOrInternalProperty, AstStockIcons.InternalAndProtectedProperty
 
123
                };
 
124
                static readonly IconId[] eventIconTable = {
 
125
                        AstStockIcons.Event, AstStockIcons.PrivateEvent, AstStockIcons.Event, AstStockIcons.ProtectedEvent, AstStockIcons.InternalEvent, AstStockIcons.ProtectedOrInternalEvent, AstStockIcons.InternalAndProtectedEvent
 
126
                };
 
127
 
 
128
                static bool GetAccessibility (EntityDeclaration element, out Accessibility acc)
 
129
                {
 
130
                        if (element.Parent is TypeDeclaration && ((TypeDeclaration)element.Parent).ClassType == ClassType.Interface) {
 
131
                                acc = Accessibility.Public;
 
132
                                return true;
 
133
                        }
 
134
                        bool result = false;
 
135
                        acc = Accessibility.Private;
 
136
                        if (element is TypeDeclaration && !(element.Parent is TypeDeclaration))
 
137
                                acc = Accessibility.Internal;
110
138
                        if (element.HasModifier (Modifiers.Public)) {
111
139
                                acc = Accessibility.Public;
112
 
                        } else if (element.HasModifier (Modifiers.Protected)) {
113
 
                                acc = Accessibility.Protected;
 
140
                                result = true;
114
141
                        } else if (element.HasModifier (Modifiers.Private)) {
115
142
                                acc = Accessibility.Private;
116
 
                        }
 
143
                                result = true;
 
144
                        } else if (element.HasModifier (Modifiers.Protected | Modifiers.Internal)) {
 
145
                                acc = Accessibility.ProtectedOrInternal;
 
146
                                result = true;
 
147
                        } else if (element.HasModifier (Modifiers.Protected)) {
 
148
                                acc = Accessibility.Protected;
 
149
                                result = true;
 
150
                        } else if (element.HasModifier (Modifiers.Internal)) {
 
151
                                acc = Accessibility.Internal;
 
152
                                result = true;
 
153
                        } 
 
154
                        return result;
 
155
                }
 
156
                
 
157
                public static string GetStockIcon (this EntityDeclaration element, bool showAccessibility = true)
 
158
                {
 
159
                        Accessibility acc = Accessibility.Public;
 
160
 
117
161
                        
 
162
                        if (element is Accessor) {
 
163
                                if (showAccessibility) {
 
164
                                        if (!GetAccessibility (element, out acc))
 
165
                                                GetAccessibility (element.Parent as EntityDeclaration, out acc);
 
166
                                }
 
167
 
 
168
                                return methodIconTable [(int) (acc)];
 
169
                        }
 
170
 
 
171
                        if (showAccessibility) {
 
172
                                GetAccessibility (element, out acc);
 
173
                        }
 
174
 
118
175
                        if (element is TypeDeclaration) {
119
176
                                var type = element as TypeDeclaration;
120
177
                                switch (type.ClassType) {
121
178
                                case ClassType.Class:
122
 
                                        return typeIconTable [0, ModifierToOffset (acc)];
 
179
                                        return typeIconTable [0, (int) (acc)];
123
180
                                case ClassType.Struct:
124
 
                                        return typeIconTable [3, ModifierToOffset (acc)];
 
181
                                        return typeIconTable [3, (int) (acc)];
125
182
                                case ClassType.Interface:
126
 
                                        return typeIconTable [2, ModifierToOffset (acc)];
 
183
                                        return typeIconTable [2, (int) (acc)];
127
184
                                case ClassType.Enum:
128
 
                                        return typeIconTable [1, ModifierToOffset (acc)];
 
185
                                        return typeIconTable [1, (int) (acc)];
129
186
                                default:
130
187
                                        throw new ArgumentOutOfRangeException ();
131
188
                                }
132
189
                        }
133
190
                        if (element is DelegateDeclaration)
134
 
                                return typeIconTable [4, ModifierToOffset (acc)];
 
191
                                return typeIconTable [4, (int) (acc)];
135
192
 
136
193
                        // member accessibility
137
 
                        acc = Accessibility.Private;
138
 
                        if (element.HasModifier (Modifiers.Public)) {
139
 
                                acc = Accessibility.Public;
140
 
                        } else if (element.HasModifier (Modifiers.Protected)) {
141
 
                                acc = Accessibility.Protected;
142
 
                        } else if (element.HasModifier (Modifiers.Internal)) {
143
 
                                acc = Accessibility.Internal;
144
 
                        }
 
194
                        GetAccessibility (element, out acc);
145
195
 
146
196
                        if (element is MethodDeclaration) {
147
197
                                var method = element as MethodDeclaration;
148
198
                                if (method.IsExtensionMethod)
149
 
                                        return extensionMethodIconTable [ModifierToOffset (acc)];
150
 
                                return methodIconTable [ModifierToOffset (acc)];
 
199
                                        return extensionMethodIconTable [(int) (acc)];
 
200
                                return methodIconTable [(int) (acc)];
151
201
                        }
152
202
                        if (element is OperatorDeclaration || element is ConstructorDeclaration || element is DestructorDeclaration || element is Accessor)
153
 
                                return methodIconTable [ModifierToOffset (acc)];
 
203
                                return methodIconTable [(int) (acc)];
154
204
 
155
205
                        if (element is PropertyDeclaration)
156
 
                                return propertyIconTable [ModifierToOffset (acc)];
 
206
                                return propertyIconTable [(int) (acc)];
157
207
                        if (element is EventDeclaration || element is CustomEventDeclaration)
158
 
                                return eventIconTable [ModifierToOffset (acc)];
159
 
 
160
 
                        return fieldIconTable [ModifierToOffset (acc)];
 
208
                                return eventIconTable [(int) (acc)];
 
209
                         if (element.Parent is TypeDeclaration && ((TypeDeclaration)element.Parent).ClassType == ClassType.Enum)
 
210
                                acc = Accessibility.Public;
 
211
                        return fieldIconTable [(int) (acc)];
161
212
                }
162
213
        }
163
214