use of org.eclipse.xtext.parser.antlr.IReferableElementsUnloader in project xtext-core by eclipse.
the class XtextResourceTest method testUnloadReferables.
@Test
public void testUnloadReferables() throws Exception {
resource.reparse(simpleModel);
final Wrapper<Boolean> unloaded = Wrapper.wrap(Boolean.FALSE);
resource.setUnloader(new IReferableElementsUnloader() {
@Override
public void unloadRoot(EObject root) {
unloaded.set(Boolean.TRUE);
}
});
resource.reparse(simpleModel);
assertTrue("unloaded", unloaded.get());
}
use of org.eclipse.xtext.parser.antlr.IReferableElementsUnloader in project xtext-core by eclipse.
the class AbstractPartialParserReplaceTest method replaceAndReparse.
protected void replaceAndReparse(String model, int offset, int length, String change, String expectedReparseRegion) throws Exception {
IParseResult parseResult = getParseResult(model);
PartialParsingPointers parsingPointers = getPartialParser().calculatePartialParsingPointers(parseResult, offset, length);
String reparseRegion = getPartialParser().insertChangeIntoReplaceRegion(parsingPointers.getDefaultReplaceRootNode(), new ReplaceRegion(offset, length, change));
assertEquals(expectedReparseRegion, reparseRegion);
final Wrapper<Boolean> unloaded = Wrapper.wrap(Boolean.FALSE);
getPartialParser().setUnloader(new IReferableElementsUnloader() {
@Override
public void unloadRoot(EObject root) {
unloaded.set(Boolean.TRUE);
}
});
IParseResult partiallyReparse = reparse(parseResult, offset, length, change);
assertTrue("unloaded", unloaded.get());
assertFalse(partiallyReparse.getRootNode().getText(), partiallyReparse.hasSyntaxErrors());
String expectedReparseModel = model.substring(0, offset) + change + model.substring(offset + length);
assertEquals(expectedReparseModel, partiallyReparse.getRootNode().getText());
}
use of org.eclipse.xtext.parser.antlr.IReferableElementsUnloader in project xtext-core by eclipse.
the class AbstractPartialParserCrossContainmentTest method replaceAndReparse.
protected void replaceAndReparse(String model, int offset, int length, String inserted, boolean expectSameRoot) throws Exception {
final XtextResource resource = getResourceFromString(model);
resource.setUnloader(new IReferableElementsUnloader() {
@Override
public void unloadRoot(EObject root) {
InternalEObject internalEObject = (InternalEObject) root;
internalEObject.eSetProxyURI(resource.getURI().appendFragment(resource.getURIFragment(internalEObject)));
internalEObject.eAdapters().clear();
}
});
assertEquals(1, resource.getContents().size());
EObject wasObject = resource.getContents().get(0);
assertNotNull(wasObject.eContainer());
assertNotSame(wasObject.eResource(), wasObject.eContainer().eResource());
resource.update(offset, length, inserted);
assertEquals(1, resource.getContents().size());
EObject newRoot = resource.getContents().get(0);
assertEquals(expectSameRoot, wasObject == newRoot);
if (!expectSameRoot) {
assertTrue(((InternalEObject) wasObject).eIsProxy());
assertNotSame(resource, wasObject.eResource());
}
assertSame(resource, newRoot.eResource());
}
use of org.eclipse.xtext.parser.antlr.IReferableElementsUnloader in project xtext-core by eclipse.
the class Bug419429Test method replaceAndReparse.
protected void replaceAndReparse(String model, int offset, int length, String change, String expectedReparseRegion) throws Exception {
IParseResult parseResult = getParseResultAndExpect(model, UNKNOWN_EXPECTATION);
PartialParsingPointers parsingPointers = getPartialParser().calculatePartialParsingPointers(parseResult, offset, length);
String reparseRegion = getPartialParser().insertChangeIntoReplaceRegion(parsingPointers.getDefaultReplaceRootNode(), new ReplaceRegion(offset, length, change));
assertEquals(expectedReparseRegion, reparseRegion);
final Wrapper<Boolean> unloaded = Wrapper.wrap(Boolean.FALSE);
getPartialParser().setUnloader(new IReferableElementsUnloader() {
@Override
public void unloadRoot(EObject root) {
unloaded.set(Boolean.TRUE);
}
});
IParseResult partiallyReparse = reparse(parseResult, offset, length, change);
assertTrue("unloaded", unloaded.get());
String expectedReparseModel = model.substring(0, offset) + change + model.substring(offset + length);
assertEquals(expectedReparseModel, partiallyReparse.getRootNode().getText());
compareWithFullParse(model, offset, length, change);
}
Aggregations