class AddCommasFilter extends RuleFilter {
  
  private static final Pattern OPENING_QUOTES = Pattern.compile("[«“\"‘'„¿¡]", Pattern.DOTALL);
  
  
  @Override
  public RuleMatch acceptRuleMatch(RuleMatch match, Map<String, String> arguments, int patternTokenPos,
                                   AnalyzedTokenReadings[] patternTokens, List<Integer> tokenPositions) throws IOException {<FILL_FUNCTION_BODY>}

}

   
    // for patterns ", aun así" suggest "; aun así," and ", aun así,"
    String suggestSemicolon = getOptional("suggestSemicolon", arguments);
    boolean bSuggestSemicolon = false;
    if (suggestSemicolon != null && suggestSemicolon.equalsIgnoreCase("true")) {
      bSuggestSemicolon = true;
    }

    AnalyzedTokenReadings[] tokens = match.getSentence().getTokensWithoutWhitespace();
    int postagFrom = 1;
    while (postagFrom < tokens.length && tokens[postagFrom].getStartPos() < match.getFromPos()) {
      postagFrom++;
    }
    int postagTo = postagFrom;
    while (postagTo < tokens.length && tokens[postagTo].getEndPos() < match.getToPos()) {
      postagTo++;
    }
    boolean beforeOK = (postagFrom == 1) || StringTools.isPunctuationMark(tokens[postagFrom - 1].getToken())
        || StringTools.isCapitalizedWord(tokens[postagFrom].getToken());
    boolean afterOK = !(postagTo + 1 > tokens.length - 1)
        && StringTools.isPunctuationMark(tokens[postagTo + 1].getToken())
        && !(tokens[postagTo + 1].isWhitespaceBefore() && OPENING_QUOTES.matcher(tokens[postagTo + 1].getToken()).matches());
    if (beforeOK && afterOK) {
      return null;
    }
    RuleMatch newMatch = null;
    if (bSuggestSemicolon && tokens[postagFrom - 1].getToken().equals(",") && !afterOK) {
      newMatch = new RuleMatch(match.getRule(), match.getSentence(), tokens[postagFrom - 1].getStartPos(),
          tokens[postagTo].getEndPos(), match.getMessage(), match.getShortMessage());
      newMatch.addSuggestedReplacement(
          "; " + match.getSentence().getText().substring(match.getFromPos(), match.getToPos()) + ",");
      newMatch.addSuggestedReplacement(
          ", " + match.getSentence().getText().substring(match.getFromPos(), match.getToPos()) + ",");
    } else if (beforeOK && !afterOK) {
      newMatch = new RuleMatch(match.getRule(), match.getSentence(), tokens[postagTo].getStartPos(), match.getToPos(),
          match.getMessage(), match.getShortMessage());
      newMatch.setSuggestedReplacement(tokens[postagTo].getToken() + ",");
    } else if (!beforeOK && afterOK) {
      int startPos = tokens[postagFrom].getStartPos();
      if (tokens[postagFrom].isWhitespaceBefore()) {
        startPos--;
      }
      newMatch = new RuleMatch(match.getRule(), match.getSentence(), startPos, tokens[postagFrom].getEndPos(),
          match.getMessage(), match.getShortMessage());
      newMatch.setSuggestedReplacement(", " + tokens[postagFrom].getToken());
    } else if (!beforeOK && !afterOK) {
      int startPos = tokens[postagFrom].getStartPos();
      if (tokens[postagFrom].isWhitespaceBefore()) {
        startPos--;
      }
      newMatch = new RuleMatch(match.getRule(), match.getSentence(), startPos, tokens[postagTo].getEndPos(),
          match.getMessage(), match.getShortMessage());
      newMatch.setSuggestedReplacement(
          ", " + match.getSentence().getText().substring(match.getFromPos(), match.getToPos()) + ",");
    }
    return newMatch;
  
<methods>public non-sealed void <init>() ,public abstract org.languagetool.rules.RuleMatch acceptRuleMatch(org.languagetool.rules.RuleMatch, Map<java.lang.String,java.lang.String>, int, org.languagetool.AnalyzedTokenReadings[], List<java.lang.Integer>) throws java.io.IOException,public boolean matches(Map<java.lang.String,java.lang.String>, org.languagetool.AnalyzedTokenReadings[], int, List<java.lang.Integer>) throws java.io.IOException<variables>