Source:
<code>public void initialise() { setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation()); ColumnLayout mainLayout = new ColumnLayout(); mainLayout.setHorizontalSpacing(8); mainLayout.setVerticalSpacing(8); Map<TelemetryCategory, Class> telemetryCategories = Maps.newHashMap(); DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry()); for (Name moduleId : moduleManager.getRegistry().getModuleIds()) { Module module = moduleManager.getRegistry().getLatestModuleVersion(moduleId); if (module.isCodeModule()) { ResolutionResult result = resolver.resolve(moduleId); if (result.isSuccess()) { try (ModuleEnvironment environment = moduleManager.loadEnvironment(result.getModules(), false)) { for (Class<?> holdingType : environment.getTypesAnnotatedWith(TelemetryCategory.class, new FromModule(environment, moduleId))) { TelemetryCategory telemetryCategory = holdingType.getAnnotation(TelemetryCategory.class); telemetryCategories.put(telemetryCategory, holdingType); } } } } <START> } <END> for (TelemetryCategory telemetryCategory: telemetryCategories.keySet()) { Class metricClass = telemetryCategories.get(telemetryCategory); Metric metricType = metric.getMap().get(metricClass); Map<String,Object> map = metricType.getMap(); addTelemetrySection(telemetryCategory,mainLayout,map); } ScrollableArea area = find("area", ScrollableArea.class); area.setContent(mainLayout); WidgetUtil.trySubscribe(this, "back", button -> triggerBackAnimation()); WidgetUtil.tryBindCheckbox(this, "enableTelemetry", BindHelper.bindBeanProperty("enableTelemetry", config.getTelemetryConfig(), Boolean.TYPE)); }</code><technical_language>put this in a method -> fetchTelemetryCategoriesFromEnvironment()</technical_language>

Target:
public void initialise() { setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation()); ColumnLayout mainLayout = new ColumnLayout(); mainLayout.setHorizontalSpacing(8); mainLayout.setVerticalSpacing(8); Map<TelemetryCategory, Class> telemetryCategories = fetchTelemetryCategoriesFromEnvironment(); for (Map.Entry<TelemetryCategory, Class> telemetryCategory: telemetryCategories.entrySet()) { Class metricClass = telemetryCategory.getValue(); Optional<Metric> optional = metrics.getMetric(metricClass); if (optional.isPresent()) { Metric metric = optional.get(); Map<String, Object> map = metric.getFieldValueMap(); addTelemetrySection(telemetryCategory.getKey(), mainLayout, map); } } ScrollableArea area = find("area", ScrollableArea.class); area.setContent(mainLayout); WidgetUtil.trySubscribe(this, "back", button -> triggerBackAnimation()); WidgetUtil.tryBindCheckBoxWithListener(this, "telemetryEnabled", BindHelper.bindBeanProperty("telemetryEnabled", config.getTelemetryConfig(), Boolean.TYPE),(checkbox) -> { if (config.getTelemetryConfig().isTelemetryEnabled()) { pushAddServerPopupAndStartEmitter(); } }); WidgetUtil.tryBindCheckBoxWithListener(this, "errorReportingEnabled", BindHelper.bindBeanProperty("errorReportingEnabled", config.getTelemetryConfig(), Boolean.TYPE), (checkbox) -> { if (config.getTelemetryConfig().isErrorReportingEnabled()) { pushAddServerPopupAndStartLogBackAppender(); } else { TelemetryLogstashAppender telemetryLogstashAppender = TelemetryUtils.fetchTelemetryLogstashAppender(); telemetryLogstashAppender.stop(); } }); }