Skip to content
This repository was archived by the owner on Jul 6, 2026. It is now read-only.

Commit 7f1d2d7

Browse files
authored
[generator] Fix <remove-attr/> metadata (#999)
Fixes: #976 Given an `api.xml` element like: <package name='my.package'> <class name='MyClass' api-since='29' /> </package> One would expect to be able to remove the `class/@api-since` attribute with this metadata: <remove-attr path='/api/package[@name='my.package']/class[@name='MyClass']' name='api-since' /> However, even though `generator` reads the `name` attribute, it then proceeds to ignore it and remove *all* attributes on the matched node, resulting in: <package name='my.package'> <class /> </package> This seems unintuitive, and I'm not sure how this could ever be successfully used in a binding project, since leaving an empty `<class/>`/etc. node causes `generator` to crash. Update `<remove-attr/>` to work as expected, removing the named attribute.
1 parent 265ad76 commit 7f1d2d7

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

‎src/Java.Interop.Tools.Generator/Metadata/FixupXmlDocument.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public void Apply (ApiXmlDocument apiDocument, string apiLevelString, int produc
153153
varmatched=false;
154154

155155
foreach(varnodeinnodes){
156-
node.RemoveAttributes();
156+
node.Attributes(name).Remove();
157157
matched=true;
158158
}
159159

‎tests/generator-Tests/Unit-Tests/FixupXmlDocumentTests.cs‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,19 @@ public void RemoveAttribute ()
8282

8383
api.ApplyFixupFile(fixup);
8484

85-
Assert.AreEqual("<api><package /><package name='java' jni-name='java' /></api>",api.ApiDocument.ToString(SaveOptions.DisableFormatting).Replace('\"','\''));
85+
Assert.AreEqual("<api><package jni-name='android' /><package name='java' jni-name='java' /></api>",api.ApiDocument.ToString(SaveOptions.DisableFormatting).Replace('\"','\''));
86+
}
87+
88+
[Test]
89+
publicvoidRemoveNotFoundAttribute()
90+
{
91+
// Attribute 'foo' doesn't exist on node
92+
varapi=GetXmlApiDocument();
93+
varfixup=GetFixupXmlDocument("<remove-attr path=\"/api/package[@name='android']\" name='foo' />");
94+
95+
api.ApplyFixupFile(fixup);
96+
97+
Assert.AreEqual("<api><package name='android' jni-name='android' /><package name='java' jni-name='java' /></api>",api.ApiDocument.ToString(SaveOptions.DisableFormatting).Replace('\"','\''));
8698
}
8799

88100
[Test]

0 commit comments

Comments
 (0)