Skip to content

Commit

Permalink
Don't rewrite //noinspection
Browse files Browse the repository at this point in the history
Fixes #202

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=171606182
  • Loading branch information
cushon committed Oct 10, 2017
1 parent c1f99a7 commit 8ea0644
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Expand Up @@ -90,7 +90,7 @@ private String preserveIndentation(List<String> lines, int column0) {
return builder.toString();
}

// Remove leading whitespace (trailing was already removed), wrap if necessary, and re-indent.
// Wraps and re-indents line comments.
private String indentLineComments(List<String> lines, int column0) {
lines = wrapLineComments(lines, column0, options);
StringBuilder builder = new StringBuilder();
Expand All @@ -102,14 +102,15 @@ private String indentLineComments(List<String> lines, int column0) {
return builder.toString();
}

private static final Pattern LINE_COMMENT_PREFIX = Pattern.compile("^(//+)[^\\s/]");
private static final Pattern LINE_COMMENT_MISSING_SPACE_PREFIX =
Pattern.compile("^(//+)(?!noinspection)[^\\s/]");

private List<String> wrapLineComments(
List<String> lines, int column0, JavaFormatterOptions options) {
List<String> result = new ArrayList<>();
for (String line : lines) {
// Add missing leading spaces to line comments: `//foo` -> `// foo`.
Matcher matcher = LINE_COMMENT_PREFIX.matcher(line);
Matcher matcher = LINE_COMMENT_MISSING_SPACE_PREFIX.matcher(line);
if (matcher.find()) {
int length = matcher.group(1).length();
line = Strings.repeat("/", length) + " " + line.substring(length);
Expand Down
@@ -0,0 +1,6 @@
class I202 {
{
//noinspection CheckResult
methodWhoseResultShouldBeChecked();
}
}
@@ -0,0 +1,6 @@
class I202 {
{
//noinspection CheckResult
methodWhoseResultShouldBeChecked();
}
}

0 comments on commit 8ea0644

Please sign in to comment.