Skip to content

Commit 7716ae5

Browse files
authored
[generator] Merge Javadoc return values on bound properties (#995)
Context: 0e01fb5 Context: https://developer.android.com/reference/android/animation/Keyframe#setInterpolator(android.animation.TimeInterpolator) The Java source for `Keyframe.setInterpolator` incidentally includes a `@return` tag, even though the return type is void: /** * Sets the optional interpolator for this Keyframe. A value of <code>null</code> indicates * that there is no interpolation, which is the same as linear interpolation. * * @return The optional interpolator for this Keyframe. */ public void setInterpolator(TimeInterpolator interpolator) { mInterpolator = interpolator; } This causes us to generate multiple `<returns>` C# doc comment tags on the `Android.Animation.Keyframe.Interpolator` property, as the setter and getter both include the same `@return` tag: /// <summary>Gets the optional interpolator for this Keyframe. -or- Sets the optional interpolator for this Keyframe.</summary> /// ... /// <returns>The optional interpolator for this Keyframe.</returns> /// <returns>The optional interpolator for this Keyframe.</returns> public virtual unsafe Android.Animation.ITimeInterpolator? Interpolator { The `mdoc` tool does not handle this well, and will continuously append a `<value/>` element on this property every time the tool runs against our improperly formatted C# doc comments: <Docs> <summary>Gets the optional interpolator for this Keyframe. -or- Sets the optional interpolator for this Keyframe.</summary> <value>The optional interpolator for this Keyframe.</value> <value>The optional interpolator for this Keyframe.</value> <value>The optional interpolator for this Keyframe.</value> … <since version="Added in API level 11" /> </Docs> Fix this by attempting to merge `<returns/>` elements for property getters and setters.
1 parent 51c3dae commit 7716ae5

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tools/generator/SourceWriters/BoundProperty.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ void AddJavadocs (Property property)
179179

180180
MergeSummary (memberDocs, setterDocs);
181181
MergeRemarks (memberDocs, setterDocs);
182+
MergeReturns (memberDocs, setterDocs);
182183

183184
memberDocs.Add (setterDocs.Nodes ());
184185
}
@@ -223,5 +224,20 @@ static void MergeRemarks (XElement mergeInto, XElement mergeFrom)
223224
toContent.Add (fromContent.Nodes ());
224225
}
225226
}
227+
228+
static void MergeReturns (XElement mergeInto, XElement mergeFrom)
229+
{
230+
var toContent = mergeInto.Element ("returns");
231+
var fromContent = mergeFrom.Element ("returns");
232+
233+
if (toContent != null && fromContent != null) {
234+
if (toContent.Value == fromContent.Value) {
235+
fromContent.Remove ();
236+
} else {
237+
toContent.Add (" ");
238+
toContent.Add (fromContent.Nodes ());
239+
}
240+
}
241+
}
226242
}
227243
}

0 commit comments

Comments
 (0)