<?xml version="1.0"?>
<!DOCTYPE import-control PUBLIC
    "-//Checkstyle//DTD ImportControl Configuration 1.4//EN"
    "https://checkstyle.org/dtds/import_control_1_4.dtd">

<import-control pkg="com.puppycrawl.tools.checkstyle">

  <!-- java.io.FileInputStream and java.io.FileOutputStream are disallowed in favor of
         Files.newInputStream and Files.newOutputStream.
         See https://github.com/checkstyle/checkstyle/issues/5638 -->
  <disallow class="java.io.FileInputStream"/>
  <disallow class="java.io.FileOutputStream"/>

  <!-- guava causes issues with other libraries since not everyone is on the same version -->
  <disallow pkg="com\.google.*" regex="true"/>

  <!-- until https://github.com/checkstyle/checkstyle/issues/6628 -->
  <allow class="com.puppycrawl.tools.checkstyle.DetailAstImpl"/>

  <allow pkg="com.puppycrawl.tools.checkstyle.api"/>
  <allow pkg="com.puppycrawl.tools.checkstyle.checks"/>
  <allow pkg="java.io"/>
  <allow pkg="java.net"/>
  <allow pkg="java.util"/>
  <allow pkg="javax.xml.parsers"/>
  <allow pkg="org.apache.commons.beanutils"/>
  <allow pkg="org.apache.commons.logging"/>
  <allow pkg="org.xml.sax"/>

  <!-- The local ones -->
  <allow pkg="java.lang.reflect" local-only="true" />
  <allow pkg="java.nio" local-only="true" />
  <allow class="java.security.MessageDigest" local-only="true"/>
  <allow class="java.security.NoSuchAlgorithmException" local-only="true"/>
  <allow pkg="com.puppycrawl.tools.checkstyle.utils" local-only="true"/>
  <allow pkg="com.puppycrawl.tools.checkstyle.grammar" local-only="true"/>
  <allow pkg="picocli" local-only="true"/>
  <allow class="com.puppycrawl.tools.checkstyle.JavadocDetailNodeParser.+"
          local-only="true" regex="true"/>
  <allow class="java.lang.annotation.ElementType" local-only="true"/>
  <allow class="java.lang.annotation.Inherited" local-only="true"/>
  <allow class="java.lang.annotation.Retention" local-only="true"/>
  <allow class="java.lang.annotation.RetentionPolicy" local-only="true"/>
  <allow class="java.lang.annotation.Target" local-only="true"/>
  <allow class="com.puppycrawl.tools.checkstyle.xpath.XpathQueryGenerator" local-only="true"/>

  <allow class="com.puppycrawl.tools.checkstyle.XpathFileGeneratorAstFilter"
         local-only="true"/>
  <allow class="com.puppycrawl.tools.checkstyle.XpathFileGeneratorAuditListener"
         local-only="true"/>

  <file name="DetailAstImpl|JavaParser" regex="true">
    <allow pkg="antlr"/>
  </file>
  <file name="JavadocDetailNodeParser">
    <allow pkg="org.antlr.v4.runtime"/>
  </file>
  <file name="PropertyCacheFile">
    <allow class="java.math.BigInteger"/>
  </file>

  <subpackage name="utils">
    <!-- until https://github.com/checkstyle/checkstyle/issues/6628 -->
    <allow pkg="antlr"/>
    <allow class="com.puppycrawl.tools.checkstyle.DetailAstImpl"/>

    <allow pkg="java.lang.reflect" local-only="true" />
    <allow pkg="java.nio" local-only="true" />
    <allow class="com.puppycrawl.tools.checkstyle.TreeWalkerFilter"/>
    <allow class="com.google.common.reflect.ClassPath" local-only="true"/>

    <file name="XpathUtil" regex="true">
      <allow pkg="net.sf.saxon"/>
      <allow class="com.puppycrawl.tools.checkstyle.AstTreeStringPrinter"/>
      <allow class="com.puppycrawl.tools.checkstyle.JavaParser"/>
      <allow class="com.puppycrawl.tools.checkstyle.xpath.AbstractNode"/>
      <allow class="com.puppycrawl.tools.checkstyle.xpath.RootNode"/>
    </file>
  </subpackage>

  <subpackage name="ant">
    <disallow pkg="com.puppycrawl.tools.checkstyle.checks"/>
    <disallow pkg="com.puppycrawl.tools.checkstyle.filters"/>
    <disallow pkg="com.puppycrawl.tools.checkstyle.gui"/>

    <allow pkg="org.apache.tools.ant" local-only="true"/>
    <allow pkg="com.puppycrawl.tools.checkstyle"/>

    <allow class="java.nio.file.Files" local-only="true"/>
  </subpackage>

  <subpackage name="api">
    <disallow pkg="org.antlr.v4.runtime"/>

    <allow pkg="com.puppycrawl.tools.checkstyle.grammar"/>
    <allow pkg="java.lang.reflect" local-only="true"/>
    <allow pkg="java.nio.charset" local-only="true"/>
    <allow class="java.beans.PropertyDescriptor" local-only="true"/>
    <allow class="java.nio.file.Files" local-only="true"/>
    <allow class="java.text.MessageFormat" local-only="true"/>
    <allow class="com.puppycrawl.tools.checkstyle.grammar.CommentListener"
           local-only="true"/>
    <!-- AccessModifier is in util package (should be moved to api package) to disallow
    its usage by API clients till https://github.com/checkstyle/checkstyle/issues/3511-->
    <allow class="com.puppycrawl.tools.checkstyle.checks.naming.AccessModifier"
           local-only="true"/>

    <allow class="com.puppycrawl.tools.checkstyle.Checker" local-only="true"/>
    <!-- allowed till https://github.com/checkstyle/checkstyle/issues/3817 -->
    <allow pkg="com.puppycrawl.tools.checkstyle.utils"/>
  </subpackage>

  <subpackage name="checks">
    <allow pkg="java.math"/>
    <allow pkg="com.puppycrawl.tools.checkstyle.utils"/>
    <allow class="java.nio.charset.StandardCharsets" local-only="true"/>
    <allow class="java.nio.file.Files" local-only="true"/>
    <allow class="java.nio.file.NoSuchFileException" local-only="true"/>
    <allow class="com.puppycrawl.tools.checkstyle.Definitions" local-only="true"/>

    <allow class="com.puppycrawl.tools.checkstyle.StatelessCheck"/>
    <allow class="com.puppycrawl.tools.checkstyle.FileStatefulCheck"/>
    <allow class="com.puppycrawl.tools.checkstyle.GlobalStatefulCheck"/>

    <subpackage name="imports">
      <allow class="com.puppycrawl.tools.checkstyle.XmlLoader" local-only="true"/>
    </subpackage>
    <subpackage name="indentation">
      <allow pkg="java.lang.reflect"/>
    </subpackage>
    <subpackage name="header">
      <allow class="java.nio.charset.Charset" local-only="true"/>
      <allow class="java.nio.charset.StandardCharsets" local-only="true" />
    </subpackage>
    <subpackage name="javadoc">
      <allow pkg="com.puppycrawl.tools.checkstyle.grammar.javadoc"/>
      <allow pkg="java.lang.reflect"/>
      <allow class="com.puppycrawl.tools.checkstyle.JavadocDetailNodeParser"
        local-only="true"/>
      <allow class="com.puppycrawl.tools.checkstyle.JavadocDetailNodeParser.+"
            regex="true" local-only="true"/>
    </subpackage>
  </subpackage>

  <subpackage name="filters">
    <disallow pkg="com\.puppycrawl\.tools\.checkstyle\.checks\.[^.]+" regex="true"/>

    <allow pkg="net.sf.saxon"/>
    <allow class="java.lang.ref.WeakReference" local-only="true"/>
    <allow class="com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent" local-only="true"/>
    <allow class="com.puppycrawl.tools.checkstyle.TreeWalkerFilter" local-only="true"/>
    <allow class="com.puppycrawl.tools.checkstyle.XmlLoader" local-only="true"/>
    <allow pkg="com.puppycrawl.tools.checkstyle.utils"/>
    <allow pkg="com.puppycrawl.tools.checkstyle.xpath"/>
    <allow class="java.nio.charset.StandardCharsets" local-only="true"/>
  </subpackage>

  <subpackage name="gui" strategyOnMismatch="disallowed">
    <!-- until https://github.com/checkstyle/checkstyle/issues/3095 -->
    <allow pkg="antlr"/>
    <allow class="com.puppycrawl.tools.checkstyle.DetailAstImpl"/>

    <allow pkg="java.awt"/>
    <allow pkg="java.io"/>
    <allow pkg="javax.swing"/>
    <allow pkg="java.util" exact-match="true"/>
    <allow pkg="com.puppycrawl.tools.checkstyle.api" local-only="true"/>
    <allow class="com.puppycrawl.tools.checkstyle.gui.MainFrameModel.ParseMode"
           local-only="true"/>
    <disallow pkg="com\.puppycrawl\.tools\.checkstyle\.(checks|ant|doclets|filters)" regex="true"/>

    <file name=".*(Model|Presentation)" regex="true">
      <disallow pkg="java.awt.Graphics"/>
      <disallow pkg="java.awt.Component"/>
      <disallow pkg="javax\.swing\.J.*" regex="true"/>
      <allow class="java.nio.charset.StandardCharsets" />
      <allow class="com.puppycrawl.tools.checkstyle.JavadocDetailNodeParser"/>
      <allow class="com.puppycrawl.tools.checkstyle.JavaParser"/>
      <allow pkg="com.puppycrawl.tools.checkstyle.utils"/>
    </file>
  </subpackage>

  <subpackage name="xpath">
    <allow pkg="net.sf.saxon"/>
    <allow class="java.lang.reflect.Field"/>
    <allow class="java.nio.charset.StandardCharsets" local-only="true"/>
    <allow pkg="com.puppycrawl.tools.checkstyle.utils" local-only="true"/>
    <allow class="com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent" local-only="true"/>
  </subpackage>
</import-control>
