Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 44856ab8edcfe693d2e81a3c0435059165683831 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
 * generated by Xtext
 */
package org.eclipse.etrice.core.fsm.ui.quickfix;

import com.google.inject.Inject;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.etrice.core.common.converter.BaseConverterService;
import org.eclipse.etrice.core.common.converter.CCStringConverter;
import org.eclipse.etrice.core.fsm.fSM.DetailCode;
import org.eclipse.etrice.core.fsm.validation.FSMJavaValidator;
import org.eclipse.xtext.formatting.ILineSeparatorInformation;
import org.eclipse.xtext.formatting.IWhitespaceInformationProvider;
import org.eclipse.xtext.nodemodel.ICompositeNode;
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
import org.eclipse.xtext.ui.editor.model.IXtextDocument;
import org.eclipse.xtext.ui.editor.model.edit.IModificationContext;
import org.eclipse.xtext.ui.editor.model.edit.ISemanticModification;
import org.eclipse.xtext.ui.editor.quickfix.DefaultQuickfixProvider;
import org.eclipse.xtext.ui.editor.quickfix.Fix;
import org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor;
import org.eclipse.xtext.validation.Issue;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;

/**
 * Custom quickfixes.
 * 
 * see http://www.eclipse.org/Xtext/documentation.html#quickfixes
 */
@SuppressWarnings("all")
public class FSMQuickfixProvider extends DefaultQuickfixProvider {
  @Inject
  private BaseConverterService converterService;
  
  @Inject
  private IWhitespaceInformationProvider whitespaceProvider;
  
  @Fix(FSMJavaValidator.PLAIN_STRING_DETAILCODE)
  public void fixMultiLineDetailCode(final Issue issue, final IssueResolutionAcceptor acceptor) {
    final ISemanticModification _function = (EObject element, IModificationContext context) -> {
      final Procedure1<DetailCode> _function_1 = (DetailCode it) -> {
        EList<String> _lines = it.getLines();
        Resource _eResource = it.eResource();
        URI _uRI = _eResource.getURI();
        ILineSeparatorInformation _lineSeparatorInformation = this.whitespaceProvider.getLineSeparatorInformation(_uRI);
        String _lineSeparator = _lineSeparatorInformation.getLineSeparator();
        final String ccString = IterableExtensions.join(_lines, _lineSeparator);
        ICompositeNode _findActualNodeFor = NodeModelUtils.findActualNodeFor(it);
        final Procedure1<ICompositeNode> _function_2 = (ICompositeNode it_1) -> {
          try {
            IXtextDocument _xtextDocument = context.getXtextDocument();
            int _offset = it_1.getOffset();
            int _length = it_1.getLength();
            CCStringConverter _cC_StringConverter = this.converterService.getCC_StringConverter();
            String _addDelim = _cC_StringConverter.addDelim(ccString);
            _xtextDocument.replace(_offset, _length, _addDelim);
          } catch (Throwable _e) {
            throw Exceptions.sneakyThrow(_e);
          }
        };
        ObjectExtensions.<ICompositeNode>operator_doubleArrow(_findActualNodeFor, _function_2);
      };
      ObjectExtensions.<DetailCode>operator_doubleArrow(
        ((DetailCode) element), _function_1);
    };
    acceptor.accept(issue, "Convert to smart string", "", "correction_change.gif", _function);
  }
}

Back to the top