Java Code Examples for org.eclipse.xtext.nodemodel.util.NodeModelUtils#compactDump()

The following examples show how to use org.eclipse.xtext.nodemodel.util.NodeModelUtils#compactDump() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SetEntryPointOnXtextResourceTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void test1() throws Exception {
	with(ReferenceGrammarTestLanguageStandaloneSetup.class);
	String model = "kind (Hugo 13)";
	ParserRule kindRule = get(ReferenceGrammarTestLanguageGrammarAccess.class).getKindRule();
	XtextResource resource = createResource();
	// test 1: parse and assume there are no errors
	resource.setEntryPoint(kindRule);
	resource.load(new StringInputStream(model), Collections.emptyMap());
	Assert.assertTrue(resource.getErrors().isEmpty());
	Assert.assertEquals(kindRule, NodeModelUtils.getEntryParserRule(resource.getParseResult().getRootNode()));
	// test 2: update and assume node model does not change
	String originalNodeModel = NodeModelUtils.compactDump(resource.getParseResult().getRootNode(), false);
	resource.update(0, model.length(), " " + model + " ");
	String reparsedNodeModel = NodeModelUtils.compactDump(resource.getParseResult().getRootNode(), false);
	Assert.assertEquals(originalNodeModel, reparsedNodeModel);
	// test 3: change parser rule
	ParserRule erwachsenerRule = get(ReferenceGrammarTestLanguageGrammarAccess.class).getErwachsenerRule();
	resource.setEntryPoint(erwachsenerRule);
	resource.update(0, model.length(), "erwachsener (Peter 30)");
	Assert.assertEquals(erwachsenerRule,
			NodeModelUtils.getEntryParserRule(resource.getParseResult().getRootNode()));
}
 
Example 2
Source File: PartialParserTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private void checkFullReparse(ParserRule rule, String model) {
	IParseResult oldParseResult = getParser().parse(rule, new StringReader(model));
	IParseResult partialParseResult = reparse(oldParseResult, 0, model.length(), " " + model + " ");
	String oldNodeModel = NodeModelUtils.compactDump(oldParseResult.getRootNode(), false);
	String partialNodeModel = NodeModelUtils.compactDump(partialParseResult.getRootNode(), false);
	assertEquals(oldNodeModel, partialNodeModel);
}