Search in sources :

Example 6 with IModification

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

the class CreateXtendTypeQuickfixes method newXtendInterfaceQuickfix.

protected void newXtendInterfaceQuickfix(final String typeName, final String explicitPackage, final XtextResource resource, Issue issue, IssueResolutionAcceptor issueResolutionAcceptor) {
    String packageDescription = getPackageDescription(explicitPackage);
    issueResolutionAcceptor.accept(issue, "Create Xtend interface '" + typeName + "'" + packageDescription, "Opens the new Xtend interface 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 newXtendInterfaceWizard = newXtendInterfaceWizardProvider.get();
                    WizardDialog dialog = createWizardDialog(newXtendInterfaceWizard);
                    NewXtendInterfaceWizardPage page = (NewXtendInterfaceWizardPage) newXtendInterfaceWizard.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) NewXtendInterfaceWizardPage(org.eclipse.xtend.ide.wizards.NewXtendInterfaceWizardPage) WizardDialog(org.eclipse.jface.wizard.WizardDialog) IModification(org.eclipse.xtext.ui.editor.model.edit.IModification)

Example 7 with IModification

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

the class CreateXtendTypeQuickfixes method newXtendClassQuickfix.

protected void newXtendClassQuickfix(final String typeName, final String explicitPackage, final XtextResource resource, Issue issue, IssueResolutionAcceptor issueResolutionAcceptor) {
    String packageDescription = getPackageDescription(explicitPackage);
    issueResolutionAcceptor.accept(issue, "Create Xtend class '" + typeName + "'" + packageDescription, "Opens the new Xtend class 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 newXtendClassWizard = newXtendClassWizardProvider.get();
                    WizardDialog dialog = createWizardDialog(newXtendClassWizard);
                    NewXtendClassWizardPage page = (NewXtendClassWizardPage) newXtendClassWizard.getStartingPage();
                    configureWizardPage(page, resource.getURI(), typeName, explicitPackage);
                    dialog.open();
                }
            });
        }
    });
}
Also used : NewElementWizard(org.eclipse.jdt.internal.ui.wizards.NewElementWizard) NewXtendClassWizardPage(org.eclipse.xtend.ide.wizards.NewXtendClassWizardPage) IModificationContext(org.eclipse.xtext.ui.editor.model.edit.IModificationContext) WizardDialog(org.eclipse.jface.wizard.WizardDialog) IModification(org.eclipse.xtext.ui.editor.model.edit.IModification)

Example 8 with IModification

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

the class DomainmodelQuickfixProvider method fixTypeName.

@Fix(IssueCodes.INVALID_TYPE_NAME)
public void fixTypeName(final Issue issue, final IssueResolutionAcceptor acceptor) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("Capitalize name  of \'");
    String _get = issue.getData()[0];
    _builder.append(_get);
    _builder.append("\'");
    final IModification _function = (IModificationContext context) -> {
        IXtextDocument xtextDocument = context.getXtextDocument();
        String firstLetter = xtextDocument.get((issue.getOffset()).intValue(), 1);
        xtextDocument.replace((issue.getOffset()).intValue(), 1, Strings.toFirstUpper(firstLetter));
    };
    acceptor.accept(issue, "Capitalize name", _builder.toString(), "upcase.png", _function);
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) 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 9 with IModification

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

the class XbaseQuickfixProvider method fixTypeArguments.

@Fix(IssueCodes.INVALID_TYPE_ARGUMENTS_ON_TYPE_LITERAL)
public void fixTypeArguments(final Issue issue, IssueResolutionAcceptor acceptor) {
    String message = issue.getMessage();
    String fixup = "Remove invalid type arguments";
    if (message.contains("argument.")) {
        fixup = "Remove invalid type argument";
    }
    acceptor.accept(issue, fixup, fixup, null, new IModification() {

        @Override
        public void apply(IModificationContext context) throws Exception {
            IXtextDocument document = context.getXtextDocument();
            document.replace(issue.getOffset(), issue.getLength(), "");
        }
    });
}
Also used : IModificationContext(org.eclipse.xtext.ui.editor.model.edit.IModificationContext) WrappedException(org.eclipse.emf.common.util.WrappedException) 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 10 with IModification

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

the class XbaseQuickfixProvider method fixEqualsWithNull.

@Fix(IssueCodes.EQUALS_WITH_NULL)
public void fixEqualsWithNull(final Issue issue, IssueResolutionAcceptor acceptor) {
    String[] data = issue.getData();
    if (data == null || data.length == 0) {
        return;
    }
    String operator = data[0];
    String message = "Replace '" + operator + "' with '" + operator + "='";
    acceptor.accept(issue, message, message, null, new IModification() {

        @Override
        public void apply(IModificationContext context) throws Exception {
            IXtextDocument document = context.getXtextDocument();
            document.replace(issue.getOffset(), issue.getLength(), operator + "=");
        }
    });
}
Also used : IModificationContext(org.eclipse.xtext.ui.editor.model.edit.IModificationContext) WrappedException(org.eclipse.emf.common.util.WrappedException) 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