diff --git a/src/Java.Interop.Tools.JavaSource/Java.Interop.Tools.JavaSource/SourceJavadocToXmldocGrammar.HtmlBnfTerms.cs b/src/Java.Interop.Tools.JavaSource/Java.Interop.Tools.JavaSource/SourceJavadocToXmldocGrammar.HtmlBnfTerms.cs index 475da73b5..2c22a5339 100644 --- a/src/Java.Interop.Tools.JavaSource/Java.Interop.Tools.JavaSource/SourceJavadocToXmldocGrammar.HtmlBnfTerms.cs +++ b/src/Java.Interop.Tools.JavaSource/Java.Interop.Tools.JavaSource/SourceJavadocToXmldocGrammar.HtmlBnfTerms.cs @@ -131,9 +131,17 @@ internal void CreateRules (SourceJavadocToXmldocGrammar grammar) } }; - CodeElementDeclaration.Rule = CreateStartElement ("code", grammar) + InlineDeclarations + CreateEndElement ("code", grammar); + CodeElementDeclaration.Rule = CodeElementContentTerm; CodeElementDeclaration.AstConfig.NodeCreator = (context, parseNode) => { - var target = parseNode.ChildNodes [1].AstNode; + // Parse the entire element captured in the token + var codeElementText = parseNode.ChildNodes [0].Token.Text; + int startIndex = codeElementText.IndexOf ('>'); + int stopIndex = codeElementText.LastIndexOf ('<'); + if (startIndex == -1 || stopIndex == -1) { + parseNode.AstNode = new XText (codeElementText); + return; + } + var target = codeElementText.Substring (startIndex + 1, stopIndex - startIndex - 1); parseNode.AstNode = new XElement ("c", target); }; } @@ -232,6 +240,12 @@ static string GetChildNodesAsString (ParseTreeNode parseNode) public readonly NonTerminal InlineHyperLinkDeclaration = new NonTerminal (nameof (InlineHyperLinkDeclaration), ConcatChildNodes); public readonly NonTerminal CodeElementDeclaration = new NonTerminal (nameof (CodeElementDeclaration), ConcatChildNodes); + public readonly Terminal CodeElementContentTerm = new RegexBasedTerminal ("", $@"(?i)]*>(.|\s)*?(<\/code>|<\/null>|)") { + AstConfig = new AstNodeConfig { + NodeCreator = (context, parseNode) => parseNode.AstNode = "", + }, + }; + public readonly Terminal InlineHyperLinkOpenTerm = new RegexBasedTerminal ("input.position()"); Assert.IsFalse (r.HasErrors (), DumpMessages (r, p)); Assert.AreEqual ("input.position()", r.Root.AstNode.ToString ()); - } + r = p.Parse ("null"); + Assert.IsFalse (r.HasErrors (), DumpMessages (r, p)); + Assert.AreEqual ("null", r.Root.AstNode.ToString ()); + + r = p.Parse ("android:label=\"@string/resolve_title\""); + Assert.IsFalse (r.HasErrors (), DumpMessages (r, p)); + Assert.AreEqual ("android:label=\"@string/resolve_title\"", r.Root.AstNode.ToString ()); + + r = p.Parse ("Activity.RESULT_OK"); + Assert.IsFalse (r.HasErrors (), DumpMessages (r, p)); + Assert.AreEqual ("Activity.RESULT_OK", r.Root.AstNode.ToString ()); + + r = p.Parse ("format.setString(MediaFormat.KEY_FRAME_RATE, null)"); + Assert.IsFalse (r.HasErrors (), DumpMessages (r, p)); + Assert.AreEqual ("format.setString(MediaFormat.KEY_FRAME_RATE, null)", r.Root.AstNode.ToString ()); + + r = p.Parse (@" +

[ 0, 0, 0, 0, 0 ] +

[ 0, 0, 0, 0, 0 ] +

[ 0, 0, 1, 0, 0 ] +

[ 0, 0, 0, 0, 0 ] +

[ 0, 0, 0, 0, 0 ] +"); + Assert.IsFalse (r.HasErrors (), DumpMessages (r, p)); + Assert.AreEqual (@" +<p> [ 0, 0, 0, 0, 0 ] +<p> [ 0, 0, 0, 0, 0 ] +<p> [ 0, 0, 1, 0, 0 ] +<p> [ 0, 0, 0, 0, 0 ] +<p> [ 0, 0, 0, 0, 0 ] +", r.Root.AstNode.ToString ()); + } } } diff --git a/tests/Java.Interop.Tools.JavaSource-Tests/SourceJavadocToXmldocParserTests.cs b/tests/Java.Interop.Tools.JavaSource-Tests/SourceJavadocToXmldocParserTests.cs index d224a6ee9..a586f744d 100644 --- a/tests/Java.Interop.Tools.JavaSource-Tests/SourceJavadocToXmldocParserTests.cs +++ b/tests/Java.Interop.Tools.JavaSource-Tests/SourceJavadocToXmldocParserTests.cs @@ -144,16 +144,36 @@ more description here. ", }, new ParseResult { - Javadoc = "Something {@link #method}: description, \"declaration\" or \"another declaration\".\n\n@apiSince 1\n", + Javadoc = "Something {@link #method}: description, \"declaration\" or

some content

.\n\n@apiSince 1\n", FullXml = @" - Something #method: description, ""declaration"" or ""another declaration"". + Something #method: description, ""declaration"" or <pre><p>some content</pre></p>. - Something #method: description, ""declaration"" or ""another declaration"". + Something #method: description, ""declaration"" or <pre><p>some content</pre></p>. Added in API level 1. ", IntelliSenseXml = @" - Something #method: description, ""declaration"" or ""another declaration"". + Something #method: description, ""declaration"" or <pre><p>some content</pre></p>. +", + }, + new ParseResult { + Javadoc = @"The result code will be Activity.RESULT_OK for success, + or one of these errors: + RESULT_ERROR_GENERIC_FAILURE", + FullXml = @" + The result code will be Activity.RESULT_OK for success, + or one of these errors: + RESULT_ERROR_GENERIC_FAILURE + + The result code will be Activity.RESULT_OK for success, + or one of these errors: + RESULT_ERROR_GENERIC_FAILURE + +", + IntelliSenseXml = @" + The result code will be Activity.RESULT_OK for success, + or one of these errors: + RESULT_ERROR_GENERIC_FAILURE ", }, new ParseResult {