Skip to content

Commit 963a6eb

Browse files
atsushienojonpryor
authored andcommitted
[Xamarin.Android.Tools.ApiXmlAdjuster] Cleanup (#82)
Rename `reader` variable to `writer`, to match actual use/semantics. Avoid recurring `<package>` element occurrence: when reading multiple API XML files which contain the same `//package/@name` value, there would be multiple `<package/>` elements in the resulting document. It was almost harmless, but it could result in XPath query differences.
1 parent a1d3ecc commit 963a6eb

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/Xamarin.Android.Tools.ApiXmlAdjuster/JavaApiXmlGeneratorExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ public static class JavaApiXmlGeneratorExtensions
1010
{
1111
public static void Save (this JavaApi api, string xmlfile)
1212
{
13-
using (var reader = XmlWriter.Create (xmlfile, new XmlWriterSettings () {
13+
using (var writer = XmlWriter.Create (xmlfile, new XmlWriterSettings () {
1414
Encoding = new UTF8Encoding (false, true),
1515
Indent = true,
1616
OmitXmlDeclaration = true,
1717
}))
18-
api.Save (reader);
18+
api.Save (writer);
1919
}
2020

2121
public static void Save (this JavaApi api, XmlWriter writer)

src/Xamarin.Android.Tools.ApiXmlAdjuster/JavaApiXmlLoaderExtensions.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@ public static void Load (this JavaApi api, XmlReader reader, bool isReferenceOnl
3131
break; // </api>
3232
if (reader.NodeType != XmlNodeType.Element || reader.LocalName != "package")
3333
throw XmlUtil.UnexpectedElementOrContent ("api", reader, "package");
34-
var pkg = api.Packages.FirstOrDefault (p => p.Name == reader.GetAttribute ("name")) ?? new JavaPackage (api);
34+
var pkg = api.Packages.FirstOrDefault (p => p.Name == reader.GetAttribute ("name"));
35+
if (pkg == null) {
36+
pkg = new JavaPackage (api);
37+
api.Packages.Add (pkg);
38+
}
3539
pkg.Load (reader, isReferenceOnly);
36-
api.Packages.Add (pkg);
3740
} while (true);
3841

3942
XmlUtil.VerifyEndElement (reader, "api");

0 commit comments

Comments
 (0)