Package jep
Class NamingConventionClassEnquirer
java.lang.Object
jep.NamingConventionClassEnquirer
- All Implemented Interfaces:
ClassEnquirer
A simple ClassEnquirer
to see if the package/class to be imported in
a Python 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.
- 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 inherited from interface jep.ClassEnquirer
RESTRICTED_PKG_NAMES
-
Constructor Summary
ConstructorsConstructorDescriptionConvenience constructor.NamingConventionClassEnquirer
(boolean includeDefaults) ConstructorNamingConventionClassEnquirer
(boolean includeDefaults, boolean includeCountryCodes) Constructor -
Method Summary
Modifier and TypeMethodDescriptionaddTopLevelPackageName
(String pkgStart) Adds a top level package name to the list of names that should be considered as Java packagesString[]
getClassNames
(String pkgName) Given a Java package name, gets the fully-qualified classnames available for import in the package.String[]
getSubPackages
(String pkgName) Given a Java package name, gets the sub-packages available.boolean
isJavaPackage
(String name) Checks if the name is likely available in Java as a package.
-
Constructor Details
-
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 Details
-
addTopLevelPackageName
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- Returns:
- this instance of the NamingConventionClassEnquirer to support the fluent interface pattern
-
isJavaPackage
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 interfaceClassEnquirer
- 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
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 interfaceClassEnquirer
- 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
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 interfaceClassEnquirer
- 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
-