class WordRepeatBeginningRule extends TextLevelRule {
  
  public WordRepeatBeginningRule(ResourceBundle messages, Language language) {
    super(messages);
    super.setCategory(Categories.REPETITIONS_STYLE.getCategory(messages));
    setLocQualityIssueType(ITSIssueType.Style);
  }

  @Override
  public String getId() {
    return "WORD_REPEAT_BEGINNING_RULE";
  }

  @Override
  public String getDescription() {
    return messages.getString("desc_repetition_beginning");
  }
  
  protected boolean isAdverb(AnalyzedTokenReadings token) {
    return false;
  }
  
  public boolean isException(String token) {
    // avoid warning when having lists like "2007: ..." or the like
    return token.equals(":") || token.equals("–") || token.equals("-") || token.equals("✔️") || token.equals("➡️")
        || token.equals("—") || token.equals("⭐️") || token.equals("⚠️");
  }

  public boolean isSentenceException(AnalyzedSentence sentence) {
    return false;
  }

  @Override
  public RuleMatch[] match(List<AnalyzedSentence> sentences) throws IOException {<FILL_FUNCTION_BODY>}

  protected List<String> getSuggestions(AnalyzedTokenReadings analyzedToken) {
    return Collections.emptyList();
  }

  @Override
  public int minToCheckParagraph() {
    return 2;
  }

}

    String lastToken = "";
    String beforeLastToken = "";
    List<RuleMatch> ruleMatches = new ArrayList<>();
    int pos = 0;
    AnalyzedSentence prevSentence = null;
    for (AnalyzedSentence sentence : sentences) {
      if (isSentenceException(sentence)) {
        prevSentence = null;
        continue;
      }
      AnalyzedTokenReadings[] tokens = sentence.getTokensWithoutWhitespace();
      String token = "";
      if (tokens.length > 1) {
        AnalyzedTokenReadings analyzedToken = tokens[1];
        token = analyzedToken.getToken();
        if (tokens.length > 3) {
          // avoid "..." etc. to be matched:
          boolean isWord = true;
          if (token.length() == 1) {
            if (!Character.isLetter(token.charAt(0))) {
              isWord = false;
            }
          }
          if (isWord && lastToken.equals(token) && !isException(token) && !isException(tokens[2].getToken())
              && !isException(tokens[3].getToken()) && prevSentence != null
              && prevSentence.getText().trim().matches(".+[.?!]$")) { // no matches for e.g. table cells
            String shortMsg;
            if (isAdverb(analyzedToken)) {
              shortMsg = messages.getString("desc_repetition_beginning_adv");
            } else if (beforeLastToken.equals(token)) {
              shortMsg = messages.getString("desc_repetition_beginning_word");
            } else {
              shortMsg = "";
            }
            if (!shortMsg.isEmpty()) {
              String msg = shortMsg + " " + messages.getString("desc_repetition_beginning_thesaurus");
              int startPos = analyzedToken.getStartPos();
              int endPos = startPos + token.length();
              RuleMatch ruleMatch = new RuleMatch(this, sentence, pos + startPos, pos + endPos, msg, shortMsg);
              List<String> suggestions = getSuggestions(analyzedToken);
              if (suggestions.size() > 0) {
                ruleMatch.setSuggestedReplacements(suggestions);
              }
              ruleMatches.add(ruleMatch);
            }
          }
        }
      }
      beforeLastToken = lastToken;
      lastToken = token;
      pos += sentence.getCorrectedTextLength();
      prevSentence = sentence;
    }
    return toRuleMatchArray(ruleMatches);
  
<methods>public void <init>() ,public void <init>(java.util.ResourceBundle) ,public int estimateContextForSureMatch() ,public org.languagetool.rules.RuleMatch[] match(List<org.languagetool.AnalyzedSentence>, org.languagetool.markup.AnnotatedText) throws java.io.IOException,public abstract org.languagetool.rules.RuleMatch[] match(List<org.languagetool.AnalyzedSentence>) throws java.io.IOException,public final org.languagetool.rules.RuleMatch[] match(org.languagetool.AnalyzedSentence) throws java.io.IOException,public abstract int minToCheckParagraph() <variables>