Skip to content

Commit

Permalink
Recognize javadoc comments in ParameterNameTest
Browse files Browse the repository at this point in the history
e.g. `f(/** arg= */ 42)` in addition to `f(/* arg= */ 42)`.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=283343001
  • Loading branch information
cushon authored and nick-someone committed Dec 2, 2019
1 parent 1ddb22a commit df4cdef
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ public static String getTextFromComment(Comment comment) {
return comment.getText().replaceAll("^\\s*/\\*\\s*(.*?)\\s*\\*/\\s*", "$1");
case LINE:
return comment.getText().replaceAll("^\\s*//\\s*", "");
default:
return comment.getText();
case JAVADOC:
return comment.getText().replaceAll("^\\s*/\\*\\*\\s*(.*?)\\s*\\*/\\s*", "$1");
}
throw new AssertionError(comment.getStyle());
}

private static ImmutableList<Commented<ExpressionTree>> findCommentsForArguments(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static com.google.common.collect.Streams.forEachPair;
import static com.google.errorprone.BugPattern.SeverityLevel.WARNING;
import static com.google.errorprone.matchers.Description.NO_MATCH;
import static com.sun.tools.javac.parser.Tokens.Comment.CommentStyle.BLOCK;

import com.google.auto.value.AutoValue;
import com.google.common.base.Strings;
Expand Down Expand Up @@ -155,9 +154,6 @@ private void checkArgument(
VarSymbol formal, ExpressionTree actual, ErrorProneToken token, VisitorState state) {
List<FixInfo> matches = new ArrayList<>();
for (Comment comment : token.comments()) {
if (comment.getStyle() != BLOCK) {
continue;
}
Matcher m =
NamedParameterComment.PARAMETER_COMMENT_PATTERN.matcher(
Comments.getTextFromComment(comment));
Expand Down Expand Up @@ -235,9 +231,6 @@ private void checkArgument(
// complains on parameter name comments on varargs past the first one
private void checkComment(ExpressionTree arg, ErrorProneToken token, VisitorState state) {
for (Comment comment : token.comments()) {
if (comment.getStyle() != BLOCK) {
continue;
}
Matcher m =
NamedParameterComment.PARAMETER_COMMENT_PATTERN.matcher(
Comments.getTextFromComment(comment));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public void positive() {
" void f(int foo, int bar) {}",
" {",
" f(/* bar= */ 1, /* foo= */ 2);",
" f(/** bar= */ 3, /** foo= */ 4);",
" }",
"}")
.addOutputLines(
Expand All @@ -49,6 +50,7 @@ public void positive() {
" void f(int foo, int bar) {}",
" {",
" f(/* foo= */ 1, /* bar= */ 2);",
" f(/* foo= */ 3, /* bar= */ 4);",
" }",
"}")
.doTest(TEXT_MATCH);
Expand Down

0 comments on commit df4cdef

Please sign in to comment.