use of org.eclipse.xtext.ui.editor.model.edit.IModification in project xtext-eclipse by eclipse.
the class WorkbenchMarkerResolutionAdapter method run.
@Override
public void run(final IMarker[] markers, final IProgressMonitor progressMonitor) {
final Function1<IMarker, IProject> _function = (IMarker it) -> {
return it.getResource().getProject();
};
final Map<IProject, List<IMarker>> markersByProject = IterableExtensions.<IProject, IMarker>groupBy(((Iterable<? extends IMarker>) Conversions.doWrapArray(markers)), _function);
final SubMonitor monitor = SubMonitor.convert(progressMonitor);
monitor.beginTask("Applying resolutions", markersByProject.size());
Set<Map.Entry<IProject, List<IMarker>>> _entrySet = markersByProject.entrySet();
for (final Map.Entry<IProject, List<IMarker>> g : _entrySet) {
{
final BatchModification batch = this.batchModificationProvider.get();
batch.setProject(g.getKey());
final List<IMarker> markersInProject = g.getValue();
final Function1<IMarker, IssueResolution> _function_1 = (IMarker it) -> {
return this.resolution(it);
};
final List<IssueResolution> resolutions = IterableExtensions.<IssueResolution>toList(IterableExtensions.<IssueResolution>filterNull(ListExtensions.<IMarker, IssueResolution>map(markersInProject, _function_1)));
this.cancelIfNeeded(monitor);
final Function1<IssueResolution, IModification> _function_2 = (IssueResolution it) -> {
return it.getModification();
};
final Iterable<BatchModification.IBatchableModification> modifications = Iterables.<BatchModification.IBatchableModification>filter(ListExtensions.<IssueResolution, IModification>map(resolutions, _function_2), BatchModification.IBatchableModification.class);
this.cancelIfNeeded(monitor);
batch.apply(modifications, monitor.newChild(1));
this.cancelIfNeeded(monitor);
}
}
monitor.done();
}
use of org.eclipse.xtext.ui.editor.model.edit.IModification in project xtext-eclipse by eclipse.
the class XtextGrammarQuickfixProvider method fixImportedPackageFromSuperGrammar.
@Fix(INVALID_PACKAGE_REFERENCE_INHERITED)
public void fixImportedPackageFromSuperGrammar(final Issue issue, IssueResolutionAcceptor acceptor) {
if (issue.getData().length == 1)
acceptor.accept(issue, "Change to '" + issue.getData()[0] + "'", "Fix the bogus package import\n" + "import '" + issue.getData()[0] + "'", NULL_QUICKFIX_IMAGE, new IModification() {
@Override
public void apply(IModificationContext context) throws BadLocationException {
String replaceString = valueConverterService.toString(issue.getData()[0], "STRING");
IXtextDocument document = context.getXtextDocument();
String delimiter = document.get(issue.getOffset(), 1);
if (!replaceString.startsWith(delimiter)) {
replaceString = delimiter + replaceString.substring(1, replaceString.length() - 1) + delimiter;
}
document.replace(issue.getOffset(), issue.getLength(), replaceString);
}
});
}
use of org.eclipse.xtext.ui.editor.model.edit.IModification in project xtext-eclipse by eclipse.
the class CreateJavaTypeQuickfixes method newJavaAnnotationQuickfix.
protected void newJavaAnnotationQuickfix(final String typeName, final String explicitPackage, final XtextResource resource, Issue issue, IssueResolutionAcceptor issueResolutionAcceptor) {
String packageDescription = getPackageDescription(explicitPackage);
issueResolutionAcceptor.accept(issue, "Create Java annotation '@" + typeName + "'" + packageDescription, "Opens the new Java annotation wizard to create the type '@" + typeName + "'" + packageDescription, "java_file.gif", new IModification() {
@Override
public void apply(/* @Nullable */
IModificationContext context) throws Exception {
runAsyncInDisplayThread(new Runnable() {
@Override
public void run() {
NewAnnotationWizardPage annotationWizardPage = new NewAnnotationWizardPage();
NewAnnotationCreationWizard wizard = new NewAnnotationCreationWizard(annotationWizardPage, true);
WizardDialog dialog = createWizardDialog(wizard);
configureWizardPage(annotationWizardPage, resource.getURI(), typeName, explicitPackage);
dialog.open();
}
});
}
});
}
use of org.eclipse.xtext.ui.editor.model.edit.IModification in project dsl-devkit by dsldevkit.
the class FormatQuickfixProvider method removeOverride.
/**
* Semantic quickfix removing the override flag for a rule.
*
* @param issue
* the issue
* @param acceptor
* the acceptor
*/
@Fix(FormatJavaValidator.OVERRIDE_ILLEGAL_CODE)
public void removeOverride(final Issue issue, final IssueResolutionAcceptor acceptor) {
acceptor.accept(issue, "Remove override", "Remove override.", null, new IModification() {
@Override
public void apply(final IModificationContext context) throws BadLocationException {
context.getXtextDocument().modify(new IUnitOfWork<Void, XtextResource>() {
@Override
public java.lang.Void exec(final XtextResource state) {
Rule rule = (Rule) state.getEObject(issue.getUriToProblem().fragment());
rule.setOverride(false);
return null;
}
});
}
});
}
use of org.eclipse.xtext.ui.editor.model.edit.IModification in project dsl-devkit by dsldevkit.
the class CheckCfgQuickfixProvider method fixSeverityToMaxSeverity.
/**
* Fix severity by setting it to a legal value as is defined by severity range of referenced check. Legal
* severities are passed as issue data (org.eclipse.xtext.validation.Issue#getData()).
*
* @param issue
* the issue
* @param acceptor
* the acceptor
*/
@Fix(IssueCodes.SEVERITY_NOT_ALLOWED)
public void fixSeverityToMaxSeverity(final Issue issue, final IssueResolutionAcceptor acceptor) {
if (issue.getData() != null) {
for (final String severityProposal : issue.getData()) {
final String label = NLS.bind(Messages.CheckCfgQuickfixProvider_CORRECT_SEVERITY_LABEL, severityProposal);
final String descn = NLS.bind(Messages.CheckCfgQuickfixProvider_CORRECT_SEVERITY_DESCN, severityProposal);
acceptor.accept(issue, label, descn, NO_IMAGE, new IModification() {
public void apply(final IModificationContext context) throws BadLocationException {
IXtextDocument xtextDocument = context.getXtextDocument();
xtextDocument.replace(issue.getOffset(), issue.getLength(), severityProposal);
}
});
}
}
}
Aggregations