[netcore] Remove local copy of static alc resolve methods
[mono-project.git] / mcs / tools / mono-api-html / ConstructorComparer.cs
blob47594091bfa4199b0da35928cbb5e4024568e153
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:
15 // The above copyright notice and this permission notice shall be
16 // included in all copies or substantial portions of the Software.
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.
27 using System;
28 using System.Collections.Generic;
29 using System.Reflection;
30 using System.Text;
31 using System.Xml.Linq;
33 namespace Mono.ApiTools {
35 // MethodComparer inherits from this one
36 class ConstructorComparer : MemberComparer {
38 public ConstructorComparer (State state)
39 : base (state)
43 public override string GroupName {
44 get { return "constructors"; }
47 public override string ElementName {
48 get { return "constructor"; }
51 public override bool Find (XElement e)
53 return (e.Attribute ("name").Value == Source.Attribute ("name").Value);
56 void RenderReturnType (XElement source, XElement target, ApiChange change)
58 var srcType = source.GetTypeName ("returntype", State);
59 var tgtType = target.GetTypeName ("returntype", State);
61 if (srcType != tgtType) {
62 change.AppendModified (srcType, tgtType, true);
63 change.Append (" ");
64 } else if (srcType != null) {
65 // ctor don't have a return type
66 change.Append (srcType);
67 change.Append (" ");
71 public override bool Equals (XElement source, XElement target, ApiChanges changes)
73 if (base.Equals (source, target, changes))
74 return true;
76 var change = new ApiChange (GetDescription (source), State);
77 change.Header = "Modified " + GroupName;
78 RenderMethodAttributes (source, target, change);
79 RenderReturnType (source, target, change);
80 RenderName (source, target, change);
81 RenderGenericParameters (source, target, change);
82 RenderParameters (source, target, change);
84 changes.Add (source, target, change);
86 return false;
89 public override string GetDescription (XElement e)
91 var sb = new StringBuilder ();
93 var attribs = e.Attribute ("attrib");
94 if (attribs != null) {
95 var attr = (MethodAttributes) Int32.Parse (attribs.Value);
96 if ((attr & MethodAttributes.Public) != MethodAttributes.Public) {
97 sb.Append ("protected ");
98 } else {
99 sb.Append ("public ");
102 if ((attr & MethodAttributes.Static) != 0) {
103 sb.Append ("static ");
104 } else if ((attr & MethodAttributes.Virtual) != 0) {
105 if ((attr & MethodAttributes.VtableLayoutMask) == 0)
106 sb.Append ("override ");
107 else
108 sb.Append ("virtual ");
112 string name = e.GetAttribute ("name");
114 var r = e.GetTypeName ("returntype", State);
115 if (r != null) {
116 // ctor dont' have a return type
117 sb.Append (r).Append (' ');
118 } else {
119 // show the constructor as it would be defined in C#
120 name = name.Replace (".ctor", State.Type);
123 // the XML file `name` does not contain parameter names, so we must process them ourselves
124 // which gives us the opportunity to simplify type names
125 sb.Append (name.Substring (0, name.IndexOf ('(')));
127 var genericp = e.Element ("generic-parameters");
128 if (genericp != null) {
129 var list = new List<string> ();
130 foreach (var p in genericp.Elements ("generic-parameter")) {
131 list.Add (p.GetTypeName ("name", State));
133 sb.Append (Formatter.LesserThan).Append (String.Join (", ", list)).Append (Formatter.GreaterThan);
136 sb.Append (" (");
137 var parameters = e.Element ("parameters");
138 if (parameters != null) {
139 var list = new List<string> ();
140 foreach (var p in parameters.Elements ("parameter")) {
141 var param = p.GetTypeName ("type", State);
142 if (!State.IgnoreParameterNameChanges)
143 param += " " + p.GetAttribute ("name");
145 var direction = p.GetAttribute ("direction");
146 if (direction?.Length > 0)
147 param = direction + " " + param;
149 list.Add (param);
151 sb.Append (String.Join (", ", list));
153 sb.Append (");");
155 return sb.ToString ();