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());
}
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());
}
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());
}
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());
}
}
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);
});
}
Aggregations