Source:
private void processDynamicElements(MMenu menuModel, MenuManager menuManager) { MMenuElement[] ml = menuModel.getChildren().toArray( new MMenuElement[menuModel.getChildren().size()]); for (MMenuElement currentMenuElement : ml) { if (currentMenuElement instanceof MDynamicMenuContribution) { MDynamicMenuContribution dmc = (MDynamicMenuContribution) currentMenuElement; Object contribution = dmc.getObject(); if (contribution == null) { IEclipseContext context = modelService.getContainingContext(menuModel); contribution = contributionFactory.create(dmc.getContributionURI(), context); dmc.setObject(contribution); } IEclipseContext dynamicMenuContext = EclipseContextFactory.create(); ArrayList<MMenuElement> mel = new ArrayList<>(); dynamicMenuContext.set(List.class, mel); dynamicMenuContext.set(MDynamicMenuContribution.class, dmc); IEclipseContext parentContext = modelService.getContainingContext(currentMenuElement); Object rc = ContextInjectionFactory.invoke(contribution, AboutToShow.class, parentContext, dynamicMenuContext, this); dynamicMenuContext.dispose(); if (rc == this) { if (logger != null) { logger.error("Missing @AboutToShow method in " + contribution); } continue; } if (mel.size() > 0) { int position = 0; while (position < menuModel.getChildren().size()) { if (currentMenuElement == menuModel.getChildren().get( position)) { position++; break; } position++; } for (int j = 0; j < mel.size(); j++) { MMenuElement menuElement = mel.get(j); if (menuElement.getElementId() == null || menuElement.getElementId().length() < 1) { menuElement.setElementId(currentMenuElement .getElementId() + "." + j); } menuModel.getChildren().add(position++, menuElement); renderer.modelProcessSwitch(menuManager, menuElement); } currentMenuElement.getTransientData().put(DYNAMIC_ELEMENT_STORAGE_KEY, mel); } } } }

Target:
private void processDynamicElements(MMenu menuModel, MenuManager menuManager) { MMenuElement[] menuElements = menuModel.getChildren().toArray( new MMenuElement[menuModel.getChildren().size()]); for (MMenuElement currentMenuElement : menuElements) { if (currentMenuElement instanceof MDynamicMenuContribution) { MDynamicMenuContribution dmc = (MDynamicMenuContribution) currentMenuElement; Object contribution = dmc.getObject(); if (contribution == null) { IEclipseContext context = modelService.getContainingContext(menuModel); contribution = contributionFactory.create(dmc.getContributionURI(), context); dmc.setObject(contribution); } IEclipseContext dynamicMenuContext = EclipseContextFactory.create(); ArrayList<MMenuElement> mel = new ArrayList<>(); dynamicMenuContext.set(List.class, mel); dynamicMenuContext.set(MDynamicMenuContribution.class, dmc); IEclipseContext parentContext = modelService.getContainingContext(currentMenuElement); Object rc = ContextInjectionFactory.invoke(contribution, AboutToShow.class, parentContext, dynamicMenuContext, this); dynamicMenuContext.dispose(); if (rc == this) { if (logger != null) { logger.error("Missing @AboutToShow method in " + contribution); } continue; } if (mel.size() > 0) { int position = 0; while (position < menuModel.getChildren().size()) { if (currentMenuElement == menuModel.getChildren().get( position)) { position++; break; } position++; } for (int j = 0; j < mel.size(); j++) { MMenuElement menuElement = mel.get(j); if (menuElement.getElementId() == null || menuElement.getElementId().length() < 1) { menuElement.setElementId(currentMenuElement .getElementId() + "." + j); } menuModel.getChildren().add(position++, menuElement); renderer.modelProcessSwitch(menuManager, menuElement); } currentMenuElement.getTransientData().put(DYNAMIC_ELEMENT_STORAGE_KEY, mel); } } } }