~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeTemplates/ExpansionObject.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
using MonoDevelop.Projects.Dom.Parser;
35
35
using MonoDevelop.Projects.Dom.Output;
36
36
using Mono.TextEditor.PopupWindow;
 
37
using Mono.TextEditor;
37
38
 
38
39
namespace MonoDevelop.Ide.CodeTemplates
39
40
{
53
54
                        set;
54
55
                }
55
56
                
56
 
                public DomLocation InsertPosition {
 
57
                public DocumentLocation InsertPosition {
57
58
                        get;
58
59
                        set;
59
60
                }
96
97
                        return type.Name;
97
98
                }
98
99
                
 
100
                public string GetConstructorModifier ()
 
101
                {
 
102
                        if (CurrentContext.ParsedDocument == null)
 
103
                                return null;
 
104
                        IType type = CurrentContext.ParsedDocument.CompilationUnit.GetTypeAt (CurrentContext.InsertPosition.Line, CurrentContext.InsertPosition.Column);
 
105
                        if (type == null)
 
106
                                return "";
 
107
                        return type.IsStatic ? "static " : "public ";
 
108
                }
 
109
                
99
110
                public string GetLengthProperty (Func<string, string> callback, string varName)
100
111
                {
101
112
                        if (callback == null)
105
116
                        
106
117
                        ITextEditorResolver textEditorResolver = CurrentContext.Document.GetContent <ITextEditorResolver> ();
107
118
                        if (textEditorResolver != null) {
108
 
                                ResolveResult result = textEditorResolver.GetLanguageItem (CurrentContext.Document.TextEditor.GetPositionFromLineColumn (CurrentContext.InsertPosition.Line, CurrentContext.InsertPosition.Column), var);
109
 
                                if (result != null && (result.ResolvedType.ArrayDimensions > 0 || result.ResolvedType.FullName == DomReturnType.String.FullName))
 
119
                                ResolveResult result = textEditorResolver.GetLanguageItem (CurrentContext.Document.Editor.Document.LocationToOffset (CurrentContext.InsertPosition.Line, CurrentContext.InsertPosition.Column), var);
 
120
                                if (result != null && result.ResolvedType != null && (result.ResolvedType.ArrayDimensions > 0 || result.ResolvedType.FullName == DomReturnType.String.FullName))
110
121
                                        return "Length";
111
122
                        }
112
123
                        return "Count";
120
131
                        string var = callback (varName);
121
132
                        ITextEditorResolver textEditorResolver = CurrentContext.Document.GetContent <ITextEditorResolver> ();
122
133
                        if (textEditorResolver != null) {
123
 
                                ResolveResult result =  textEditorResolver.GetLanguageItem (CurrentContext.Document.TextEditor.CursorPosition, var);
 
134
                                ResolveResult result =  textEditorResolver.GetLanguageItem (CurrentContext.Document.Editor.Caret.Offset, var);
124
135
                                if (result != null) {
125
136
                                        IReturnType componentType =  DomType.GetComponentType (CurrentContext.ProjectDom, result.ResolvedType);
126
137
                                        if (componentType != null) {
139
150
                        var ext = CurrentContext.Document.GetContent <CompletionTextEditorExtension> ();
140
151
                        if (ext != null) {
141
152
                                if (list == null)
142
 
                                        list = ext.CodeCompletionCommand (CurrentContext.Document.TextEditor.CurrentCodeCompletionContext);
 
153
                                        list = ext.CodeCompletionCommand (CurrentContext.Document.GetContent <MonoDevelop.Ide.CodeCompletion.ICompletionWidget> ().CurrentCodeCompletionContext);
143
154
                                
144
155
                                foreach (object o in list) {
145
156
                                        MonoDevelop.Ide.CodeCompletion.MemberCompletionData data = o as MonoDevelop.Ide.CodeCompletion.MemberCompletionData;
182
193
                {
183
194
                        if (CurrentContext.ParsedDocument == null)
184
195
                                return fullTypeName;
185
 
                        
186
 
                        return CurrentContext.ParsedDocument.CompilationUnit.ShortenTypeName (new DomReturnType (fullTypeName), CurrentContext.InsertPosition).FullName;
 
196
                        DomReturnType returnType;
 
197
                        int idx = fullTypeName.IndexOf ('#');
 
198
                        if (idx < 0) {
 
199
                                returnType = new DomReturnType (fullTypeName);
 
200
                        } else {
 
201
                                returnType = new DomReturnType (fullTypeName.Substring (0, idx), fullTypeName.Substring (idx + 1));
 
202
                        }
 
203
                        return CurrentContext.ParsedDocument.CompilationUnit.ShortenTypeName (returnType, CurrentContext.InsertPosition.Line, CurrentContext.InsertPosition.Column).FullName;
187
204
                }
188
205
                
189
206
                static Regex functionRegEx = new Regex ("([^(]*)\\(([^(]*)\\)", RegexOptions.Compiled);
195
212
                                return new string[] {
196
213
                                        "",
197
214
                                        "GetCurrentClassName()",
 
215
                                        "GetConstructorModifier()",
198
216
                                        "GetSimpleTypeName(\"LongName\")",
199
217
                                        "GetLengthProperty(\"Var\")",
200
218
                                        "GetComponentTypeOf(\"Var\")",
215
233
                                return GetCollections ();
216
234
                        case "GetCurrentClassName":
217
235
                                return new CodeTemplateListDataProvider (GetCurrentClassName ());
 
236
                        case "GetConstructorModifier":
 
237
                                return new CodeTemplateListDataProvider (GetConstructorModifier ());
 
238
                                
218
239
                        case "GetSimpleTypeName":
219
240
                                return new CodeTemplateListDataProvider (GetSimpleTypeName (match.Groups[2].Value.Trim ('"')));
220
241
                        case "GetLengthProperty":
221
 
                                return new CodeTemplateListDataProvider (GetLengthProperty (callback, match.Groups[2].Value.Trim ('"')));
 
242
                                return new CodeTemplateListDataProvider (GetLengthProperty (callback, match.Groups == null || match.Groups.Count < 3 ? null : match.Groups[2].Value.Trim ('"')));
222
243
                        case "GetComponentTypeOf":
223
244
                                return new CodeTemplateListDataProvider (GetComponentTypeOf (callback, match.Groups[2].Value.Trim ('"')));
224
245
                        }