Fix bugs in sizing TableLayoutPanel (Xamarin bug 18638)
[mono.git] / mcs / tools / corcompare / mono-api-html / ConstructorComparer.cs
1 // 
2 // Authors
3 //    Sebastien Pouliot  <sebastien@xamarin.com>
4 //
5 // Copyright 2013 Xamarin Inc. http://www.xamarin.com
6 // 
7 // Permission is hereby granted, free of charge, to any person obtaining
8 // a copy of this software and associated documentation files (the
9 // "Software"), to deal in the Software without restriction, including
10 // without limitation the rights to use, copy, modify, merge, publish,
11 // distribute, sublicense, and/or sell copies of the Software, and to
12 // permit persons to whom the Software is furnished to do so, subject to
13 // the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be
16 // included in all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 //
26
27 using System;
28 using System.Collections.Generic;
29 using System.Reflection;
30 using System.Text;
31 using System.Xml.Linq;
32
33 namespace Xamarin.ApiDiff {
34
35         public class ConstructorComparer : MemberComparer {
36
37                 public override string GroupName {
38                         get { return "constructors"; }
39                 }
40
41                 public override string ElementName {
42                         get { return "constructor"; }
43                 }
44
45                 public override bool Find (XElement e)
46                 {
47                         return (e.Attribute ("name").Value == Source.Attribute ("name").Value);
48                 }
49
50                 public override string GetDescription (XElement e)
51                 {
52                         var sb = new StringBuilder ();
53
54                         var attribs = e.Attribute ("attrib");
55                         if (attribs != null) {
56                                 var attr = (MethodAttributes) Int32.Parse (attribs.Value);
57                                 if ((attr & MethodAttributes.Public) != MethodAttributes.Public) {
58                                         sb.Append ("protected ");
59                                 } else {
60                                         sb.Append ("public ");
61                                 }
62
63                                 if ((attr & MethodAttributes.Static) != 0) {
64                                         sb.Append ("static ");
65                                 } else if ((attr & MethodAttributes.Virtual) != 0) {
66                                         if ((attr & MethodAttributes.VtableLayoutMask) == 0)
67                                                 sb.Append ("override ");
68                                         else
69                                                 sb.Append ("virtual ");
70                                 }
71                         }
72
73                         string name = e.GetAttribute ("name");
74
75                         var r = e.GetTypeName ("returntype");
76                         if (r != null) {
77                                 // ctor dont' have a return type
78                                 sb.Append (r).Append (' ');
79                         } else {
80                                 // show the constructor as it would be defined in C#
81                                 name = name.Replace (".ctor", State.Type);
82                         }
83
84                         // the XML file `name` does not contain parameter names, so we must process them ourselves
85                         // which gives us the opportunity to simplify type names
86                         sb.Append (name.Substring (0, name.IndexOf ('(')));
87
88                         var genericp = e.Element ("generic-parameters");
89                         if (genericp != null) {
90                                 var list = new List<string> ();
91                                 foreach (var p in genericp.Elements ("generic-parameter")) {
92                                         list.Add (p.GetTypeName ("name"));
93                                 }
94                                 sb.Append ("&lt;").Append (String.Join (", ", list)).Append ("&gt;");
95                         }
96
97                         sb.Append (" (");
98                         var parameters = e.Element ("parameters");
99                         if (parameters != null) {
100                                 var list = new List<string> ();
101                                 foreach (var p in parameters.Elements ("parameter")) {
102                                         var pTypeName   = p.GetTypeName ("type");
103                                         list.Add (State.IgnoreParameterNameChanges
104                                                 ? pTypeName
105                                                 : pTypeName + " " + p.GetAttribute ("name"));
106                                 }
107                                 sb.Append (String.Join (", ", list));
108                         }
109                         sb.Append (");");
110
111                         return sb.ToString ();
112                 }
113         }
114 }