Search in sources :

Example 1 with IssueResolutionProvider

use of org.eclipse.xtext.ui.editor.quickfix.IssueResolutionProvider in project xtext-eclipse by eclipse.

the class LinkingErrorTest method testQuickfixTurnaround.

@Test
public void testQuickfixTurnaround() throws Exception {
    xtextEditor = newXtextEditor(PROJECT_NAME, MODEL_FILE, MODEL_WITH_LINKING_ERROR);
    IXtextDocument document = xtextEditor.getDocument();
    List<Issue> issues = getIssues(document);
    assertFalse(issues.isEmpty());
    Issue issue = issues.get(0);
    assertNotNull(issue);
    IssueResolutionProvider quickfixProvider = getInjector().getInstance(IssueResolutionProvider.class);
    List<IssueResolution> resolutions = quickfixProvider.getResolutions(issue);
    assertEquals(1, resolutions.size());
    IssueResolution resolution = resolutions.get(0);
    assertEquals("Change to 'Bar'", resolution.getLabel());
    resolution.apply();
    issues = getIssues(document);
    assertTrue(issues.isEmpty());
}
Also used : Issue(org.eclipse.xtext.validation.Issue) IssueResolutionProvider(org.eclipse.xtext.ui.editor.quickfix.IssueResolutionProvider) IssueResolution(org.eclipse.xtext.ui.editor.quickfix.IssueResolution) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) Test(org.junit.Test)

Example 2 with IssueResolutionProvider

use of org.eclipse.xtext.ui.editor.quickfix.IssueResolutionProvider 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 IssueResolutionProvider

use of org.eclipse.xtext.ui.editor.quickfix.IssueResolutionProvider in project xtext-eclipse by eclipse.

the class LinkingErrorTest method testBug361509.

@Test
public void testBug361509() throws Exception {
    xtextEditor = newXtextEditor(PROJECT_NAME, MODEL_FILE, MODEL_WITH_LINKING_ERROR_361509);
    IXtextDocument document = xtextEditor.getDocument();
    List<Issue> issues = getIssues(document);
    assertFalse(issues.isEmpty());
    Issue issue = issues.get(0);
    assertNotNull(issue);
    IssueResolutionProvider quickfixProvider = getInjector().getInstance(IssueResolutionProvider.class);
    List<IssueResolution> resolutions = quickfixProvider.getResolutions(issue);
    assertEquals(1, resolutions.size());
    IssueResolution resolution = resolutions.get(0);
    assertEquals("Change to 'ref'", resolution.getLabel());
    resolution.apply();
    issues = getIssues(document);
    assertTrue(issues.isEmpty());
    assertEquals(MODEL_WITH_LINKING_ERROR_361509.replace("raf", "^ref"), document.get());
}
Also used : Issue(org.eclipse.xtext.validation.Issue) IssueResolutionProvider(org.eclipse.xtext.ui.editor.quickfix.IssueResolutionProvider) IssueResolution(org.eclipse.xtext.ui.editor.quickfix.IssueResolution) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) Test(org.junit.Test)

Example 4 with IssueResolutionProvider

use of org.eclipse.xtext.ui.editor.quickfix.IssueResolutionProvider in project xtext-eclipse by eclipse.

the class XtextGrammarQuickfixProviderTest method assertAndApplySingleResolution.

private void assertAndApplySingleResolution(XtextEditor xtextEditor, String issueCode, int issueDataCount, String resolutionLabel, boolean isCleanAfterApply) {
    IssueResolutionProvider quickfixProvider = createInjector().getInstance(IssueResolutionProvider.class);
    IXtextDocument document = xtextEditor.getDocument();
    List<Issue> issues = getIssues(document);
    assertFalse(issues.isEmpty());
    Issue issue = issues.iterator().next();
    assertEquals(issueCode, issue.getCode());
    assertNotNull(issue.getData());
    assertEquals(issueDataCount, issue.getData().length);
    List<IssueResolution> resolutions = quickfixProvider.getResolutions(issue);
    assertEquals(1, resolutions.size());
    IssueResolution resolution = resolutions.iterator().next();
    assertEquals(resolutionLabel, resolution.getLabel());
    try {
        resolution.apply();
        assertEquals(getIssues(document).toString(), isCleanAfterApply, getIssues(document).isEmpty());
    } finally {
        // Save xtextEditor in any case. Otherwise test will stuck,
        // because the "save changed resource dialog" waits for user input.
        xtextEditor.doSave(new NullProgressMonitor());
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Issue(org.eclipse.xtext.validation.Issue) IssueResolutionProvider(org.eclipse.xtext.ui.editor.quickfix.IssueResolutionProvider) IssueResolution(org.eclipse.xtext.ui.editor.quickfix.IssueResolution) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument)

Example 5 with IssueResolutionProvider

use of org.eclipse.xtext.ui.editor.quickfix.IssueResolutionProvider in project n4js by eclipse.

the class OwnResourceValidatorAwareValidatingEditorCallback method newValidationJob.

private ValidationJob newValidationJob(final XtextEditor editor) {
    final IXtextDocument document = editor.getDocument();
    final IAnnotationModel annotationModel = editor.getInternalSourceViewer().getAnnotationModel();
    final IssueResolutionProvider issueResolutionProvider = getService(editor, IssueResolutionProvider.class);
    final MarkerTypeProvider markerTypeProvider = getService(editor, MarkerTypeProvider.class);
    final MarkerCreator markerCreator = getService(editor, MarkerCreator.class);
    final IValidationIssueProcessor issueProcessor = new CompositeValidationIssueProcessor(new AnnotationIssueProcessor(document, annotationModel, issueResolutionProvider), new MarkerIssueProcessor(editor.getResource(), markerCreator, markerTypeProvider));
    return editor.getDocument().modify(resource -> {
        final IResourceServiceProvider serviceProvider = resource.getResourceServiceProvider();
        final IResourceValidator resourceValidator = serviceProvider.getResourceValidator();
        return new ValidationJob(resourceValidator, editor.getDocument(), issueProcessor, ALL);
    });
}
Also used : IValidationIssueProcessor(org.eclipse.xtext.ui.editor.validation.IValidationIssueProcessor) MarkerTypeProvider(org.eclipse.xtext.ui.validation.MarkerTypeProvider) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) IssueResolutionProvider(org.eclipse.xtext.ui.editor.quickfix.IssueResolutionProvider) IResourceValidator(org.eclipse.xtext.validation.IResourceValidator) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) MarkerCreator(org.eclipse.xtext.ui.editor.validation.MarkerCreator) MarkerIssueProcessor(org.eclipse.xtext.ui.editor.validation.MarkerIssueProcessor) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) AnnotationIssueProcessor(org.eclipse.xtext.ui.editor.validation.AnnotationIssueProcessor) ValidationJob(org.eclipse.xtext.ui.editor.validation.ValidationJob)

Aggregations

IssueResolutionProvider (org.eclipse.xtext.ui.editor.quickfix.IssueResolutionProvider)5 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)4 IssueResolution (org.eclipse.xtext.ui.editor.quickfix.IssueResolution)4 Issue (org.eclipse.xtext.validation.Issue)4 Test (org.junit.Test)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 URI (org.eclipse.emf.common.util.URI)1 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)1 IResourceServiceProvider (org.eclipse.xtext.resource.IResourceServiceProvider)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 AnnotationIssueProcessor (org.eclipse.xtext.ui.editor.validation.AnnotationIssueProcessor)1 IValidationIssueProcessor (org.eclipse.xtext.ui.editor.validation.IValidationIssueProcessor)1 MarkerCreator (org.eclipse.xtext.ui.editor.validation.MarkerCreator)1 MarkerIssueProcessor (org.eclipse.xtext.ui.editor.validation.MarkerIssueProcessor)1 ValidationJob (org.eclipse.xtext.ui.editor.validation.ValidationJob)1 Element (org.eclipse.xtext.ui.tests.quickfix.quickfixCrossref.Element)1 Main (org.eclipse.xtext.ui.tests.quickfix.quickfixCrossref.Main)1 MarkerTypeProvider (org.eclipse.xtext.ui.validation.MarkerTypeProvider)1 IResourceValidator (org.eclipse.xtext.validation.IResourceValidator)1