-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestSuiteQuickfixProvider.java
66 lines (59 loc) · 2.28 KB
/
TestSuiteQuickfixProvider.java
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
/*
* generated by Xtext 2.22.0
*/
package xtext.http.rest.ui.quickfix;
import java.util.Arrays;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.xtext.EcoreUtil2;
import org.eclipse.xtext.ui.editor.model.IXtextDocument;
import org.eclipse.xtext.ui.editor.model.edit.IModification;
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 xtext.http.rest.testSuite.Assertion;
import xtext.http.rest.testSuite.StatusCodeAssertion;
import xtext.http.rest.validation.TestSuiteValidator;
/**
* Custom quickfixes.
*
* See https://www.eclipse.org/Xtext/documentation/310_eclipse_support.html#quick-fixes
*/
public class TestSuiteQuickfixProvider extends DefaultQuickfixProvider {
@Fix(TestSuiteValidator.NOT_UNIQUE)
public void renameName(final Issue issue, IssueResolutionAcceptor acceptor) {
acceptor.accept(issue,
"Rename name", // label
"Rename name", // description
"upcase.png", // icon
new ISemanticModification() {
@Override
public void apply(EObject element, IModificationContext context) throws Exception {
IXtextDocument xtextDocument = context.getXtextDocument();
String name = xtextDocument.get(issue.getOffset(), issue.getLength());
xtextDocument.replace(issue.getOffset(), issue.getLength(), name + "_new");
}
}
);
}
@Fix(TestSuiteValidator.NR_OF_STATUS_CODE_ASSERTIONS)
@Fix(TestSuiteValidator.NR_OF_BODY_ASSERTIONS)
@Fix(TestSuiteValidator.NR_OF_TEXT_ASSERTIONS)
public void deleteAssertion(final Issue issue, IssueResolutionAcceptor acceptor) {
acceptor.accept(issue,
"Remove assertion", // label
"Remove assertion", // description
"upcase.png", // icon
new ISemanticModification() {
@Override
public void apply(EObject element, IModificationContext context) throws Exception {
IXtextDocument xtextDocument = context.getXtextDocument();
xtextDocument.replace(issue.getOffset(), issue.getLength(), "");
}
}
);
}
}