use of org.eclipse.xtext.ui.tests.quickfix.quickfixCrossref.Element in project xtext-eclipse by eclipse.
the class QuickfixCrossrefTestLanguageQuickfixProvider method fixBadNames.
@SuppressWarnings("unchecked")
@Fix(QuickfixCrossrefTestLanguageValidator.BAD_NAME_IN_SUBELEMENTS)
public void fixBadNames(final Issue issue, IssueResolutionAcceptor acceptor) {
acceptor.acceptMulti(issue, "Fix Bad Names", "Fix Bad Names", null, (Element main, ICompositeModificationContext<Element> ctx) -> {
ctx.addModification(main.eContainer(), c -> {
List<Element> siblings = (List<Element>) main.eContainer().eGet(main.eContainmentFeature());
int index = siblings.indexOf(main);
Element newEle = QuickfixCrossrefFactory.eINSTANCE.createElement();
newEle.setName("newElement");
siblings.add(index, newEle);
});
for (String s : issue.getData()[0].split(";")) {
EObject ele = main.eResource().getEObject(s);
Assert.assertTrue(ele instanceof Element);
ctx.addModification((Element) ele, e -> {
e.setName("goodname");
});
}
});
}
use of org.eclipse.xtext.ui.tests.quickfix.quickfixCrossref.Element in project xtext-eclipse by eclipse.
the class LinkingErrorTest method testSemanticIssueResolution.
@Test
public void testSemanticIssueResolution() throws Exception {
xtextEditor = newXtextEditor(PROJECT_NAME, MODEL_FILE, MODEL_WITH_LINKING_ERROR);
URI uriToProblem = xtextEditor.getDocument().readOnly(new IUnitOfWork<URI, XtextResource>() {
@Override
public URI exec(XtextResource state) throws Exception {
Main main = (Main) state.getContents().get(0);
Element element = main.getElements().get(1);
return EcoreUtil.getURI(element);
}
});
Issue.IssueImpl issue = new Issue.IssueImpl();
issue.setUriToProblem(uriToProblem);
issue.setCode(QuickfixCrossrefTestLanguageQuickfixProvider.SEMANTIC_FIX_ID);
IssueResolutionProvider quickfixProvider = getInjector().getInstance(IssueResolutionProvider.class);
List<IssueResolution> resolutions = quickfixProvider.getResolutions(issue);
assertEquals(1, resolutions.size());
IssueResolution issueResolution = resolutions.get(0);
issueResolution.apply();
xtextEditor.doSave(null);
List<Issue> issues = getIssues(xtextEditor.getDocument());
assertTrue(issues.isEmpty());
}
use of org.eclipse.xtext.ui.tests.quickfix.quickfixCrossref.Element in project xtext-eclipse by eclipse.
the class QuickfixCrossrefTestLanguageSemanticSequencer method sequence.
@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
EPackage epackage = semanticObject.eClass().getEPackage();
ParserRule rule = context.getParserRule();
Action action = context.getAssignedAction();
Set<Parameter> parameters = context.getEnabledBooleanParameters();
if (epackage == QuickfixCrossrefPackage.eINSTANCE)
switch(semanticObject.eClass().getClassifierID()) {
case QuickfixCrossrefPackage.ELEMENT:
sequence_Element(context, (Element) semanticObject);
return;
case QuickfixCrossrefPackage.MAIN:
sequence_Main(context, (Main) semanticObject);
return;
}
if (errorAcceptor != null)
errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Aggregations