Search in sources :

Example 1 with IModification

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();
}
Also used : SubMonitor(org.eclipse.core.runtime.SubMonitor) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) IssueResolution(org.eclipse.xtext.ui.editor.quickfix.IssueResolution) IProject(org.eclipse.core.resources.IProject) BatchModification(org.eclipse.xtext.ui.editor.model.edit.BatchModification) List(java.util.List) IMarker(org.eclipse.core.resources.IMarker) Map(java.util.Map) IModification(org.eclipse.xtext.ui.editor.model.edit.IModification)

Example 2 with IModification

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);
            }
        });
}
Also used : IModificationContext(org.eclipse.xtext.ui.editor.model.edit.IModificationContext) IModification(org.eclipse.xtext.ui.editor.model.edit.IModification) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) Fix(org.eclipse.xtext.ui.editor.quickfix.Fix)

Example 3 with IModification

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();
                }
            });
        }
    });
}
Also used : IModificationContext(org.eclipse.xtext.ui.editor.model.edit.IModificationContext) NewAnnotationWizardPage(org.eclipse.jdt.ui.wizards.NewAnnotationWizardPage) NewAnnotationCreationWizard(org.eclipse.jdt.internal.ui.wizards.NewAnnotationCreationWizard) WizardDialog(org.eclipse.jface.wizard.WizardDialog) JavaModelException(org.eclipse.jdt.core.JavaModelException) IModification(org.eclipse.xtext.ui.editor.model.edit.IModification)

Example 4 with IModification

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;
                }
            });
        }
    });
}
Also used : IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) IModificationContext(org.eclipse.xtext.ui.editor.model.edit.IModificationContext) XtextResource(org.eclipse.xtext.resource.XtextResource) Rule(com.avaloq.tools.ddk.xtext.format.format.Rule) BadLocationException(org.eclipse.jface.text.BadLocationException) IModification(org.eclipse.xtext.ui.editor.model.edit.IModification) Fix(org.eclipse.xtext.ui.editor.quickfix.Fix)

Example 5 with IModification

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);
                }
            });
        }
    }
}
Also used : IModificationContext(org.eclipse.xtext.ui.editor.model.edit.IModificationContext) BadLocationException(org.eclipse.jface.text.BadLocationException) IModification(org.eclipse.xtext.ui.editor.model.edit.IModification) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) Fix(org.eclipse.xtext.ui.editor.quickfix.Fix)

Aggregations

IModification (org.eclipse.xtext.ui.editor.model.edit.IModification)25 IModificationContext (org.eclipse.xtext.ui.editor.model.edit.IModificationContext)23 Fix (org.eclipse.xtext.ui.editor.quickfix.Fix)16 BadLocationException (org.eclipse.jface.text.BadLocationException)12 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)11 XtextResource (org.eclipse.xtext.resource.XtextResource)7 CoreException (org.eclipse.core.runtime.CoreException)5 EObject (org.eclipse.emf.ecore.EObject)5 WizardDialog (org.eclipse.jface.wizard.WizardDialog)5 IUnitOfWork (org.eclipse.xtext.util.concurrent.IUnitOfWork)5 IOException (java.io.IOException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 List (java.util.List)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 WrappedException (org.eclipse.emf.common.util.WrappedException)3 INode (org.eclipse.xtext.nodemodel.INode)3 Rule (com.avaloq.tools.ddk.xtext.format.format.Rule)2 Map (java.util.Map)2 Set (java.util.Set)2 IFile (org.eclipse.core.resources.IFile)2