Class ClassTool
- java.lang.Object
-
- org.apache.commons.jexl3.internal.introspection.ClassTool
-
final class ClassTool extends java.lang.ObjectUtility for Java9+ backport in Java8 of class and module related methods.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.invoke.MethodHandleGET_MODULEThe Class.getModule() method.private static java.lang.invoke.MethodHandleGET_PKGNAMEThe Class.getPackageName() method.private static java.lang.invoke.MethodHandleIS_EXPORTEDThe Module.isExported(String packageName) method.private static java.lang.ObjectJEXL_MODULEThe Module of JEXL itself.
-
Constructor Summary
Constructors Constructor Description ClassTool()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static java.lang.StringgetPackageName(java.lang.Class<?> clz)Gets the package name of a class (class.getPackage() may return null).(package private) static booleanisExported(java.lang.Class<?> declarator)Checks whether a class is exported by its module (Java 9+) to JEXL.
-
-
-
Field Detail
-
GET_MODULE
private static final java.lang.invoke.MethodHandle GET_MODULE
The Class.getModule() method.
-
GET_PKGNAME
private static final java.lang.invoke.MethodHandle GET_PKGNAME
The Class.getPackageName() method.
-
IS_EXPORTED
private static final java.lang.invoke.MethodHandle IS_EXPORTED
The Module.isExported(String packageName) method.
-
JEXL_MODULE
private static final java.lang.Object JEXL_MODULE
The Module of JEXL itself.
-
-
Method Detail
-
getPackageName
static java.lang.String getPackageName(java.lang.Class<?> clz)
Gets the package name of a class (class.getPackage() may return null).- Parameters:
clz- the class- Returns:
- the class package name
-
isExported
static boolean isExported(java.lang.Class<?> declarator)
Checks whether a class is exported by its module (Java 9+) to JEXL. 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 jexlModule ClassTool.getClass().getModule(); Module module = declarator.getModule(); return module.isExported(declarator.getPackageName(), jexlModule);This is required since some classes and methods may not be exported thus not callable through reflection. A package can be non-exported, unconditionally exported (to all reading modules), or use qualified exports to only export the package to specifically named modules. This method is only concerned with whether JEXL may reflectively access the package, so a qualified export naming the JEXL module is the least-privilege access required. The declarator's module may also use: unqualified exports, qualifiedopens, or unqualifiedopens, in increasing order of privilege; the last two allow reflective access to non-public members and are not recommended.- Parameters:
declarator- the class- Returns:
- true if class is exported (to JEXL) or no module support exists
-
-