use of org.eclipse.xtext.util.concurrent.IUnitOfWork in project xtext-eclipse by eclipse.
the class XtextGrammarRefactoringIntegrationTest method checkConsistenceOfGrammar.
private void checkConsistenceOfGrammar(XtextEditor editor) {
waitForBuild();
assertEquals(REFACTOREDCLASSIFIERNAME, editor.getDocument().readOnly(new IUnitOfWork<String, XtextResource>() {
@Override
public String exec(XtextResource state) throws Exception {
String renamedRuleFragment = greetingParserRuleUri.fragment().replaceFirst(CLASSIFIERNAME, REFACTOREDCLASSIFIERNAME);
EObject renamedRule = state.getEObject(renamedRuleFragment);
assertNotNull(renamedRule);
return SimpleAttributeResolver.NAME_RESOLVER.apply(renamedRule);
}
}));
editor.getDocument().readOnly(new IUnitOfWork<Boolean, XtextResource>() {
@Override
public Boolean exec(XtextResource state) throws Exception {
AbstractRule rule = ((RuleCall) ((Assignment) ((ParserRule) state.getEObject(modelParserRuleUri.fragment())).getAlternatives()).getTerminal()).getRule();
assertFalse(rule.eIsProxy());
assertEquals(REFACTOREDCLASSIFIERNAME, rule.getName());
return true;
}
});
}
use of org.eclipse.xtext.util.concurrent.IUnitOfWork in project xtext-eclipse by eclipse.
the class XtextElementLinksTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
modelAsText = "stuff mystuff\nstuff yourstuff";
IFile file = IResourcesSetupUtil.createFile("test/test.testlanguage", modelAsText);
editor = openEditor(file);
document = editor.getDocument();
elementLinks = TestsActivator.getInstance().getInjector(getEditorId()).getInstance(XtextElementLinks.class);
f = document.readOnly(new IUnitOfWork<File, XtextResource>() {
@Override
public File exec(XtextResource state) throws Exception {
return (File) state.getContents().get(0);
}
});
}
use of org.eclipse.xtext.util.concurrent.IUnitOfWork in project xtext-eclipse by eclipse.
the class OutlineNodeTest method testStateAccess.
@Test
public void testStateAccess() {
DocumentRootNode rootNode = createRootNode();
EObjectNode parentNode = new EObjectNode(parentElement, rootNode, (ImageDescriptor) null, "parent", false);
EStructuralFeatureNode featureNode = new EStructuralFeatureNode(parentElement, OutlineTestPackage.Literals.ELEMENT__XREFS, parentNode, (ImageDescriptor) null, "eClassifiers", true);
IUnitOfWork<Boolean, EObject> work = new IUnitOfWork<Boolean, EObject>() {
@Override
public Boolean exec(EObject state) throws Exception {
return state != null;
}
};
assertTrue(rootNode.readOnly(work));
assertTrue(parentNode.readOnly(work));
assertTrue(featureNode.readOnly(work));
}
use of org.eclipse.xtext.util.concurrent.IUnitOfWork in project xtext-eclipse by eclipse.
the class XbaseQuickfixProvider method fixObsoletCast.
@Fix(IssueCodes.OBSOLETE_CAST)
public void fixObsoletCast(final Issue issue, IssueResolutionAcceptor acceptor) {
String fixup = "Remove unnecessary cast";
acceptor.accept(issue, fixup, fixup, null, new IModification() {
@Override
public void apply(IModificationContext context) throws Exception {
final IXtextDocument document = context.getXtextDocument();
ReplaceRegion replacement = document.tryReadOnly(new IUnitOfWork<ReplaceRegion, XtextResource>() {
@Override
public ReplaceRegion exec(XtextResource state) throws Exception {
EObject type = state.getEObject(issue.getUriToProblem().fragment());
XCastedExpression cast = EcoreUtil2.getContainerOfType(type, XCastedExpression.class);
INode castNode = NodeModelUtils.findActualNodeFor(cast);
INode targetNode = NodeModelUtils.findActualNodeFor(cast.getTarget());
return new ReplaceRegion(castNode.getTotalTextRegion(), targetNode.getText());
}
});
if (replacement != null) {
document.replace(replacement.getOffset(), replacement.getLength(), replacement.getText());
}
}
});
}
Aggregations