<?xml version="1.0"?>

<!--
   Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
  -->

<!DOCTYPE module PUBLIC
          "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
          "https://checkstyle.org/dtds/configuration_1_3.dtd">

<!--
  Commons Statitics customization of default Checkstyle behavior:
  https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/sun_checks.xml
-->
<module name="Checker">
  <property name="fileExtensions" value="java, properties, xml" />

  <!-- Excludes all 'module-info.java' files              -->
  <!-- See https://checkstyle.org/config_filefilters.html -->
  <module name="BeforeExecutionExclusionFileFilter">
    <property name="fileNamePattern" value="module\-info\.java$"/>
  </module>

  <!-- https://checkstyle.org/config_filters.html#SuppressionFilter -->
  <module name="SuppressionFilter">
    <!-- Default property set by maven-checkstyle-plugin -->
    <property name="file" value="${checkstyle.suppressions.file}"/>
    <property name="optional" value="false"/>
  </module>

  <property name="localeLanguage" value="en"/>

  <!-- Checks that a package-info.java file exists for each package. -->
  <!-- See https://checkstyle.org/config_javadoc.html#JavadocPackage -->
  <module name="JavadocPackage" />

  <!-- Checks whether files end with a new line. -->
  <!-- See https://checkstyle.org/config_misc.html#NewlineAtEndOfFile -->
  <module name="NewlineAtEndOfFile" />

  <!-- Checks that property files contain the same keys. -->
  <!-- See https://checkstyle.org/config_misc.html#Translation -->
  <module name="Translation" />

  <!-- Checks for Size Violations. -->
  <!-- See https://checkstyle.org/config_sizes.html -->
  <module name="FileLength" />
  <module name="LineLength">
    <property name="fileExtensions" value="java"/>
    <!-- Ignore lines that begin with " * ", such as within a Javadoc comment. -->
    <property name="ignorePattern" value="^ *\* *[^ ]"/>
    <property name="max" value="120"/>
  </module>

  <!-- Checks for whitespace -->
  <!-- See http://checkstyle.org/config_whitespace.html -->
  <module name="FileTabCharacter" />

  <!-- Miscellaneous other checks. -->
  <!-- See http://checkstyle.org/config_misc.html -->
  <module name="RegexpSingleline">
    <property name="format" value="\s+$" />
    <property name="minimum" value="0" />
    <property name="maximum" value="0" />
    <property name="message" value="Line has trailing spaces." />
  </module>

  <!-- Checks for Headers -->
  <!-- See http://checkstyle.org/config_header.html -->
  <module name="Header">
    <property name="headerFile" value="${checkstyle.header.file}"/>
    <property name="fileExtensions" value="java"/>
  </module>

  <module name="TreeWalker">

    <!-- Checks for Javadoc comments. -->
    <!-- See http://checkstyle.org/config_javadoc.html -->
    <module name="InvalidJavadocPosition"/>
    <module name="JavadocMethod" />
    <module name="JavadocType" />
    <module name="JavadocVariable" />
    <module name="JavadocStyle" />
    <module name="MissingJavadocMethod">
      <property name="scope" value="private"/>
    </module>
    <module name="MissingJavadocPackage" />
    <module name="MissingJavadocType">
      <property name="scope" value="private"/>
    </module>

    <!-- Checks for Naming Conventions. -->
    <!-- See http://checkstyle.org/config_naming.html -->
    <module name="ConstantName" />
    <module name="LocalFinalVariableName" />
    <module name="LocalVariableName" />
    <module name="MemberName" />
    <module name="MethodName" />
    <module name="PackageName" />
    <module name="ParameterName" />
    <module name="StaticVariableName" />
    <module name="TypeName" />

    <!-- Checks for imports -->
    <!-- See http://checkstyle.org/config_import.html -->
    <module name="AvoidStarImport" />
    <module name="AvoidStaticImport"/>
    <module name="IllegalImport" /> <!-- defaults to sun.* packages -->
    <module name="RedundantImport" />
    <module name="UnusedImports">
      <property name="processJavadoc" value="false" />
    </module>
    <module name="CustomImportOrder">
      <property name="sortImportsInGroupAlphabetically" value="true"/>
    </module>

    <!-- Checks for Size Violations. -->
    <!-- See http://checkstyle.org/config_sizes.html -->
    <module name="MethodLength">
      <!-- Ignore empty and comments -->
      <property name="countEmpty" value="false"/>
    </module>
    <module name="ParameterNumber" />

    <!-- Checks for whitespace -->
    <!-- See http://checkstyle.org/config_whitespace.html -->
    <module name="EmptyForIteratorPad" />
    <module name="GenericWhitespace" />
    <module name="MethodParamPad" />
    <module name="NoWhitespaceAfter" />
    <module name="NoWhitespaceBefore" />
    <!-- Operator must be at end of wrapped line -->
    <module name="OperatorWrap">
      <property name="option" value="eol"/>
    </module>
    <module name="ParenPad" />
    <module name="TypecastParenPad" />
    <module name="WhitespaceAfter">
      <property name="tokens" value="COMMA, SEMI, LITERAL_IF, LITERAL_ELSE, LITERAL_WHILE, LITERAL_DO, LITERAL_FOR, DO_WHILE"/>
    </module>
    <module name="WhitespaceAround">
      <property name="allowEmptyConstructors" value="true"/>
      <property name="allowEmptyTypes" value="true"/>
    </module>

    <!-- Modifier Checks -->
    <!-- See http://checkstyle.org/config_modifiers.html -->
    <module name="ModifierOrder" />
    <module name="RedundantModifier" />

    <!-- Checks for blocks. You know, those {}'s -->
    <!-- See http://checkstyle.org/config_blocks.html -->
    <module name="AvoidNestedBlocks" />
    <module name="EmptyBlock" />
    <module name="LeftCurly" />
    <module name="NeedBraces" />
    <module name="RightCurly" />

    <!-- Checks for common coding problems -->
    <!-- See http://checkstyle.org/config_coding.html -->
    <module name="EmptyStatement" />
    <module name="EqualsHashCode" />
    <!-- Method parameters and local variables should not hide fields, except in constructors and setters -->
    <module name="HiddenField">
        <property name="ignoreConstructorParameter" value="true" />
        <property name="ignoreSetter" value="true" />
    </module>
    <!-- Disallow unnecessary instantiation of Boolean, String -->
    <module name="IllegalInstantiation">
      <property name="classes" value="java.lang.Boolean, java.lang.String"/>
    </module>
    <!-- Allowed for algorithm implementations. -->
    <!-- <module name="InnerAssignment" /> -->
    <!-- <module name="MagicNumber" /> -->
    <!-- Switch statements checked using PMD ExhaustiveSwitchHasDefault. -->
    <!-- <module name="MissingSwitchDefault" /> -->
    <module name="MultipleVariableDeclarations" />
    <module name="SimplifyBooleanExpression" />
    <module name="SimplifyBooleanReturn" />

    <!-- Checks for class design -->
    <!-- See http://checkstyle.org/config_design.html -->
    <module name="DesignForExtension" />
    <module name="FinalClass" />
    <module name="HideUtilityClassConstructor" />
    <module name="InterfaceIsType" />
    <!-- No public fields -->
    <module name="VisibilityModifier">
       <property name="protectedAllowed" value="true"/>
    </module>

    <!-- Miscellaneous other checks. -->
    <!-- See http://checkstyle.org/config_misc.html -->
    <module name="ArrayTypeStyle" />
    <!-- <module name="FinalParameters" />  -->
    <module name="TodoComment">
      <property name="severity" value="warning"/>
    </module>
    <module name="UpperEll" />

    <!-- Addition to Checkstyle sun_checks.xml  -->

    <!-- Indentation of 4 spaces. -->
    <module name="Indentation">
      <!-- Indentation style recommended by Oracle -->
      <property name="caseIndent" value="0"/>
    </module>

    <!-- Switch statements should have independent cases -->
    <module name="FallThrough" />

    <!-- No System.out.println() statements -->
    <module name="Regexp">
      <!-- no sysouts -->
      <property name="format" value="System\.(out|err)\."/>
      <property name="illegalPattern" value="true"/>
    </module>

    <!-- Authors should be in pom.xml file -->
    <module name="Regexp">
      <property name="format" value="@author"/>
      <property name="illegalPattern" value="true"/>
      <property name="message" value="Developers names should be in pom file"/>
    </module>

    <!-- Use a consistent way to put declarations -->
    <module name="DeclarationOrder" />

    <!-- Don't add up parentheses when they are not required -->
    <module name="UnnecessaryParentheses" />

    <!--  Don't use too widespread catch (Exception, Throwable, RuntimeException)  -->
    <module name="IllegalCatch" />

    <!-- Don't use = or != for string comparisons -->
    <module name="StringLiteralEquality" />

    <!-- String literals more than one character long should not be repeated several times -->
    <!-- the "unchecked" string is also accepted to allow @SuppressWarnings("unchecked") -->
    <module name="MultipleStringLiterals" >
      <property name="ignoreStringsRegexp" value='^(("")|(".")|("unchecked"))$'/>
    </module>

    <!-- Check if @Override tags are present  -->
    <module name="MissingOverride" />

    <!-- Setup special comments to suppress specific checks from source files -->
    <module name="SuppressionCommentFilter">
      <property name="offCommentFormat" value="CHECKSTYLE\: stop ([\w\|]+)"/>
      <property name="onCommentFormat"  value="CHECKSTYLE\: resume ([\w\|]+)"/>
      <property name="checkFormat"      value="$1"/>
    </module>
    <module name="SuppressionCommentFilter">
      <property name="offCommentFormat" value="CHECKSTYLE\: stop all"/>
      <property name="onCommentFormat"  value="CHECKSTYLE\: resume all"/>
    </module>

  </module>

</module>
