[ 
https://issues.apache.org/jira/browse/HBASE-27401?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17611925#comment-17611925
 ] 

Duo Zhang commented on HBASE-27401:
-----------------------------------

This is the code I used to fix the style problem. And after running this code 
and execute 'mvn spotless:apply' again, we could fix most of the problems.

{code}
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class FixFormat {

  private static Pattern N_IN_THE_MIDDLE = Pattern.compile(" n+ *\\*");

  private static Pattern N_AT_THE_END = Pattern.compile("^(.*) +n+$");

  private static Pattern JAVA_DOC_TAG = Pattern.compile(" *\\* 
*@(param|throws|return) *\\w*");

  private static void fix(Path path) throws IOException {
    List<String> lines = Files.readAllLines(path);
    try (PrintWriter writer = new PrintWriter(path.toFile(), 
StandardCharsets.UTF_8.name())) {
      for (int i = 0; i < lines.size(); i++) {
        String line = lines.get(i);
        if (!line.trim().startsWith("*")) {
          writer.println(line);
          continue;
        }
        Matcher m = N_IN_THE_MIDDLE.matcher(line);
        int start = 0;
        while (m.find()) {
          writer.println(line.substring(start, m.start()));
          start = m.end() - 1;
        }
        String lastPart = line.substring(start);
        if (!JAVA_DOC_TAG.matcher(lastPart).matches() || i == lines.size() - 1) 
{
          writer.println(lastPart);
          continue;
        }
        String nextLine = lines.get(i + 1);
        if (!nextLine.trim().startsWith("* @")) {
          writer.print(lastPart);
          writer.print(" ");
          writer.println(nextLine.trim().substring(1));
          i++;
        } else {
          writer.println(lastPart);
        }
      }
    }
    lines = Files.readAllLines(path);
    try (PrintWriter writer = new PrintWriter(path.toFile(), 
StandardCharsets.UTF_8.name())) {
      for (int i = 0; i < lines.size(); i++) {
        String line = lines.get(i);
        if (!line.trim().startsWith("*")) {
          writer.println(line);
          continue;
        }
        Matcher m = N_AT_THE_END.matcher(line);
        if (m.matches()) {
          writer.print(m.group(1));
        } else {
          writer.println(line);
        }
      }
    }
  }

  public static void main(String[] args) throws IOException {
    Files.walk(Paths.get("/home/zhangduo/hbase/code")).filter(p -> 
p.toFile().isFile())
        .filter(p -> p.toFile().getName().endsWith(".java"))
        .filter(p -> 
!p.toAbsolutePath().toFile().getAbsolutePath().contains("/generated/"))
        .filter(p -> 
!p.toAbsolutePath().toFile().getAbsolutePath().contains("/target/"))
        .forEach(p -> {
          try {
            fix(p);
          } catch (IOException e) {
            throw new UncheckedIOException(e);
          }
        });
  }
}
{code}

> Clean up current broken 'n's in our javadoc
> -------------------------------------------
>
>                 Key: HBASE-27401
>                 URL: https://issues.apache.org/jira/browse/HBASE-27401
>             Project: HBase
>          Issue Type: Sub-task
>            Reporter: Duo Zhang
>            Assignee: Duo Zhang
>            Priority: Major
>         Attachments: ns_at_the_end, ns_in_the_middle
>
>




--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to