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

« back to all changes in this revision

Viewing changes to src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/TemplateParameterDataProvider.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:
1
 
// 
2
 
// TemplateParameterDataProvider.cs
3
 
//  
4
 
// Author:
5
 
//       Mike Krüger <mkrueger@xamarin.com>
6
 
// 
7
 
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
8
 
// 
9
 
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
 
// of this software and associated documentation files (the "Software"), to deal
11
 
// in the Software without restriction, including without limitation the rights
12
 
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
 
// copies of the Software, and to permit persons to whom the Software is
14
 
// furnished to do so, subject to the following conditions:
15
 
// 
16
 
// The above copyright notice and this permission notice shall be included in
17
 
// all copies or substantial portions of the Software.
18
 
// 
19
 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
 
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
 
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
 
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
 
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
 
// THE SOFTWARE.
26
 
using System;
27
 
using System.Collections.Generic;
28
 
using System.Text;
29
 
using System.Xml;
30
 
 
31
 
using MonoDevelop.Core;
32
 
using MonoDevelop.Ide.Gui;
33
 
using MonoDevelop.Ide.CodeCompletion;
34
 
using MonoDevelop.CSharp.Formatting;
35
 
using MonoDevelop.CSharp.Parser;
36
 
using System.Text.RegularExpressions;
37
 
using ICSharpCode.NRefactory.CSharp;
38
 
using MonoDevelop.CSharp.Resolver;
39
 
using Mono.TextEditor;
40
 
using ICSharpCode.NRefactory.TypeSystem;
41
 
using ICSharpCode.NRefactory.CSharp.Resolver;
42
 
using MonoDevelop.Ide.TypeSystem;
43
 
using ICSharpCode.NRefactory.Completion;
44
 
 
45
 
namespace MonoDevelop.CSharp.Completion
46
 
{
47
 
        public class TemplateParameterDataProvider: IParameterDataProvider
48
 
        {
49
 
                int startOffset;
50
 
                //CSharpCompletionTextEditorExtension ext;
51
 
                
52
 
                List<IType> types;
53
 
                CSharpAmbience ambience = new CSharpAmbience ();
54
 
 
55
 
                public int StartOffset {
56
 
                        get {
57
 
                                return startOffset;
58
 
                        }
59
 
                }               
60
 
                
61
 
                public TemplateParameterDataProvider (int startOffset, CSharpCompletionTextEditorExtension ext, IEnumerable<IType> types)
62
 
                {
63
 
                        this.startOffset = startOffset;
64
 
//                      this.ext = ext;
65
 
                        this.types = new List<IType> (types);
66
 
                }
67
 
                
68
 
                static int TypeComparer (IType left, IType right)
69
 
                {
70
 
                        return left.TypeParameterCount - right.TypeParameterCount;
71
 
                }
72
 
                
73
 
                #region IParameterDataProvider implementation
74
 
                
75
 
                protected virtual string GetPrefix (IMethod method)
76
 
                {
77
 
                        var flags = OutputFlags.ClassBrowserEntries | OutputFlags.IncludeMarkup | OutputFlags.IncludeGenerics;
78
 
                        return ambience.GetString (method.ReturnType, flags) + " ";
79
 
                }
80
 
                
81
 
                public string GetHeading (int overload, string[] parameterMarkup, int currentParameter)
82
 
                {
83
 
                        var result = new StringBuilder ();
84
 
                        result.Append ("<b>");
85
 
                        result.Append (ambience.GetString (types [overload], OutputFlags.UseFullName | OutputFlags.IncludeMarkup));
86
 
                        result.Append ("</b>");
87
 
                        result.Append ("&lt;");
88
 
                        int parameterCount = 0;
89
 
                        foreach (string parameter in parameterMarkup) {
90
 
                                if (parameterCount > 0)
91
 
                                        result.Append (", ");
92
 
                                result.Append (parameter);
93
 
                                parameterCount++;
94
 
                        }
95
 
                        result.Append ("&gt;");
96
 
                        
97
 
                        return result.ToString ();
98
 
                }
99
 
                
100
 
                public string GetDescription (int overload, int currentParameter)
101
 
                {
102
 
                        return "";
103
 
                }
104
 
                
105
 
                public string GetParameterDescription (int overload, int paramIndex)
106
 
                {
107
 
                        var type = types[overload];
108
 
                        
109
 
                        if (paramIndex < 0 || paramIndex >= type.TypeParameterCount)
110
 
                                return "";
111
 
                        
112
 
                        return ambience.GetString (type.GetDefinition ().TypeParameters [paramIndex], OutputFlags.AssemblyBrowserDescription | OutputFlags.HideExtensionsParameter | OutputFlags.IncludeGenerics | OutputFlags.IncludeModifiers | OutputFlags.HighlightName);
113
 
                }
114
 
                
115
 
                public int GetParameterCount (int overload)
116
 
                {
117
 
                        if (overload >= Count)
118
 
                                return -1;
119
 
                        var type = types[overload];
120
 
                        return type != null ? type.TypeParameterCount : 0;
121
 
                }
122
 
 
123
 
                public bool AllowParameterList (int overload)
124
 
                {
125
 
                        return false;
126
 
                }
127
 
 
128
 
                public int Count {
129
 
                        get {
130
 
                                return types != null ? types.Count : 0;
131
 
                        }
132
 
                }
133
 
                #endregion 
134
 
        }
135
 
}
136