-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[generator] Handle multiple @return javadoc values #836
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,21 +17,19 @@ namespace Java.Interop.Tools.JavaSource.Tests | |
[TestFixture] | ||
public class SourceJavadocToXmldocParserTests : SourceJavadocToXmldocGrammarFixture { | ||
|
||
[Test] | ||
public void TryParse () | ||
[Test, TestCaseSource (nameof (TryParse_Success))] | ||
public void TryParse (ParseResult parseResult) | ||
{ | ||
foreach (var values in TryParse_Success) { | ||
ParseTree parseTree; | ||
var p = new SourceJavadocToXmldocParser (XmldocStyle.Full); | ||
var n = p.TryParse (values.Javadoc, null, out parseTree); | ||
Assert.IsFalse (parseTree.HasErrors (), DumpMessages (parseTree, p)); | ||
Assert.AreEqual (values.FullXml, GetMemberXml (n), $"while parsing input: ```{values.Javadoc}```"); | ||
ParseTree parseTree; | ||
var p = new SourceJavadocToXmldocParser (XmldocStyle.Full); | ||
var n = p.TryParse (parseResult.Javadoc, null, out parseTree); | ||
Assert.IsFalse (parseTree.HasErrors (), DumpMessages (parseTree, p)); | ||
Assert.AreEqual (parseResult.FullXml, GetMemberXml (n), $"while parsing input: ```{parseResult.Javadoc}```"); | ||
|
||
p = new SourceJavadocToXmldocParser (XmldocStyle.IntelliSense); | ||
n = p.TryParse (values.Javadoc, null, out parseTree); | ||
Assert.IsFalse (parseTree.HasErrors (), DumpMessages (parseTree, p)); | ||
Assert.AreEqual (values.IntelliSenseXml, GetMemberXml (n), $"while parsing input: ```{values.Javadoc}```"); | ||
} | ||
p = new SourceJavadocToXmldocParser (XmldocStyle.IntelliSense); | ||
n = p.TryParse (parseResult.Javadoc, null, out parseTree); | ||
Assert.IsFalse (parseTree.HasErrors (), DumpMessages (parseTree, p)); | ||
Assert.AreEqual (parseResult.IntelliSenseXml, GetMemberXml (n), $"while parsing input: ```{parseResult.Javadoc}```"); | ||
} | ||
|
||
static string GetMemberXml (IEnumerable<XNode> members) | ||
|
@@ -40,7 +38,7 @@ static string GetMemberXml (IEnumerable<XNode> members) | |
return e.ToString (); | ||
} | ||
|
||
static readonly ParseResult[] TryParse_Success = new ParseResult[]{ | ||
public static readonly ParseResult[] TryParse_Success = new ParseResult[]{ | ||
new ParseResult { | ||
Javadoc = "Summary.\n\nP2.\n\n<p>Hello!</p>", | ||
FullXml = @"<member> | ||
|
@@ -78,6 +76,17 @@ static string GetMemberXml (IEnumerable<XNode> members) | |
<returns> | ||
<c>true</c> if something | ||
or other; otherwise <c>false</c>.</returns> | ||
</member>", | ||
}, | ||
new ParseResult { | ||
Javadoc = "@return {@code true} if something else @return {@code false}.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm half surprised that |
||
FullXml = @"<member> | ||
<returns> | ||
<c>true</c> if something else <c>false</c>.</returns> | ||
</member>", | ||
IntelliSenseXml = @"<member> | ||
<returns> | ||
<c>true</c> if something else <c>false</c>.</returns> | ||
</member>", | ||
}, | ||
new ParseResult { | ||
|
@@ -166,7 +175,7 @@ more description here.</para> | |
}, | ||
}; | ||
|
||
class ParseResult { | ||
public class ParseResult { | ||
public string Javadoc; | ||
public string FullXml; | ||
public string IntelliSenseXml; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can't be
null
;.First()
requires that an element be returned, and unless we have a bug and we do.Returns.Add(null)
, there should only be non-null
elements withinjdi.Returns
.If we want to allow
null
, use.FirstOrDefault()
.Actually, on review this entire block doesn't quite make sense to me:
r
itself shouldn't change fromr.Add()
, and thus this should be a no-op (unlessjdi.Returns
somehow has > 1 element in it? But how could that happen?)Neither of the above statements should be needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The null check was intended to handle the possibility of
jdi.Returns.First ()
not being anXElement
, though I think we only ever addXElement
s to thisICollection<XNode>
in the section above and so the check probably shouldn't be needed.The
FinishParse (context, parseNode).Returns
collection will have more than zero elements in it when the<javadoc>
entry that is being parsed has multiple@return
values in it, as shown in the test addition below. TheReturns.Clear
andReturns.Add
additions do look to be redundant here though, I will clean that up.