Search in sources :

Example 16 with IModification

use of org.eclipse.xtext.ui.editor.model.edit.IModification in project xtext-eclipse by eclipse.

the class XtextGrammarQuickfixProvider method fixInvalidMetaModelName.

@Fix(INVALID_METAMODEL_NAME)
public void fixInvalidMetaModelName(final Issue issue, IssueResolutionAcceptor acceptor) {
    final String metaModelName = issue.getData()[0];
    acceptor.accept(issue, "Fix metamodel name '" + metaModelName + "'", "Fix metamodel name '" + metaModelName + "'", NULL_QUICKFIX_IMAGE, new IModification() {

        @Override
        public void apply(IModificationContext context) throws Exception {
            context.getXtextDocument().replace(issue.getOffset(), issue.getLength(), Strings.toFirstLower(metaModelName));
        }
    });
}
Also used : IModificationContext(org.eclipse.xtext.ui.editor.model.edit.IModificationContext) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) BadLocationException(org.eclipse.jface.text.BadLocationException) IOException(java.io.IOException) IModification(org.eclipse.xtext.ui.editor.model.edit.IModification) Fix(org.eclipse.xtext.ui.editor.quickfix.Fix)

Example 17 with IModification

use of org.eclipse.xtext.ui.editor.model.edit.IModification in project xtext-eclipse by eclipse.

the class ArithmeticsQuickfixProvider method normalize.

@Fix(ArithmeticsValidator.NORMALIZABLE)
public void normalize(final Issue issue, final IssueResolutionAcceptor acceptor) {
    final String string = issue.getData()[0];
    final IModification _function = (IModificationContext it) -> {
        it.getXtextDocument().replace((issue.getOffset()).intValue(), (issue.getLength()).intValue(), string);
    };
    acceptor.accept(issue, ("Replace with " + string), (("Replace expression with \'" + string) + "\'"), "upcase.png", _function);
}
Also used : IModificationContext(org.eclipse.xtext.ui.editor.model.edit.IModificationContext) IModification(org.eclipse.xtext.ui.editor.model.edit.IModification) Fix(org.eclipse.xtext.ui.editor.quickfix.Fix)

Example 18 with IModification

use of org.eclipse.xtext.ui.editor.model.edit.IModification in project dsl-devkit by dsldevkit.

the class CheckQuickfixProvider method fixIllegalDefaultSeverity.

/**
 * Fixes an illegally set default severity. The default severity must be within given severity range.
 *
 * @param issue
 *          the issue
 * @param acceptor
 *          the acceptor
 */
@Fix(IssueCodes.DEFAULT_SEVERITY_NOT_IN_RANGE)
public void fixIllegalDefaultSeverity(final Issue issue, final IssueResolutionAcceptor acceptor) {
    if (issue.getData() != null) {
        for (final String severityProposal : issue.getData()) {
            final String label = NLS.bind(Messages.CheckQuickfixProvider_DEFAULT_SEVERITY_FIX_LABEL, severityProposal);
            final String descn = NLS.bind(Messages.CheckQuickfixProvider_DEFAULT_SEVERITY_FIX_DESCN, severityProposal);
            acceptor.accept(issue, label, descn, NO_IMAGE, new IModification() {

                @Override
                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)

Example 19 with IModification

use of org.eclipse.xtext.ui.editor.model.edit.IModification in project dsl-devkit by dsldevkit.

the class FormatQuickfixProvider method setOverride.

/**
 * Semantic quickfix setting the override flag for a rule.
 *
 * @param issue
 *          the issue
 * @param acceptor
 *          the acceptor
 */
@Fix(FormatJavaValidator.OVERRIDE_MISSING_CODE)
public void setOverride(final Issue issue, final IssueResolutionAcceptor acceptor) {
    acceptor.accept(issue, "Set override", "Set override flag.", 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(true);
                    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 20 with IModification

use of org.eclipse.xtext.ui.editor.model.edit.IModification in project xtext-xtend by eclipse.

the class CreateXtendTypeQuickfixes method newXtendAnnotationQuickfix.

protected void newXtendAnnotationQuickfix(final String typeName, final String explicitPackage, final XtextResource resource, Issue issue, IssueResolutionAcceptor issueResolutionAcceptor) {
    String packageDescription = getPackageDescription(explicitPackage);
    issueResolutionAcceptor.accept(issue, "Create Xtend annotation '" + typeName + "'" + packageDescription, "Opens the new Xtend annotation wizard to create the type '" + typeName + "'" + packageDescription, "xtend_file.png", new IModification() {

        @Override
        public void apply(/* @Nullable */
        IModificationContext context) throws Exception {
            runAsyncInDisplayThread(new Runnable() {

                @Override
                public void run() {
                    NewElementWizard newXtendAnnotationWizard = newXtendAnnotationWizardProvider.get();
                    WizardDialog dialog = createWizardDialog(newXtendAnnotationWizard);
                    NewXtendAnnotationWizardPage page = (NewXtendAnnotationWizardPage) newXtendAnnotationWizard.getStartingPage();
                    configureWizardPage(page, resource.getURI(), typeName, explicitPackage);
                    dialog.open();
                }
            });
        }
    });
}
Also used : NewElementWizard(org.eclipse.jdt.internal.ui.wizards.NewElementWizard) IModificationContext(org.eclipse.xtext.ui.editor.model.edit.IModificationContext) NewXtendAnnotationWizardPage(org.eclipse.xtend.ide.wizards.NewXtendAnnotationWizardPage) WizardDialog(org.eclipse.jface.wizard.WizardDialog) IModification(org.eclipse.xtext.ui.editor.model.edit.IModification)

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