use of org.eclipse.xtext.linking.lazy.LazyLinkingResource in project xtext-xtend by eclipse.
the class AbstractSmokeTest method testSkipNodesInBetween.
@Test
public void testSkipNodesInBetween() throws Exception {
for (String string : smokeTestModels) {
LazyLinkingResource resource = createResource(string);
ICompositeNode rootNode = resource.getParseResult().getRootNode();
ReplaceRegion replaceRegion = null;
for (INode node : rootNode.getAsTreeIterable()) {
int offset = node.getTotalOffset();
int length = node.getTotalLength();
if (replaceRegion == null || replaceRegion.getOffset() != offset || replaceRegion.getLength() != length) {
replaceRegion = new ReplaceRegion(offset, length, "");
StringBuilder builder = new StringBuilder(string);
replaceRegion.applyTo(builder);
doParseAndCheckForSmoke(builder.toString());
}
}
}
}
use of org.eclipse.xtext.linking.lazy.LazyLinkingResource in project xtext-xtend by eclipse.
the class AbstractSmokeTest method createResource.
protected LazyLinkingResource createResource(final String model) throws IOException {
if (logger.isTraceEnabled()) {
logger.trace("createResource: " + model);
}
XtextResourceSet set = getResourceSet();
typeProviderFactory.findOrCreateTypeProvider(set);
LazyLinkingResource resource = (LazyLinkingResource) resourceFactory.createResource(URI.createURI("Test.xtend"));
set.getResources().add(resource);
resource.load(new StringInputStream(model), null);
resource.resolveLazyCrossReferences(CancelIndicator.NullImpl);
return resource;
}
use of org.eclipse.xtext.linking.lazy.LazyLinkingResource in project xtext-xtend by eclipse.
the class SmokeTest method compareWithNewResource.
protected void compareWithNewResource(LazyLinkingResource resource, int offset, int length, String newText) throws IOException {
String model = resource.getParseResult().getRootNode().getText();
try {
long start = System.currentTimeMillis();
long time = System.currentTimeMillis();
if (logger.isDebugEnabled()) {
logger.debug("Partial parsing ...");
logger.trace("Input is >>>" + resource.getParseResult().getRootNode().getText() + "<<<");
logger.trace("Offset: " + offset);
logger.trace("Length: " + length);
logger.trace("New Text: >>>" + newText + "<<<");
}
resource.update(offset, length, newText);
resource.resolveLazyCrossReferences(CancelIndicator.NullImpl);
String text = resource.getParseResult().getRootNode().getText();
if (logger.isDebugEnabled()) {
logger.debug("... took " + (System.currentTimeMillis() - time));
logger.debug("Loading second resource ...");
time = System.currentTimeMillis();
}
LazyLinkingResource newResource = createResource(text);
if (logger.isDebugEnabled()) {
logger.debug("... took " + (System.currentTimeMillis() - time));
logger.debug("Semantic equality check ...");
time = System.currentTimeMillis();
}
assertEquals(text, resource.getContents().size(), newResource.getContents().size());
EcoreUtil.resolveAll(resource);
EcoreUtil.resolveAll(newResource);
for (int i = 0; i < resource.getContents().size(); i++) {
assertEquals(text, EmfFormatter.objToStr(newResource.getContents().get(i)), EmfFormatter.objToStr(resource.getContents().get(i)));
}
if (logger.isDebugEnabled()) {
logger.debug("... took " + (System.currentTimeMillis() - time));
logger.debug("Node equality check ...");
time = System.currentTimeMillis();
}
ICompositeNode rootNode = resource.getParseResult().getRootNode();
ICompositeNode newRootNode = newResource.getParseResult().getRootNode();
Iterator<INode> iterator = rootNode.getAsTreeIterable().iterator();
Iterator<INode> newIterator = newRootNode.getAsTreeIterable().iterator();
while (iterator.hasNext()) {
assertTrue(newIterator.hasNext());
assertEqualNodes(text, iterator.next(), newIterator.next());
}
assertFalse(iterator.hasNext());
assertFalse(newIterator.hasNext());
if (logger.isDebugEnabled()) {
logger.debug("... took " + (System.currentTimeMillis() - time));
logger.debug("... done - total time: " + (System.currentTimeMillis() - start));
}
} catch (Throwable e) {
e.printStackTrace();
String failureMessage = e.getMessage() + " : Model was >>>\n" + model + "\n<<<\n" + "offset: " + offset + "\n" + "length:" + length + "\n" + "newText: >>>" + newText + "<<<";
assertEquals(failureMessage, model, "");
// just to make sure we fail for empty model, too
fail(failureMessage);
}
}
use of org.eclipse.xtext.linking.lazy.LazyLinkingResource in project xtext-core by eclipse.
the class AbstractSmokeTest method testSkipNodesInBetween.
@Test
public void testSkipNodesInBetween() throws Exception {
for (String string : getSmokeTestModels()) {
LazyLinkingResource resource = createResource(string);
if (resource != null) {
ICompositeNode rootNode = resource.getParseResult().getRootNode();
ReplaceRegion replaceRegion = null;
for (INode node : rootNode.getAsTreeIterable()) {
int offset = node.getTotalOffset();
int length = node.getTotalLength();
if (replaceRegion == null || replaceRegion.getOffset() != offset || replaceRegion.getLength() != length) {
replaceRegion = new ReplaceRegion(offset, length, "");
StringBuilder builder = new StringBuilder(string);
replaceRegion.applyTo(builder);
processModel(builder.toString());
}
}
}
}
}
use of org.eclipse.xtext.linking.lazy.LazyLinkingResource in project xtext-core by eclipse.
the class AbstractSmokeTest method testSkipNodesInBetweenWithoutResourceSet.
@Test
public void testSkipNodesInBetweenWithoutResourceSet() throws Exception {
for (String string : getSmokeTestModels()) {
LazyLinkingResource resource = createResource(string);
if (resource != null) {
ICompositeNode rootNode = resource.getParseResult().getRootNode();
ReplaceRegion replaceRegion = null;
for (INode node : rootNode.getAsTreeIterable()) {
int offset = node.getTotalOffset();
int length = node.getTotalLength();
if (replaceRegion == null || replaceRegion.getOffset() != offset || replaceRegion.getLength() != length) {
replaceRegion = new ReplaceRegion(offset, length, "");
StringBuilder builder = new StringBuilder(string);
replaceRegion.applyTo(builder);
processModelWithoutResourceSet(builder.toString());
}
}
}
}
}
Aggregations