Class ClassTool
java.lang.Object
org.apache.commons.jexl3.internal.introspection.ClassTool
Utility for Java9+ backport in Java8 of class and module related methods.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final MethodHandle
The Class.getModule() method.private static final MethodHandle
The Class.getPackageName() method.private static final MethodHandle
The Module.isExported(String packageName) method. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static String
getPackageName
(Class<?> clz) Gets the package name of a class (class.getPackage() may return null).(package private) static boolean
isExported
(Class<?> declarator) Checks whether a class is exported by its module (Java 9+).
-
Field Details
-
GET_MODULE
The Class.getModule() method. -
GET_PKGNAME
The Class.getPackageName() method. -
IS_EXPORTED
The Module.isExported(String packageName) method.
-
-
Constructor Details
-
ClassTool
ClassTool()
-
-
Method Details
-
getPackageName
Gets the package name of a class (class.getPackage() may return null).- Parameters:
clz
- the class- Returns:
- the class package name
-
isExported
Checks whether a class is exported by its module (Java 9+). The code performs the following sequence through reflection (since the same jar can run on a Java8 or Java9+ runtime and the module features does not exist on 8).Module module = declarator.getModule(); return module.isExported(declarator.getPackageName());
This is required since some classes and methods may not be exported thus not callable through reflection.- Parameters:
declarator
- the class- Returns:
- true if class is exported or no module support exists
-