Search in sources :

Example 1 with ICompositeModificationContext

use of org.eclipse.xtext.ui.editor.model.edit.ICompositeModificationContext in project xtext-eclipse by eclipse.

the class QuickfixCrossrefTestLanguageQuickfixProvider method fixBadNames.

@SuppressWarnings("unchecked")
@Fix(QuickfixCrossrefTestLanguageValidator.BAD_NAME_IN_SUBELEMENTS)
public void fixBadNames(final Issue issue, IssueResolutionAcceptor acceptor) {
    acceptor.acceptMulti(issue, "Fix Bad Names", "Fix Bad Names", null, (Element main, ICompositeModificationContext<Element> ctx) -> {
        ctx.addModification(main.eContainer(), c -> {
            List<Element> siblings = (List<Element>) main.eContainer().eGet(main.eContainmentFeature());
            int index = siblings.indexOf(main);
            Element newEle = QuickfixCrossrefFactory.eINSTANCE.createElement();
            newEle.setName("newElement");
            siblings.add(index, newEle);
        });
        for (String s : issue.getData()[0].split(";")) {
            EObject ele = main.eResource().getEObject(s);
            Assert.assertTrue(ele instanceof Element);
            ctx.addModification((Element) ele, e -> {
                e.setName("goodname");
            });
        }
    });
}
Also used : ICompositeModificationContext(org.eclipse.xtext.ui.editor.model.edit.ICompositeModificationContext) Element(org.eclipse.xtext.ui.tests.quickfix.quickfixCrossref.Element) EObject(org.eclipse.emf.ecore.EObject) List(java.util.List) Fix(org.eclipse.xtext.ui.editor.quickfix.Fix)

Aggregations

List (java.util.List)1 EObject (org.eclipse.emf.ecore.EObject)1 ICompositeModificationContext (org.eclipse.xtext.ui.editor.model.edit.ICompositeModificationContext)1 Fix (org.eclipse.xtext.ui.editor.quickfix.Fix)1 Element (org.eclipse.xtext.ui.tests.quickfix.quickfixCrossref.Element)1