Skip to content

Commit e1ee4b1

Browse files
authored
[Java.Interop.Tools.JavaSource] Parse {@param} tags (#1045)
Fixes: #1042 Translates Javadoc `{@param foo}` into C# `<paramref>foo</paramref>`, which should fix ~70 instances of broken summary/remarks/param elements.
1 parent 07c95e9 commit e1ee4b1

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ internal void CreateRules (SourceJavadocToXmldocGrammar grammar)
3030
| SeeDeclaration
3131
| ValueDeclaration
3232
| IgnorableDeclaration
33+
| InlineParamDeclaration
3334
;
3435

3536
CodeDeclaration.Rule = grammar.ToTerm ("{@code") + InlineValue + "}";
@@ -116,6 +117,12 @@ internal void CreateRules (SourceJavadocToXmldocGrammar grammar)
116117
IgnorableDeclaration.AstConfig.NodeCreator = (context, parseNode) => {
117118
parseNode.AstNode = new XText (parseNode.ChildNodes [0].Term.Name.Trim ());
118119
};
120+
121+
InlineParamDeclaration.Rule = grammar.ToTerm ("{@param") + InlineValue + "}";
122+
InlineParamDeclaration.AstConfig.NodeCreator = (context, parseNode) => {
123+
var target = parseNode.ChildNodes [1].AstNode;
124+
parseNode.AstNode = new XElement ("paramref", target);
125+
};
119126
}
120127

121128
public readonly NonTerminal AllInlineTerms = new NonTerminal (nameof (AllInlineTerms), ConcatChildNodes);
@@ -151,6 +158,7 @@ internal void CreateRules (SourceJavadocToXmldocGrammar grammar)
151158

152159
public readonly NonTerminal IgnorableDeclaration = new NonTerminal (nameof (IgnorableDeclaration));
153160

161+
public readonly NonTerminal InlineParamDeclaration = new NonTerminal (nameof (InlineParamDeclaration));
154162
}
155163
}
156164
}

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,15 +188,15 @@ more description {e.g. something} here. Include @ character.
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
@param options Additional options.
194194
See {@link foo()}
195195
bar()} for more details.
196196
@return the return value
197197
",
198198
FullXml = $@"<member>
199-
<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>
199+
<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>
200200
<param name=""empty"">empty</param>
201201
<param name=""options"">Additional options.
202202
See <c>foo()</c>
@@ -210,7 +210,7 @@ more description {{e.g. something}} here. Include @ character.
210210
<returns>the return value</returns>
211211
</member>",
212212
IntelliSenseXml = $@"<member>
213-
<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>
213+
<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>
214214
<param name=""empty"">empty</param>
215215
<param name=""options"">Additional options.
216216
See <c>foo()</c>

0 commit comments

Comments
 (0)