org.eclipse.xtext.nodemodel.impl.InvariantChecker Java Examples

The following examples show how to use org.eclipse.xtext.nodemodel.impl.InvariantChecker. 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: Bug480686Test.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testAllGrammarElementsUnique() throws Exception {
	ContentAssistFragmentTestLanguageRoot result = parseHelper.parse("newArrayList()");
	XtextResource res = (XtextResource) result.eResource();
	ICompositeNode root = res.getParseResult().getRootNode();
	new InvariantChecker().checkInvariant(root);
	Set<EObject> set = new HashSet<>();
	for (INode node : root.getAsTreeIterable()) {
		if (node instanceof ICompositeNode) {
			ICompositeNode compositeNode = (ICompositeNode) node;
			if (compositeNode.getGrammarElement() != null) {
				Assert.assertTrue(compositeNode.getGrammarElement().toString(),
						set.add(compositeNode.getGrammarElement()));
			} else {
				Assert.fail("node without grammar element");
			}
		}
	}
}
 
Example #2
Source File: ParserTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test 
public void testAllGrammarElementsUnique() throws Exception {
	XtendClass clazz = clazz("class Foo { def m() { newArrayList() } }");
	XtextResource resource = (XtextResource) clazz.eResource();
	ICompositeNode root = resource.getParseResult().getRootNode();
	new InvariantChecker().checkInvariant(root);
	assertSame(root, root.getRootNode());
	Set<EObject> grammarElements = Sets.newHashSet();
	for(INode node: root.getAsTreeIterable()) {
		if (node instanceof ICompositeNode) {
			if (node.getGrammarElement() == null) {
				fail("node without grammar element");
			}
			if (!grammarElements.add(node.getGrammarElement())) {
				fail(node.getGrammarElement().toString());
			}
		}
	}
}
 
Example #3
Source File: OffsetInformationTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testCheckParsing() throws Exception {
	String string = "spielplatz 34 'holla' {\n"
		+ "  kind (Horst 3)\n"
		+ "  erwachsener (Julia 45)\n"
		+ "  erwachsener (Herrmann 50)\n" 
		+ "  erwachsener (Herrmann 50)\n" 
		+ "  erwachsener (Herrmann 50)\n" 
		+ "  erwachsener (Herrmann 50)\n" 
		+ "  erwachsener (Herrmann 50)\n" 
		+ "}";
	XtextResource resource = getResource(new StringInputStream(string));
	ICompositeNode rootNode = resource.getParseResult().getRootNode();
	
	for (int i=0;i<string.length()/2;i++) {
		String substring = string.substring(i, string.length()-i);
		resource.update(i, substring.length(), substring);
		ICompositeNode model = resource.getParseResult().getRootNode();
		new InvariantChecker().checkInvariant(model);
		assertSameStructure(rootNode, model);
	}
	
}
 
Example #4
Source File: Bug480686Test.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testUpdateTwice() throws Exception {
	ContentAssistFragmentTestLanguageRoot result = parseHelper.parse("");
	XtextResource res = (XtextResource) result.eResource();
	new InvariantChecker().checkInvariant(res.getParseResult().getRootNode());
	res.update(0, 0, "newArrayList()");
	EObject first = Iterables.getFirst(res.getContents(), null);
	Assert.assertTrue(first.eClass().getName(), first instanceof ContentAssistFragmentTestLanguageRoot);
	res.update("newArrayList(".length(), 0, "1");
	EObject second = Iterables.getFirst(res.getContents(), null);
	Assert.assertTrue(second.eClass().getName(), second instanceof ContentAssistFragmentTestLanguageRoot);
}
 
Example #5
Source File: Bug480686Test.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testBrokenInput_01() throws Exception {
	ContentAssistFragmentTestLanguageRoot result = parseHelper.parse("}");
	XtextResource res = (XtextResource) result.eResource();
	InvariantChecker invariantChecker = new InvariantChecker();
	invariantChecker.checkInvariant(res.getParseResult().getRootNode());
	res.update(0, 0, "newArrayList()");
	invariantChecker.checkInvariant(res.getParseResult().getRootNode());
	EObject first = Iterables.getFirst(res.getContents(), null);
	Assert.assertTrue(first.eClass().getName(), first instanceof ContentAssistFragmentTestLanguageRoot);
	res.update("newArrayList(".length(), 0, "1");
	invariantChecker.checkInvariant(res.getParseResult().getRootNode());
	EObject second = Iterables.getFirst(res.getContents(), null);
	Assert.assertTrue(second.eClass().getName(), second instanceof ContentAssistFragmentTestLanguageRoot);
}
 
Example #6
Source File: Bug480686Test.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testBrokenInput_02() throws Exception {
	ContentAssistFragmentTestLanguageRoot result = parseHelper.parse("}} abc");
	XtextResource res = (XtextResource) result.eResource();
	InvariantChecker invariantChecker = new InvariantChecker();
	invariantChecker.checkInvariant(res.getParseResult().getRootNode());
	res.update(0, 0, "newArrayList()");
	invariantChecker.checkInvariant(res.getParseResult().getRootNode());
	EObject first = Iterables.getFirst(res.getContents(), null);
	Assert.assertTrue(first.eClass().getName(), first instanceof ContentAssistFragmentTestLanguageRoot);
	res.update("newArrayList(".length(), 0, "1");
	invariantChecker.checkInvariant(res.getParseResult().getRootNode());
	EObject second = Iterables.getFirst(res.getContents(), null);
	Assert.assertTrue(second.eClass().getName(), second instanceof ContentAssistFragmentTestLanguageRoot);
}
 
Example #7
Source File: PartialParsingProcessor.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private void assertEqual(String data, String newData, ICompositeNode fromScratch, ICompositeNode reparsed) {
	InvariantChecker checker = new InvariantChecker();
	checker.checkInvariant(reparsed);
	Iterator<INode> scratchIterator = fromScratch.getAsTreeIterable().iterator();
	Iterator<INode> reparsedIterator = reparsed.getAsTreeIterable().iterator();
	while(scratchIterator.hasNext()) {
		Assert.assertTrue(reparsedIterator.hasNext());
		assertEqualNodes(data, newData, scratchIterator.next(), reparsedIterator.next());
	}
	Assert.assertFalse(scratchIterator.hasNext());
	Assert.assertFalse(reparsedIterator.hasNext());
}
 
Example #8
Source File: PartialParsingProcessor.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private void assertEqual(String data, String newData, ICompositeNode fromScratch, ICompositeNode reparsed) {
	InvariantChecker checker = new InvariantChecker();
	checker.checkInvariant(reparsed);
	Iterator<INode> scratchIterator = fromScratch.getAsTreeIterable().iterator();
	Iterator<INode> reparsedIterator = reparsed.getAsTreeIterable().iterator();
	while(scratchIterator.hasNext()) {
		Assert.assertTrue(reparsedIterator.hasNext());
		assertEqualNodes(data, newData, scratchIterator.next(), reparsedIterator.next());
	}
	Assert.assertFalse(scratchIterator.hasNext());
	Assert.assertFalse(reparsedIterator.hasNext());
}
 
Example #9
Source File: AbstractXtextTests.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected InvariantChecker getInvariantChecker(){
	return getInjector().getInstance(InvariantChecker.class);
}
 
Example #10
Source File: AbstractXtextTests.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected InvariantChecker getInvariantChecker(){
	return getInjector().getInstance(InvariantChecker.class);
}
 
Example #11
Source File: ParseHelper.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @since 2.22
 */
protected InvariantChecker getInvariantChecker() {
	return invariantChecker;
}
 
Example #12
Source File: AbstractXtextTests.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected InvariantChecker getInvariantChecker(){
	return getInjector().getInstance(InvariantChecker.class);
}