Search in sources :

Example 1 with Version

use of java.lang.module.ModuleDescriptor.Version in project openj9 by eclipse.

the class MyLoader method dumpModules.

private void dumpModules() {
    HashSet<Option> opts = new HashSet<>(Arrays.asList(new Option[] { Option.RETAIN_CLASS_REFERENCE, Option.SHOW_HIDDEN_FRAMES, Option.SHOW_REFLECT_FRAMES }));
    List<StackFrame> frameList = (StackWalker.getInstance(opts)).walk(s -> s.collect(Collectors.toList()));
    for (StackFrame f : frameList) {
        Module frameModule = f.getDeclaringClass().getModule();
        if ((null != frameModule)) {
            ModuleDescriptor d = frameModule.getDescriptor();
            if (null != d) {
                StackTraceElement e = f.toStackTraceElement();
                String modName = d.name();
                if (null != modName) {
                    assertEquals(modName, e.getModuleName(), "Wrong module name");
                }
                Optional<Version> modVersion = d.version();
                if (modVersion.isPresent()) {
                    assertEquals(modVersion.get(), e.getModuleVersion(), "Wrong module version");
                }
                if (f.getDeclaringClass() == Thread.class) {
                    assertEquals("java.base", e.getModuleName(), "Wrong module name");
                }
            }
        }
    }
}
Also used : ModuleDescriptor(java.lang.module.ModuleDescriptor) Version(java.lang.module.ModuleDescriptor.Version) StackFrame(java.lang.StackWalker.StackFrame) Option(java.lang.StackWalker.Option) Module(java.lang.Module) HashSet(java.util.HashSet)

Aggregations

Module (java.lang.Module)1 Option (java.lang.StackWalker.Option)1 StackFrame (java.lang.StackWalker.StackFrame)1 ModuleDescriptor (java.lang.module.ModuleDescriptor)1 Version (java.lang.module.ModuleDescriptor.Version)1 HashSet (java.util.HashSet)1