NamingConventionClassEnquirer
Date: 2017-11-20

jep

## Class NamingConventionClassEnquirer

- java.lang.Object
- - jep.NamingConventionClassEnquirer

- All Implemented Interfaces:
    ClassEnquirer

      public class NamingConventionClassEnquirer
      extends java.lang.Object
      implements ClassEnquirer

  A simple `ClassEnquirer` to see if the package/class to be imported in a Python sub-interpreter should be considered as a Java package/class. This enquirer can check for import statements beginning with java, com, gov, etc and country codes such as us, uk, fr, ch, etc.

  This class is useful for the following scenarios:
  - You don't want the overhead of initializing `ClassList.getInstance()`
  - You don't want all the classes in a package automatically imported
  - You don't have Python modules that resemble Java package names
  Since:
    3.3

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected java.util.Set<java.lang.String>` | `javaNames`
    `protected static java.util.List<java.lang.String>` | `TOP_LEVEL` the default top level package names: java, javax, com, gov, org, edu, mil, net

    - ### Fields inherited from interface jep.ClassEnquirer

      `RESTRICTED_PKG_NAMES`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `NamingConventionClassEnquirer()` Convenience constructor.
    `NamingConventionClassEnquirer(boolean includeDefaults)` Constructor
    `NamingConventionClassEnquirer(boolean includeDefaults, boolean includeCountryCodes)` Constructor

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addTopLevelPackageName(java.lang.String pkgStart)` Adds a top level package name to the list of names that should be considered as Java packages
    `java.lang.String[]` | `getClassNames(java.lang.String pkgName)` Given a Java package name, gets the fully-qualified classnames available for import in the package.
    `java.lang.String[]` | `getSubPackages(java.lang.String pkgName)` Given a Java package name, gets the sub-packages available.
    `boolean` | `isJavaPackage(java.lang.String name)` Checks if the name is likely available in Java as a package.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### TOP_LEVEL

          protected static final java.util.List<java.lang.String> TOP_LEVEL

      the default top level package names: java, javax, com, gov, org, edu, mil, net

    - #### javaNames

          protected java.util.Set<java.lang.String> javaNames

  - ### Constructor Detail

    - #### NamingConventionClassEnquirer

          public NamingConventionClassEnquirer()

      Convenience constructor. Includes defaults but not country codes.

    - #### NamingConventionClassEnquirer

          public NamingConventionClassEnquirer(boolean includeDefaults)

      Constructor
      Parameters:
        `includeDefaults` - whether or not typical package names such as java, javax, com, gov should be considered as a java package.

    - #### NamingConventionClassEnquirer

          public NamingConventionClassEnquirer(boolean includeDefaults,
                                               boolean includeCountryCodes)

      Constructor
      Parameters:
        `includeDefaults` - whether or not typical package names such as java, javax, com, gov should be considered as a java package.
        `includeCountryCodes` - whether or not a name starting with a 2-letter country code such a uk, de, fr, us, ch should be considered as a Java package.

  - ### Method Detail

    - #### addTopLevelPackageName

          public void addTopLevelPackageName(java.lang.String pkgStart)

      Adds a top level package name to the list of names that should be considered as Java packages
      Parameters:
        `pkgStart` - the start of a java package name to check, e.g. com, gov, us, it, fr

    - #### isJavaPackage

          public boolean isJavaPackage(java.lang.String name)

      Description copied from interface: `ClassEnquirer`
      Checks if the name is likely available in Java as a package. A return value of true implies the name corresponds to a Java package, but does not guarantee that an import will succeed. A return value of false implies that an import from Java would fail, but does not guarantee that an import will fail. Note: A fully-qualified Java class name should return false since it is not a package name and the importer hook is expecting that.
      Specified by:
        `isJavaPackage` in interface `ClassEnquirer`
      Parameters:
        `name` - the name to check, such as java, java.util, java.util.ArrayList
      Returns:
        true if it's likely a package supported by Java, false if it's likely a Python module (or a Java class name, or an invalid import)

    - #### getClassNames

          public java.lang.String[] getClassNames(java.lang.String pkgName)

      Description copied from interface: `ClassEnquirer`
      Given a Java package name, gets the fully-qualified classnames available for import in the package. This method is primarily used for introspection using Python's dir() method. This method can return null if dir() support is not necessary.
      Specified by:
        `getClassNames` in interface `ClassEnquirer`
      Parameters:
        `pkgName` - the name of a package the ClassEnquirer supports, such as java.util
      Returns:
        the list of classnames in the package, or null

    - #### getSubPackages

          public java.lang.String[] getSubPackages(java.lang.String pkgName)

      Description copied from interface: `ClassEnquirer`
      Given a Java package name, gets the sub-packages available. For example, a sub-package of package "java" is "util", and a sub-package of package "java.util" is "concurrent". This method is primarily used for introspection using Python's dir() method. This method can return null if dir() support is not necessary.
      Specified by:
        `getSubPackages` in interface `ClassEnquirer`
      Parameters:
        `pkgName` - the name of a package the ClassEnquirer supports, such as java.util
      Returns:
        the list of sub-packages in the package, or null