Search in sources :

Example 1 with Element

use of org.eclipse.xtext.ui.tests.quickfix.quickfixCrossref.Element 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)

Example 2 with Element

use of org.eclipse.xtext.ui.tests.quickfix.quickfixCrossref.Element in project xtext-eclipse by eclipse.

the class LinkingErrorTest method testSemanticIssueResolution.

@Test
public void testSemanticIssueResolution() throws Exception {
    xtextEditor = newXtextEditor(PROJECT_NAME, MODEL_FILE, MODEL_WITH_LINKING_ERROR);
    URI uriToProblem = xtextEditor.getDocument().readOnly(new IUnitOfWork<URI, XtextResource>() {

        @Override
        public URI exec(XtextResource state) throws Exception {
            Main main = (Main) state.getContents().get(0);
            Element element = main.getElements().get(1);
            return EcoreUtil.getURI(element);
        }
    });
    Issue.IssueImpl issue = new Issue.IssueImpl();
    issue.setUriToProblem(uriToProblem);
    issue.setCode(QuickfixCrossrefTestLanguageQuickfixProvider.SEMANTIC_FIX_ID);
    IssueResolutionProvider quickfixProvider = getInjector().getInstance(IssueResolutionProvider.class);
    List<IssueResolution> resolutions = quickfixProvider.getResolutions(issue);
    assertEquals(1, resolutions.size());
    IssueResolution issueResolution = resolutions.get(0);
    issueResolution.apply();
    xtextEditor.doSave(null);
    List<Issue> issues = getIssues(xtextEditor.getDocument());
    assertTrue(issues.isEmpty());
}
Also used : Issue(org.eclipse.xtext.validation.Issue) Element(org.eclipse.xtext.ui.tests.quickfix.quickfixCrossref.Element) IssueResolution(org.eclipse.xtext.ui.editor.quickfix.IssueResolution) XtextResource(org.eclipse.xtext.resource.XtextResource) URI(org.eclipse.emf.common.util.URI) IssueResolutionProvider(org.eclipse.xtext.ui.editor.quickfix.IssueResolutionProvider) Main(org.eclipse.xtext.ui.tests.quickfix.quickfixCrossref.Main) Test(org.junit.Test)

Example 3 with Element

use of org.eclipse.xtext.ui.tests.quickfix.quickfixCrossref.Element in project xtext-eclipse by eclipse.

the class QuickfixCrossrefTestLanguageSemanticSequencer method sequence.

@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
    EPackage epackage = semanticObject.eClass().getEPackage();
    ParserRule rule = context.getParserRule();
    Action action = context.getAssignedAction();
    Set<Parameter> parameters = context.getEnabledBooleanParameters();
    if (epackage == QuickfixCrossrefPackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case QuickfixCrossrefPackage.ELEMENT:
                sequence_Element(context, (Element) semanticObject);
                return;
            case QuickfixCrossrefPackage.MAIN:
                sequence_Main(context, (Main) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) Element(org.eclipse.xtext.ui.tests.quickfix.quickfixCrossref.Element) Parameter(org.eclipse.xtext.Parameter) Main(org.eclipse.xtext.ui.tests.quickfix.quickfixCrossref.Main) EPackage(org.eclipse.emf.ecore.EPackage)

Aggregations

Element (org.eclipse.xtext.ui.tests.quickfix.quickfixCrossref.Element)3 Main (org.eclipse.xtext.ui.tests.quickfix.quickfixCrossref.Main)2 List (java.util.List)1 URI (org.eclipse.emf.common.util.URI)1 EObject (org.eclipse.emf.ecore.EObject)1 EPackage (org.eclipse.emf.ecore.EPackage)1 Action (org.eclipse.xtext.Action)1 Parameter (org.eclipse.xtext.Parameter)1 ParserRule (org.eclipse.xtext.ParserRule)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 ICompositeModificationContext (org.eclipse.xtext.ui.editor.model.edit.ICompositeModificationContext)1 Fix (org.eclipse.xtext.ui.editor.quickfix.Fix)1 IssueResolution (org.eclipse.xtext.ui.editor.quickfix.IssueResolution)1 IssueResolutionProvider (org.eclipse.xtext.ui.editor.quickfix.IssueResolutionProvider)1 Issue (org.eclipse.xtext.validation.Issue)1 Test (org.junit.Test)1