1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Linq;
namespace Xamarin.ApiDiff
{
public class ApiChange
{
public string Header;
public StringBuilder Member = new StringBuilder ();
public bool Breaking;
public bool AnyChange;
public bool HasIgnoredChanges;
public ApiChange Append (string text)
{
Member.Append (text);
return this;
}
public ApiChange AppendAdded (string text, bool breaking = false)
{
if (breaking)
Member.Append ("<span style='text-decoration: underline'>");
if (State.Colorize)
Member.Append ("<span style='color:green'>");
Member.Append (text);
if (State.Colorize)
Member.Append ("</span>");
if (breaking)
Member.Append ("</span>");
Breaking |= breaking;
AnyChange = true;
return this;
}
public ApiChange AppendRemoved (string text, bool breaking = true)
{
Member.Append ("<span style='text-decoration: line-through'>");
if (State.Colorize && breaking)
Member.Append ("<span style='color:red'>");
Member.Append (text);
if (State.Colorize && breaking)
Member.Append ("</span>");
Member.Append ("</span>");
Breaking |= breaking;
AnyChange = true;
return this;
}
public ApiChange AppendModified (string old, string @new, bool breaking = true)
{
if (old.Length > 0)
AppendRemoved (old, breaking);
if (old.Length > 0 && @new.Length > 0)
Append (" ");
if (@new.Length > 0)
AppendAdded (@new);
Breaking |= breaking;
AnyChange = true;
return this;
}
}
public class ApiChanges : Dictionary<string, List<ApiChange>> {
public void Add (XElement source, XElement target, ApiChange change)
{
if (!change.AnyChange) {
// This is most likely because the rendering doesn't take into account something that's different (solution: fix rendering).
if (!change.HasIgnoredChanges) {
var isField = source.Name.LocalName == "field";
if (isField) {
Console.WriteLine ("Comparison resulting in no changes (src: {2} dst: {3}) :\n{0}\n{1}\n\n", source.ToString (), target.ToString (), source.GetFieldAttributes (), target.GetFieldAttributes ());
} else {
Console.WriteLine ("Comparison resulting in no changes (src: {2} dst: {3}) :\n{0}\n{1}\n\n", source.ToString (), target.ToString (), source.GetMethodAttributes (), target.GetMethodAttributes ());
}
}
return;
}
List<ApiChange> list;
if (!TryGetValue (change.Header, out list)) {
list = new List<ApiChange> ();
base.Add (change.Header, list);
}
list.Add (change);
}
}
}
|