2016-08-03 10:59:49 +00:00
|
|
|
//
|
|
|
|
// Authors
|
|
|
|
// Sebastien Pouliot <sebastien@xamarin.com>
|
|
|
|
//
|
|
|
|
// Copyright 2013 Xamarin Inc. http://www.xamarin.com
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
// a copy of this software and associated documentation files (the
|
|
|
|
// "Software"), to deal in the Software without restriction, including
|
|
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
// distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
// permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
// the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be
|
|
|
|
// included in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
//
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
2018-10-09 08:20:59 +00:00
|
|
|
namespace Mono.ApiTools {
|
2016-08-03 10:59:49 +00:00
|
|
|
|
2018-10-09 08:20:59 +00:00
|
|
|
class NamespaceComparer : Comparer {
|
2016-08-03 10:59:49 +00:00
|
|
|
|
|
|
|
ClassComparer comparer;
|
|
|
|
|
2018-10-09 08:20:59 +00:00
|
|
|
public NamespaceComparer (State state)
|
|
|
|
: base (state)
|
2016-08-03 10:59:49 +00:00
|
|
|
{
|
2018-10-09 08:20:59 +00:00
|
|
|
comparer = new ClassComparer (state);
|
2016-08-03 10:59:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Compare (XElement source, XElement target)
|
|
|
|
{
|
|
|
|
var s = source.Element ("namespaces");
|
|
|
|
var t = target.Element ("namespaces");
|
|
|
|
if (XNode.DeepEquals (s, t))
|
|
|
|
return;
|
|
|
|
Compare (s.Elements ("namespace"), t.Elements ("namespace"));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void SetContext (XElement current)
|
|
|
|
{
|
|
|
|
State.Namespace = current.Attribute ("name").Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Added (XElement target, bool wasParentAdded)
|
|
|
|
{
|
2018-06-02 08:53:49 +00:00
|
|
|
var namespaceDescription = $"{State.Namespace}: Added namespace";
|
2018-02-22 09:08:32 +00:00
|
|
|
State.LogDebugMessage ($"Possible -n value: {namespaceDescription}");
|
|
|
|
if (State.IgnoreNew.Any (re => re.IsMatch (namespaceDescription)))
|
2016-08-03 10:59:49 +00:00
|
|
|
return;
|
|
|
|
|
2018-06-02 08:53:49 +00:00
|
|
|
Formatter.BeginNamespace (Output, "New ");
|
2016-08-03 10:59:49 +00:00
|
|
|
// list all new types
|
2018-06-02 08:53:49 +00:00
|
|
|
foreach (var addedType in target.Element ("classes").Elements ("class")) {
|
|
|
|
State.Type = addedType.Attribute ("name").Value;
|
2016-08-03 10:59:49 +00:00
|
|
|
comparer.Added (addedType, true);
|
2018-06-02 08:53:49 +00:00
|
|
|
}
|
|
|
|
Formatter.EndNamespace (Output);
|
2016-08-03 10:59:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void Modified (XElement source, XElement target, ApiChanges differences)
|
|
|
|
{
|
|
|
|
var output = Output;
|
|
|
|
State.Output = new StringWriter ();
|
|
|
|
comparer.Compare (source, target);
|
|
|
|
|
|
|
|
var s = Output.ToString ();
|
|
|
|
State.Output = output;
|
|
|
|
if (s.Length > 0) {
|
|
|
|
var name = target.Attribute ("name").Value;
|
2018-06-02 08:53:49 +00:00
|
|
|
Formatter.BeginNamespace (Output);
|
2016-08-03 10:59:49 +00:00
|
|
|
Output.WriteLine (s);
|
2018-06-02 08:53:49 +00:00
|
|
|
Formatter.EndNamespace (Output);
|
2016-08-03 10:59:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Removed (XElement source)
|
|
|
|
{
|
|
|
|
var name = source.Attribute ("name").Value;
|
2017-09-25 16:57:44 +00:00
|
|
|
|
2018-02-22 09:08:32 +00:00
|
|
|
var namespaceDescription = $"{name}: Removed namespace";
|
|
|
|
State.LogDebugMessage ($"Possible -r value: {namespaceDescription}");
|
|
|
|
if (State.IgnoreRemoved.Any (re => re.IsMatch (namespaceDescription)))
|
2017-09-25 16:57:44 +00:00
|
|
|
return;
|
|
|
|
|
2018-06-02 08:53:49 +00:00
|
|
|
Formatter.BeginNamespace (Output, "Removed ");
|
2016-08-03 10:59:49 +00:00
|
|
|
Output.WriteLine ();
|
|
|
|
// list all removed types
|
2018-06-02 08:53:49 +00:00
|
|
|
foreach (var removedType in source.Element ("classes").Elements ("class")) {
|
|
|
|
State.Type = comparer.GetTypeName (removedType);
|
2016-08-03 10:59:49 +00:00
|
|
|
comparer.Removed (removedType);
|
2018-06-02 08:53:49 +00:00
|
|
|
}
|
|
|
|
Formatter.EndNamespace (Output);
|
2016-08-03 10:59:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|