Search in sources :

Example 21 with Fix

use of org.eclipse.xtext.ui.editor.quickfix.Fix in project xtext-eclipse by eclipse.

the class StatemachineQuickfixProvider method capitalizeName.

@Fix(StatemachineValidator.INVALID_NAME)
public void capitalizeName(final Issue issue, final IssueResolutionAcceptor acceptor) {
    String _firstLower = StringExtensions.toFirstLower(IterableExtensions.<String>head(((Iterable<String>) Conversions.doWrapArray(issue.getData()))));
    String _plus = ("Change to \'" + _firstLower);
    String _plus_1 = (_plus + "\'.");
    String _firstLower_1 = StringExtensions.toFirstLower(IterableExtensions.<String>head(((Iterable<String>) Conversions.doWrapArray(issue.getData()))));
    String _plus_2 = ("Change to \'" + _firstLower_1);
    String _plus_3 = (_plus_2 + "\'.");
    final IModification _function = (IModificationContext it) -> {
        final String firstLetter = it.getXtextDocument().get((issue.getOffset()).intValue(), 1);
        it.getXtextDocument().replace((issue.getOffset()).intValue(), 1, firstLetter.toLowerCase());
    };
    acceptor.accept(issue, _plus_1, _plus_3, "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 22 with Fix

use of org.eclipse.xtext.ui.editor.quickfix.Fix 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 23 with Fix

use of org.eclipse.xtext.ui.editor.quickfix.Fix in project dsl-devkit by dsldevkit.

the class DefaultCheckQuickfixProvider method getFixMethodPredicate.

/**
 * Returns a method predicate indicating whether a given method is an executable quickfix method. Both Check
 * quickfix methods and native quickfix methods are considered.
 *
 * @param issueCode
 *          the issue code
 * @return the fix method predicate
 * @see com.avaloq.tools.ddk.check.runtime.quickfix.CoreFix CoreFix annotation
 * @see org.eclipse.xtext.ui.editor.quickfix.Fix Fix annotation
 */
@Override
protected Predicate<Method> getFixMethodPredicate(final String issueCode) {
    return new Predicate<Method>() {

        @Override
        public boolean apply(final Method input) {
            CoreFix coreFixAnnotation = input.getAnnotation(CoreFix.class);
            Fix fixAnnotation = input.getAnnotation(Fix.class);
            if (coreFixAnnotation == null && fixAnnotation == null) {
                // Definitely no candidate
                return false;
            }
            final boolean typesMatch = Void.TYPE == input.getReturnType() && input.getParameterTypes().length == 2 && input.getParameterTypes()[0].isAssignableFrom(Issue.class);
            boolean result;
            if (coreFixAnnotation != null) {
                result = coreFixAnnotation != null && issueCode.equals(coreFixAnnotation.value()) && typesMatch && input.getParameterTypes()[1].isAssignableFrom(CoreIssueResolutionAcceptor.class);
            } else {
                result = fixAnnotation != null && issueCode.equals(fixAnnotation.value()) && typesMatch && input.getParameterTypes()[1].isAssignableFrom(IssueResolutionAcceptor.class);
            }
            return result;
        }
    };
}
Also used : Issue(org.eclipse.xtext.validation.Issue) CoreFix(com.avaloq.tools.ddk.check.runtime.quickfix.CoreFix) Fix(org.eclipse.xtext.ui.editor.quickfix.Fix) CoreFix(com.avaloq.tools.ddk.check.runtime.quickfix.CoreFix) Method(java.lang.reflect.Method) Predicate(com.google.common.base.Predicate)

Example 24 with Fix

use of org.eclipse.xtext.ui.editor.quickfix.Fix 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 25 with Fix

use of org.eclipse.xtext.ui.editor.quickfix.Fix 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)

Aggregations

Fix (org.eclipse.xtext.ui.editor.quickfix.Fix)43 IModificationContext (org.eclipse.xtext.ui.editor.model.edit.IModificationContext)35 BadLocationException (org.eclipse.jface.text.BadLocationException)29 EObject (org.eclipse.emf.ecore.EObject)25 ISemanticModification (org.eclipse.xtext.ui.editor.model.edit.ISemanticModification)18 IModification (org.eclipse.xtext.ui.editor.model.edit.IModification)17 CoreException (org.eclipse.core.runtime.CoreException)16 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)16 XtextResource (org.eclipse.xtext.resource.XtextResource)13 List (java.util.List)9 WrappedException (org.eclipse.emf.common.util.WrappedException)9 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)9 ReplacingAppendable (org.eclipse.xtext.xbase.ui.contentassist.ReplacingAppendable)7 ArrayList (java.util.ArrayList)5 EList (org.eclipse.emf.common.util.EList)5 URI (org.eclipse.emf.common.util.URI)5 INode (org.eclipse.xtext.nodemodel.INode)5 IOException (java.io.IOException)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 ITextRegion (org.eclipse.xtext.util.ITextRegion)4