Skip to content

Commit ba6bc72

Browse files
committed
[Java.Interop.Tools.JavaSource] Parse {@param} tags
Fixes: #1042 Translates `{@param foo}` into `<paramref>foo</paramref>`, which should fix ~70 instances of broken summary/remarks/param elements.
1 parent 9e858bb commit ba6bc72

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

src/Java.Interop.Tools.JavaSource/Java.Interop.Tools.JavaSource/SourceJavadocToXmldocGrammar.InlineTagsBnfTerms.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ internal void CreateRules (SourceJavadocToXmldocGrammar grammar)
2828
| LiteralDeclaration
2929
| SeeDeclaration
3030
| ValueDeclaration
31+
| InlineParamDeclaration
3132
;
3233

3334
CodeDeclaration.Rule = grammar.ToTerm ("{@code") + InlineValue + "}";
@@ -97,6 +98,12 @@ internal void CreateRules (SourceJavadocToXmldocGrammar grammar)
9798
parseNode.AstNode = new XText ("To be added");
9899
}
99100
};
101+
102+
InlineParamDeclaration.Rule = grammar.ToTerm ("{@param") + InlineValue + "}";
103+
InlineParamDeclaration.AstConfig.NodeCreator = (context, parseNode) => {
104+
var target = parseNode.ChildNodes [1].AstNode;
105+
parseNode.AstNode = new XElement ("paramref", target);
106+
};
100107
}
101108

102109
public readonly NonTerminal AllInlineTerms = new NonTerminal (nameof (AllInlineTerms), ConcatChildNodes);
@@ -129,6 +136,8 @@ internal void CreateRules (SourceJavadocToXmldocGrammar grammar)
129136

130137
// https://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#value
131138
public readonly NonTerminal ValueDeclaration = new NonTerminal (nameof (ValueDeclaration));
139+
140+
public readonly NonTerminal InlineParamDeclaration = new NonTerminal (nameof (InlineParamDeclaration));
132141
}
133142
}
134143
}

tests/Java.Interop.Tools.JavaSource-Tests/SourceJavadocToXmldocGrammar.InlineTagsBnfTermsTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,15 @@ public void ValueDeclaration ()
9898
Assert.IsFalse (r.HasErrors (), DumpMessages (r, p));
9999
Assert.AreEqual ("<c>#field</c>", r.Root.AstNode.ToString ());
100100
}
101+
102+
[Test]
103+
public void InlineParamDeclaration ()
104+
{
105+
var p = CreateParser (g => g.InlineTagsTerms.InlineParamDeclaration);
106+
107+
var r = p.Parse ("{@param phoneNumberString}");
108+
Assert.IsFalse (r.HasErrors (), DumpMessages (r, p));
109+
Assert.AreEqual ("<paramref>phoneNumberString</paramref>", r.Root.AstNode.ToString ());
110+
}
101111
}
102112
}

tests/Java.Interop.Tools.JavaSource-Tests/SourceJavadocToXmldocParserTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,12 @@ more description here.
188188
How about another link <a href=""http://man7.org/linux/man-pages/man2/accept.2.html"">accept(2)</a>
189189
@param manifest The value of the <a
190190
href=""{@docRoot}guide/topics/manifest/manifest-element.html#vcode"">{@code
191-
android:versionCode}</a> manifest attribute.
191+
android:versionCode}</a> manifest attribute. See {@param empty}.
192192
@param empty
193193
@return the return value
194194
",
195195
FullXml = $@"<member>
196-
<param name=""manifest"">The value of the <see href=""{DocRootPrefixExpected}guide/topics/manifest/manifest-element.html#vcode""><c>android:versionCode</c></see> manifest attribute.</param>
196+
<param name=""manifest"">The value of the <see href=""{DocRootPrefixExpected}guide/topics/manifest/manifest-element.html#vcode""><c>android:versionCode</c></see> manifest attribute. See <paramref>empty</paramref>.</param>
197197
<param name=""empty"">empty</param>
198198
<summary>See <see href=""http://man7.org/linux/man-pages/man2/accept.2.html"">accept(2)</see>.</summary>
199199
<remarks>
@@ -204,7 +204,7 @@ more description here.
204204
<returns>the return value</returns>
205205
</member>",
206206
IntelliSenseXml = $@"<member>
207-
<param name=""manifest"">The value of the <see href=""{DocRootPrefixExpected}guide/topics/manifest/manifest-element.html#vcode""><c>android:versionCode</c></see> manifest attribute.</param>
207+
<param name=""manifest"">The value of the <see href=""{DocRootPrefixExpected}guide/topics/manifest/manifest-element.html#vcode""><c>android:versionCode</c></see> manifest attribute. See <paramref>empty</paramref>.</param>
208208
<param name=""empty"">empty</param>
209209
<summary>See <see href=""http://man7.org/linux/man-pages/man2/accept.2.html"">accept(2)</see>.</summary>
210210
<returns>the return value</returns>

0 commit comments

Comments
 (0)