Search in sources :

Example 1 with ReplaceModification

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

the class XbaseQuickfixProvider method fixAmbiguousMethodCall.

@Fix(IssueCodes.AMBIGUOUS_FEATURE_CALL)
public void fixAmbiguousMethodCall(final Issue issue, IssueResolutionAcceptor acceptor) {
    String[] data = issue.getData();
    if (data == null || data.length == 0) {
        return;
    }
    for (String replacement : data) {
        String replaceLabel = "Change to '" + replacement + "'";
        acceptor.accept(issue, replaceLabel, replaceLabel, null, new ReplaceModification(issue, replacement));
    }
}
Also used : ReplaceModification(org.eclipse.xtext.ui.editor.quickfix.ReplaceModification) Fix(org.eclipse.xtext.ui.editor.quickfix.Fix)

Example 2 with ReplaceModification

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

the class JavaTypeQuickfixes method createResolution.

protected void createResolution(Issue issue, IssueResolutionAcceptor issueResolutionAcceptor, String issueString, IEObjectDescription solution) {
    String replacement = qualifiedNameConverter.toString(solution.getName());
    String replaceLabel = "Change to '" + replacement + "'";
    issueResolutionAcceptor.accept(issue, replaceLabel, replaceLabel, null, new ReplaceModification(issue, replacement));
}
Also used : ReplaceModification(org.eclipse.xtext.ui.editor.quickfix.ReplaceModification)

Example 3 with ReplaceModification

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

the class XbaseQuickfixProvider method fixRedundantCase.

@Fix(IssueCodes.REDUNDANT_CASE)
public void fixRedundantCase(final Issue issue, IssueResolutionAcceptor acceptor) {
    acceptor.accept(issue, "Remove redundant case.", "Remove redundant case.", null, new ReplaceModification(issue, ""));
    acceptor.accept(issue, "Assign empty expression.", "Assign empty expression.", null, new ISemanticModification() {

        @Override
        public void apply(EObject element, IModificationContext context) throws Exception {
            XSwitchExpression switchExpression = EcoreUtil2.getContainerOfType(element, XSwitchExpression.class);
            if (switchExpression == null) {
                return;
            }
            XCasePart casePart = IterableExtensions.last(switchExpression.getCases());
            if (casePart == null || !(casePart.isFallThrough() && casePart.getThen() == null)) {
                return;
            }
            List<INode> nodes = NodeModelUtils.findNodesForFeature(casePart, XbasePackage.Literals.XCASE_PART__FALL_THROUGH);
            if (nodes.isEmpty()) {
                return;
            }
            INode firstNode = IterableExtensions.head(nodes);
            INode lastNode = IterableExtensions.last(nodes);
            int offset = firstNode.getOffset();
            int length = lastNode.getEndOffset() - offset;
            ReplacingAppendable appendable = appendableFactory.create(context.getXtextDocument(), (XtextResource) element.eResource(), offset, length);
            appendable.append(": {");
            appendable.increaseIndentation().newLine();
            appendable.decreaseIndentation().newLine().append("}");
            appendable.commitChanges();
        }
    });
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) ReplaceModification(org.eclipse.xtext.ui.editor.quickfix.ReplaceModification) EObject(org.eclipse.emf.ecore.EObject) ISemanticModification(org.eclipse.xtext.ui.editor.model.edit.ISemanticModification) IModificationContext(org.eclipse.xtext.ui.editor.model.edit.IModificationContext) XCasePart(org.eclipse.xtext.xbase.XCasePart) XSwitchExpression(org.eclipse.xtext.xbase.XSwitchExpression) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) XtextResource(org.eclipse.xtext.resource.XtextResource) ReplacingAppendable(org.eclipse.xtext.xbase.ui.contentassist.ReplacingAppendable) WrappedException(org.eclipse.emf.common.util.WrappedException) BadLocationException(org.eclipse.jface.text.BadLocationException) Fix(org.eclipse.xtext.ui.editor.quickfix.Fix)

Aggregations

ReplaceModification (org.eclipse.xtext.ui.editor.quickfix.ReplaceModification)3 Fix (org.eclipse.xtext.ui.editor.quickfix.Fix)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 EList (org.eclipse.emf.common.util.EList)1 WrappedException (org.eclipse.emf.common.util.WrappedException)1 EObject (org.eclipse.emf.ecore.EObject)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 INode (org.eclipse.xtext.nodemodel.INode)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 IModificationContext (org.eclipse.xtext.ui.editor.model.edit.IModificationContext)1 ISemanticModification (org.eclipse.xtext.ui.editor.model.edit.ISemanticModification)1 XCasePart (org.eclipse.xtext.xbase.XCasePart)1 XSwitchExpression (org.eclipse.xtext.xbase.XSwitchExpression)1 ReplacingAppendable (org.eclipse.xtext.xbase.ui.contentassist.ReplacingAppendable)1