2
// TemplateParameterDataProvider.cs
5
// Mike Krüger <mkrueger@xamarin.com>
7
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
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:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
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
27
using System.Collections.Generic;
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;
45
namespace MonoDevelop.CSharp.Completion
47
public class TemplateParameterDataProvider: IParameterDataProvider
50
//CSharpCompletionTextEditorExtension ext;
53
CSharpAmbience ambience = new CSharpAmbience ();
55
public int StartOffset {
61
public TemplateParameterDataProvider (int startOffset, CSharpCompletionTextEditorExtension ext, IEnumerable<IType> types)
63
this.startOffset = startOffset;
65
this.types = new List<IType> (types);
68
static int TypeComparer (IType left, IType right)
70
return left.TypeParameterCount - right.TypeParameterCount;
73
#region IParameterDataProvider implementation
75
protected virtual string GetPrefix (IMethod method)
77
var flags = OutputFlags.ClassBrowserEntries | OutputFlags.IncludeMarkup | OutputFlags.IncludeGenerics;
78
return ambience.GetString (method.ReturnType, flags) + " ";
81
public string GetHeading (int overload, string[] parameterMarkup, int currentParameter)
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 ("<");
88
int parameterCount = 0;
89
foreach (string parameter in parameterMarkup) {
90
if (parameterCount > 0)
92
result.Append (parameter);
95
result.Append (">");
97
return result.ToString ();
100
public string GetDescription (int overload, int currentParameter)
105
public string GetParameterDescription (int overload, int paramIndex)
107
var type = types[overload];
109
if (paramIndex < 0 || paramIndex >= type.TypeParameterCount)
112
return ambience.GetString (type.GetDefinition ().TypeParameters [paramIndex], OutputFlags.AssemblyBrowserDescription | OutputFlags.HideExtensionsParameter | OutputFlags.IncludeGenerics | OutputFlags.IncludeModifiers | OutputFlags.HighlightName);
115
public int GetParameterCount (int overload)
117
if (overload >= Count)
119
var type = types[overload];
120
return type != null ? type.TypeParameterCount : 0;
123
public bool AllowParameterList (int overload)
130
return types != null ? types.Count : 0;