Search in sources :

Example 1 with IBatchableModification

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()]);
}
Also used : Issue(org.eclipse.xtext.validation.Issue) IMarkerResolution(org.eclipse.ui.IMarkerResolution) CoreException(org.eclipse.core.runtime.CoreException) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) ITextualMultiModification(org.eclipse.xtext.ui.editor.model.edit.ITextualMultiModification) IBatchableModification(org.eclipse.xtext.ui.editor.model.edit.BatchModification.IBatchableModification)

Example 2 with IBatchableModification

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();
}
Also used : Arrays(java.util.Arrays) IssueUtil(org.eclipse.xtext.ui.util.IssueUtil) WorkbenchMarkerResolution(org.eclipse.ui.views.markers.WorkbenchMarkerResolution) SubMonitor(org.eclipse.core.runtime.SubMonitor) Inject(com.google.inject.Inject) Image(org.eclipse.swt.graphics.Image) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Objects(java.util.Objects) Logger(org.apache.log4j.Logger) List(java.util.List) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) Provider(com.google.inject.Provider) IModification(org.eclipse.xtext.ui.editor.model.edit.IModification) IProject(org.eclipse.core.resources.IProject) Issue(org.eclipse.xtext.validation.Issue) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IBatchableModification(org.eclipse.xtext.ui.editor.model.edit.BatchModification.IBatchableModification) Map(java.util.Map) BatchModification(org.eclipse.xtext.ui.editor.model.edit.BatchModification) Optional(java.util.Optional) IMarker(org.eclipse.core.resources.IMarker) IMarkerResolution(org.eclipse.ui.IMarkerResolution) SubMonitor(org.eclipse.core.runtime.SubMonitor) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) BatchModification(org.eclipse.xtext.ui.editor.model.edit.BatchModification) IBatchableModification(org.eclipse.xtext.ui.editor.model.edit.BatchModification.IBatchableModification) ArrayList(java.util.ArrayList) List(java.util.List) IMarker(org.eclipse.core.resources.IMarker) IModification(org.eclipse.xtext.ui.editor.model.edit.IModification)

Aggregations

IMarkerResolution (org.eclipse.ui.IMarkerResolution)2 IBatchableModification (org.eclipse.xtext.ui.editor.model.edit.BatchModification.IBatchableModification)2 Issue (org.eclipse.xtext.validation.Issue)2 Inject (com.google.inject.Inject)1 Provider (com.google.inject.Provider)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Logger (org.apache.log4j.Logger)1 IMarker (org.eclipse.core.resources.IMarker)1 IProject (org.eclipse.core.resources.IProject)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1