// Path: startupheroes-checks/src/main/java/es/startuphero/checkstyle/util/AnnotationUtils.java
// public static DetailAST getAnnotation(DetailAST ast, String fullAnnotation) {
//   DetailAST simpleAnnotationAst =
//       AnnotationUtil.getAnnotation(ast, CommonUtils.getSimpleName(fullAnnotation));
//   return nonNull(simpleAnnotationAst) ? simpleAnnotationAst
//       : AnnotationUtil.getAnnotation(ast, fullAnnotation);
// }
// 
// Path: startupheroes-checks/src/main/java/es/startuphero/checkstyle/util/AnnotationUtils.java
// public static Map<String, DetailAST> getKeyValueAstMap(DetailAST annotationAst) {
//   List<DetailAST> keyValuePairAstList =
//       CommonUtils.getChildsByType(annotationAst, TokenTypes.ANNOTATION_MEMBER_VALUE_PAIR);
//   return keyValuePairAstList.stream()
//                             .collect(Collectors.toMap(keyValuePairAst -> keyValuePairAst.getFirstChild().getText(),
//                                                       Function.identity(), (v1, v2) -> null,
//                                                       LinkedHashMap::new));
// }
// 
// Path: startupheroes-checks/src/main/java/es/startuphero/checkstyle/util/AnnotationUtils.java
// public static Optional<String> getValueAsString(DetailAST annotationKeyValueAst) {
//   Optional<String> result = Optional.empty();
//   DetailAST annotationValueNode = getAnnotationValueNode(annotationKeyValueAst);
//   DetailAST literalValueAst = annotationValueNode.getFirstChild();
//   if (nonNull(literalValueAst)) {
//     result = Optional.of(literalValueAst.getText().replaceAll("\"", ""));
//   }
//   return result;
// }
// 
// Path: startupheroes-checks/src/main/java/es/startuphero/checkstyle/util/ClassUtils.java
// public static String getClassName(DetailAST classAst) {
//   DetailAST type = classAst.findFirstToken(TokenTypes.LITERAL_CLASS);
//   return type.getNextSibling().getText();
// }
// 
// Path: startupheroes-checks/src/main/java/es/startuphero/checkstyle/util/ClassUtils.java
// public static Boolean isEntity(DetailAST classAst, String fullEntityAnnotation) {
//   return AnnotationUtils.hasAnnotation(classAst, fullEntityAnnotation);
// }
// 
// Path: startupheroes-checks/src/main/java/es/startuphero/checkstyle/util/VariableUtils.java
// public static List<DetailAST> getNonStaticVariables(DetailAST classAst) {
//   DetailAST objBlock = classAst.findFirstToken(TokenTypes.OBJBLOCK);
//   return CommonUtils.getChildsByType(objBlock, TokenTypes.VARIABLE_DEF).stream()
//                     .filter(ast -> !CommonUtils.isStatic(ast))
//                     .collect(toList());
// }
// 
// Path: startupheroes-checks/src/main/java/es/startuphero/checkstyle/util/VariableUtils.java
// public static String getVariableName(DetailAST variableAst) {
//   DetailAST type = variableAst.findFirstToken(TokenTypes.TYPE);
//   return type.getNextSibling().getText();
// }


import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.regex.Pattern;
import static es.startuphero.checkstyle.util.AnnotationUtils.getAnnotation;
import static es.startuphero.checkstyle.util.AnnotationUtils.getKeyValueAstMap;
import static es.startuphero.checkstyle.util.AnnotationUtils.getValueAsString;
import static es.startuphero.checkstyle.util.ClassUtils.getClassName;
import static es.startuphero.checkstyle.util.ClassUtils.isEntity;
import static es.startuphero.checkstyle.util.VariableUtils.getNonStaticVariables;
import static es.startuphero.checkstyle.util.VariableUtils.getVariableName;
import static java.util.Objects.nonNull;
package es.startuphero.checkstyle.checks.design;



/**
 * @author ozlem.ulag
 */
public class LogDataTableCheck extends AbstractCheck {

  /**
   * A key is pointing to the warning message text in "messages.properties" file.
   */
  private static final String MSG_KEY = "keep.log.data.table";

  /**
   * set type annotation to understand that a class is an entity.
   */
  private String typeAnnotation;

  private String abstractTypeAnnotation;

  private String columnAnnotation;

  private Integer limitLength;

  /** The format string of the regexp. */
  private String classNameFormat = "Log$";

  /** The regexp to match against. */
  private Pattern regexp = Pattern.compile(classNameFormat);

  @Override
  public int[] getDefaultTokens() {
    return getAcceptableTokens();
  }

  @Override
  public int[] getAcceptableTokens() {
    return new int[] {TokenTypes.CLASS_DEF};
  }

  @Override
  public int[] getRequiredTokens() {
    return getAcceptableTokens();
  }

  @Override
  public void visitToken(DetailAST ast) {
    if (isEntity(ast, typeAnnotation) || isEntity(ast, abstractTypeAnnotation)) {
      String className = getClassName(ast);
      if (isMatchingClassName(className)) {
// Path: startupheroes-checks/src/main/java/es/startuphero/checkstyle/util/AnnotationUtils.java
// public static DetailAST getAnnotation(DetailAST ast, String fullAnnotation) {
//   DetailAST simpleAnnotationAst =
//       AnnotationUtil.getAnnotation(ast, CommonUtils.getSimpleName(fullAnnotation));
//   return nonNull(simpleAnnotationAst) ? simpleAnnotationAst
//       : AnnotationUtil.getAnnotation(ast, fullAnnotation);
// }
// 
// Path: startupheroes-checks/src/main/java/es/startuphero/checkstyle/util/AnnotationUtils.java
// public static Map<String, DetailAST> getKeyValueAstMap(DetailAST annotationAst) {
//   List<DetailAST> keyValuePairAstList =
//       CommonUtils.getChildsByType(annotationAst, TokenTypes.ANNOTATION_MEMBER_VALUE_PAIR);
//   return keyValuePairAstList.stream()
//                             .collect(Collectors.toMap(keyValuePairAst -> keyValuePairAst.getFirstChild().getText(),
//                                                       Function.identity(), (v1, v2) -> null,
//                                                       LinkedHashMap::new));
// }
// 
// Path: startupheroes-checks/src/main/java/es/startuphero/checkstyle/util/AnnotationUtils.java
// public static Optional<String> getValueAsString(DetailAST annotationKeyValueAst) {
//   Optional<String> result = Optional.empty();
//   DetailAST annotationValueNode = getAnnotationValueNode(annotationKeyValueAst);
//   DetailAST literalValueAst = annotationValueNode.getFirstChild();
//   if (nonNull(literalValueAst)) {
//     result = Optional.of(literalValueAst.getText().replaceAll("\"", ""));
//   }
//   return result;
// }
// 
// Path: startupheroes-checks/src/main/java/es/startuphero/checkstyle/util/ClassUtils.java
// public static String getClassName(DetailAST classAst) {
//   DetailAST type = classAst.findFirstToken(TokenTypes.LITERAL_CLASS);
//   return type.getNextSibling().getText();
// }
// 
// Path: startupheroes-checks/src/main/java/es/startuphero/checkstyle/util/ClassUtils.java
// public static Boolean isEntity(DetailAST classAst, String fullEntityAnnotation) {
//   return AnnotationUtils.hasAnnotation(classAst, fullEntityAnnotation);
// }
// 
// Path: startupheroes-checks/src/main/java/es/startuphero/checkstyle/util/VariableUtils.java
// public static List<DetailAST> getNonStaticVariables(DetailAST classAst) {
//   DetailAST objBlock = classAst.findFirstToken(TokenTypes.OBJBLOCK);
//   return CommonUtils.getChildsByType(objBlock, TokenTypes.VARIABLE_DEF).stream()
//                     .filter(ast -> !CommonUtils.isStatic(ast))
//                     .collect(toList());
// }
// 
// Path: startupheroes-checks/src/main/java/es/startuphero/checkstyle/util/VariableUtils.java
// public static String getVariableName(DetailAST variableAst) {
//   DetailAST type = variableAst.findFirstToken(TokenTypes.TYPE);
//   return type.getNextSibling().getText();
// }


// Path: startupheroes-checks/src/main/java/es/startuphero/checkstyle/checks/design/LogDataTableCheck.java
import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.regex.Pattern;
import static es.startuphero.checkstyle.util.AnnotationUtils.getAnnotation;
import static es.startuphero.checkstyle.util.AnnotationUtils.getKeyValueAstMap;
import static es.startuphero.checkstyle.util.AnnotationUtils.getValueAsString;
import static es.startuphero.checkstyle.util.ClassUtils.getClassName;
import static es.startuphero.checkstyle.util.ClassUtils.isEntity;
import static es.startuphero.checkstyle.util.VariableUtils.getNonStaticVariables;
import static es.startuphero.checkstyle.util.VariableUtils.getVariableName;
import static java.util.Objects.nonNull;

package es.startuphero.checkstyle.checks.design;



/**
 * @author ozlem.ulag
 */
public class LogDataTableCheck extends AbstractCheck {

  /**
   * A key is pointing to the warning message text in "messages.properties" file.
   */
  private static final String MSG_KEY = "keep.log.data.table";

  /**
   * set type annotation to understand that a class is an entity.
   */
  private String typeAnnotation;

  private String abstractTypeAnnotation;

  private String columnAnnotation;

  private Integer limitLength;

  /** The format string of the regexp. */
  private String classNameFormat = "Log$";

  /** The regexp to match against. */
  private Pattern regexp = Pattern.compile(classNameFormat);

  @Override
  public int[] getDefaultTokens() {
    return getAcceptableTokens();
  }

  @Override
  public int[] getAcceptableTokens() {
    return new int[] {TokenTypes.CLASS_DEF};
  }

  @Override
  public int[] getRequiredTokens() {
    return getAcceptableTokens();
  }

  @Override
  public void visitToken(DetailAST ast) {
    if (isEntity(ast, typeAnnotation) || isEntity(ast, abstractTypeAnnotation)) {
      String className = getClassName(ast);
      if (isMatchingClassName(className)) {
        List<DetailAST> variableNodes = getNonStaticVariables(ast);