Search in sources :

Example 1 with MarkerResolutionGenerator

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

the class XtextGrammarQuickfixProviderTest method assertAndApplyAllResolutions.

private void assertAndApplyAllResolutions(XtextEditor xtextEditor, String issueCode, int issueDataCount, int issueCount, String resolutionLabel) throws CoreException {
    InternalBuilderTest.setAutoBuild(true);
    if (xtextEditor.isDirty()) {
        xtextEditor.doSave(new NullProgressMonitor());
    }
    InternalBuilderTest.fullBuild();
    IXtextDocument document = xtextEditor.getDocument();
    validateInEditor(document);
    List<Issue> issues = getIssues(document);
    assertFalse("Document has no issues, but should.", issues.isEmpty());
    issues.iterator().forEachRemaining((issue) -> {
        assertEquals(issueCode, issue.getCode());
        assertNotNull(issue.getData());
        assertEquals(issueDataCount, issue.getData().length);
    });
    IResource resource = xtextEditor.getResource();
    IMarker[] problems = resource.findMarkers(MarkerTypes.FAST_VALIDATION, true, IResource.DEPTH_INFINITE);
    assertEquals("Resource should have " + issueCount + " error marker.", issueCount, problems.length);
    validateInEditor(document);
    MarkerResolutionGenerator instance = injector.getInstance(MarkerResolutionGenerator.class);
    List<IMarkerResolution> resolutions = Lists.newArrayList(instance.getResolutions(problems[0]));
    assertEquals(1, resolutions.size());
    IMarkerResolution resolution = resolutions.iterator().next();
    assertTrue(resolution instanceof WorkbenchMarkerResolution);
    WorkbenchMarkerResolution workbenchResolution = (WorkbenchMarkerResolution) resolution;
    IMarker primaryMarker = problems[0];
    List<IMarker> others = Lists.newArrayList(workbenchResolution.findOtherMarkers(problems));
    assertFalse(others.contains(primaryMarker));
    assertEquals(problems.length - 1, others.size());
    others.add(primaryMarker);
    workbenchResolution.run(others.toArray(new IMarker[others.size()]), new NullProgressMonitor());
    if (xtextEditor.isDirty()) {
        xtextEditor.doSave(null);
    }
    InternalBuilderTest.cleanBuild();
    problems = resource.findMarkers(MarkerTypes.FAST_VALIDATION, true, IResource.DEPTH_INFINITE);
    assertEquals("Resource should have no error marker.", 0, problems.length);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Issue(org.eclipse.xtext.validation.Issue) IMarkerResolution(org.eclipse.ui.IMarkerResolution) IMarker(org.eclipse.core.resources.IMarker) MarkerResolutionGenerator(org.eclipse.xtext.ui.editor.quickfix.MarkerResolutionGenerator) WorkbenchMarkerResolution(org.eclipse.ui.views.markers.WorkbenchMarkerResolution) IResource(org.eclipse.core.resources.IResource) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument)

Example 2 with MarkerResolutionGenerator

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

the class AbstractQuickfixTest method applyQuickfixOnMultipleMarkers.

protected void applyQuickfixOnMultipleMarkers(IMarker[] markers) {
    MarkerResolutionGenerator generator = getInjector().getInstance(MarkerResolutionGenerator.class);
    IMarker primaryMarker = markers[0];
    IMarkerResolution[] resolutions = generator.getResolutions(primaryMarker);
    Assert.assertEquals(1, resolutions.length);
    assertTrue(resolutions[0] instanceof WorkbenchMarkerResolutionAdapter);
    WorkbenchMarkerResolutionAdapter resolution = (WorkbenchMarkerResolutionAdapter) resolutions[0];
    List<IMarker> others = Lists.newArrayList(resolution.findOtherMarkers(markers));
    assertFalse(others.contains(primaryMarker));
    assertEquals(markers.length - 1, others.size());
    others.add(primaryMarker);
    resolution.run(others.toArray(new IMarker[others.size()]), new NullProgressMonitor());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IMarkerResolution(org.eclipse.ui.IMarkerResolution) WorkbenchMarkerResolutionAdapter(org.eclipse.xtext.ui.editor.quickfix.WorkbenchMarkerResolutionAdapter) IMarker(org.eclipse.core.resources.IMarker) MarkerResolutionGenerator(org.eclipse.xtext.ui.editor.quickfix.MarkerResolutionGenerator)

Aggregations

IMarker (org.eclipse.core.resources.IMarker)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 IMarkerResolution (org.eclipse.ui.IMarkerResolution)2 MarkerResolutionGenerator (org.eclipse.xtext.ui.editor.quickfix.MarkerResolutionGenerator)2 IResource (org.eclipse.core.resources.IResource)1 WorkbenchMarkerResolution (org.eclipse.ui.views.markers.WorkbenchMarkerResolution)1 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)1 WorkbenchMarkerResolutionAdapter (org.eclipse.xtext.ui.editor.quickfix.WorkbenchMarkerResolutionAdapter)1 Issue (org.eclipse.xtext.validation.Issue)1