Search in sources :

Example 1 with IReferableElementsUnloader

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());
}
Also used : IReferableElementsUnloader(org.eclipse.xtext.parser.antlr.IReferableElementsUnloader) EObject(org.eclipse.emf.ecore.EObject) Test(org.junit.Test)

Example 2 with IReferableElementsUnloader

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());
}
Also used : IReferableElementsUnloader(org.eclipse.xtext.parser.antlr.IReferableElementsUnloader) ReplaceRegion(org.eclipse.xtext.util.ReplaceRegion) EObject(org.eclipse.emf.ecore.EObject) PartialParsingPointers(org.eclipse.xtext.parser.impl.PartialParsingPointers)

Example 3 with IReferableElementsUnloader

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());
}
Also used : IReferableElementsUnloader(org.eclipse.xtext.parser.antlr.IReferableElementsUnloader) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) XtextResource(org.eclipse.xtext.resource.XtextResource) InternalEObject(org.eclipse.emf.ecore.InternalEObject)

Example 4 with IReferableElementsUnloader

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);
}
Also used : IReferableElementsUnloader(org.eclipse.xtext.parser.antlr.IReferableElementsUnloader) ReplaceRegion(org.eclipse.xtext.util.ReplaceRegion) EObject(org.eclipse.emf.ecore.EObject) IParseResult(org.eclipse.xtext.parser.IParseResult) PartialParsingPointers(org.eclipse.xtext.parser.impl.PartialParsingPointers)

Aggregations

EObject (org.eclipse.emf.ecore.EObject)4 IReferableElementsUnloader (org.eclipse.xtext.parser.antlr.IReferableElementsUnloader)4 PartialParsingPointers (org.eclipse.xtext.parser.impl.PartialParsingPointers)2 ReplaceRegion (org.eclipse.xtext.util.ReplaceRegion)2 InternalEObject (org.eclipse.emf.ecore.InternalEObject)1 IParseResult (org.eclipse.xtext.parser.IParseResult)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 Test (org.junit.Test)1