use of org.eclipse.xtext.ui.editor.model.edit.BatchModification.IBatchableModification in project xtext-eclipse by eclipse.
the class MarkerResolutionGenerator method getResolutions.
@Override
public IMarkerResolution[] getResolutions(IMarker marker) {
final IMarkerResolution[] emptyResult = new IMarkerResolution[0];
try {
if (!marker.isSubtypeOf(MarkerTypes.ANY_VALIDATION))
return emptyResult;
} catch (CoreException e) {
return emptyResult;
}
if (!languageResourceHelper.isLanguageResource(marker.getResource())) {
return emptyResult;
}
XtextEditor editor = findEditor(marker.getResource());
if (editor != null) {
IAnnotationModel annotationModel = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
if (annotationModel != null && !isMarkerStillValid(marker, annotationModel))
return emptyResult;
}
Issue issue = getIssueUtil().createIssue(marker);
if (issue == null)
return emptyResult;
List<IssueResolution> resolutions = getResolutionProvider().getResolutions(issue);
List<IMarkerResolution> result = Lists.newArrayList();
List<IssueResolution> remaining = Lists.newArrayList();
for (IssueResolution resolution : resolutions) {
if (resolution.getModification() instanceof IBatchableModification) {
result.add(adapterFactory.create(marker, resolution));
} else if (resolution.getModification() instanceof ITextualMultiModification) {
result.add(textualMultiModificationAdapterFactory.create(marker, resolution));
} else {
remaining.add(resolution);
}
}
result.addAll(Lists.newArrayList(getAdaptedResolutions(remaining)));
return result.toArray(new IMarkerResolution[result.size()]);
}
use of org.eclipse.xtext.ui.editor.model.edit.BatchModification.IBatchableModification in project xtext-eclipse by eclipse.
the class WorkbenchMarkerResolutionAdapter method run.
@Override
public void run(IMarker[] markers, IProgressMonitor progressMonitor) {
Map<IProject, List<IMarker>> markersByProject = //
Arrays.asList(markers).stream().collect(Collectors.groupingBy(marker -> marker.getResource().getProject()));
SubMonitor monitor = SubMonitor.convert(progressMonitor);
monitor.beginTask("Applying resolutions", markersByProject.size());
markersByProject.forEach((key, value) -> {
BatchModification batch = batchModificationProvider.get();
batch.setProject(key);
List<IBatchableModification> modifications = new ArrayList<>();
List<IMarker> markersInProject = value;
markersInProject.forEach(marker -> {
IssueResolution resolution = resolution(marker);
if (resolution != null) {
IModification modification = resolution.getModification();
if (modification instanceof IBatchableModification) {
modifications.add((IBatchableModification) modification);
}
}
});
cancelIfNeeded(monitor);
batch.apply(modifications, monitor.newChild(1));
cancelIfNeeded(monitor);
});
monitor.done();
}
Aggregations