Java Code Examples for org.eclipse.xtext.ParserRule#setName()

The following examples show how to use org.eclipse.xtext.ParserRule#setName() . 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: DefaultEObjectLabelProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testGetStyledTextFallbackText() throws Exception {
	DefaultEObjectLabelProvider defaultLabelProvider = new DefaultEObjectLabelProvider();
	ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
	parserRule.setName("testCreateStyledString");
	StyledString styledText = defaultLabelProvider.getStyledText(parserRule);
	assertEquals("testCreateStyledString", styledText.getString());
}
 
Example 2
Source File: AbstractTextEditComposerTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testProtocol() throws Exception {
	Resource res = getResource(newTestGrammar());
	assertNull(composer.endRecording());
	composer.beginRecording(res);
	assertNull(composer.endRecording());
	assertNull(composer.endRecording());
	composer.beginRecording(res);
	Grammar grammar = (Grammar) res.getContents().get(0);
	ParserRule rule = (ParserRule) grammar.getRules().get(0);
	rule.setName("Bar");
	assertNotNull(composer.endRecording());
	assertNull(composer.endRecording());
}
 
Example 3
Source File: ParseErrorHandlingTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testExpectNoSuchMethodException() throws Exception {
	IParser parser = get(IParser.class);
	ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
	parserRule.setName("ruleDoesNotExist");
	try {
		parser.parse(parserRule, new StringReader("empty"));
		fail("Expected WrappedException");
	} catch(ParseException e) {
		assertTrue(e.getCause() instanceof WrappedException);
		WrappedException cause = (WrappedException) e.getCause();
		assertTrue(cause.getCause() instanceof NoSuchMethodException);
	}
}
 
Example 4
Source File: AbstractSGenTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected EObject parseExpression(String expression, String ruleName) {
	XtextResource resource = resourceProvider.get();
	resource.setURI(URI.createPlatformPluginURI("path", true));
	ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
	parserRule.setName(ruleName);
	IParseResult result = parser.parse(parserRule, new StringReader(
			expression));
	EObject rootASTElement = result.getRootASTElement();
	resource.getContents().add(rootASTElement);
	ListBasedDiagnosticConsumer diagnosticsConsumer = new ListBasedDiagnosticConsumer();
	linker.linkModel(result.getRootASTElement(), diagnosticsConsumer);
	if (result.hasSyntaxErrors()) {
		StringBuilder errorMessages = new StringBuilder();
		Iterable<INode> syntaxErrors = result.getSyntaxErrors();
		for (INode iNode : syntaxErrors) {
			errorMessages.append(iNode.getSyntaxErrorMessage());
			errorMessages.append("\n");
		}
		throw new RuntimeException(
				"Could not parse expression, syntax errors: "
						+ errorMessages);
	}
	if (diagnosticsConsumer.hasConsumedDiagnostics(Severity.ERROR)) {
		throw new RuntimeException("Error during linking: "
				+ diagnosticsConsumer.getResult(Severity.ERROR));
	}
	return rootASTElement;
}
 
Example 5
Source File: STextExpressionParser.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public EObject parseExpression(String expression, String ruleName, String specification) {
	StextResource resource = getResource();
	resource.setURI(URI.createPlatformResourceURI(getUri(), true));
	ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
	parserRule.setName(ruleName);
	IParseResult result = parser.parse(parserRule, new StringReader(expression));
	EObject rootASTElement = result.getRootASTElement();
	resource.getContents().add(rootASTElement);
	ListBasedDiagnosticConsumer diagnosticsConsumer = new ListBasedDiagnosticConsumer();
	Statechart sc = SGraphFactory.eINSTANCE.createStatechart();
	sc.setDomainID(domainId);
	sc.setName("sc");
	if (specification != null) {
		sc.setSpecification(specification);
	}
	resource.getContents().add(sc);
	resource.getLinkingDiagnostics().clear();
	linker.linkModel(sc, diagnosticsConsumer);
	linker.linkModel(rootASTElement, diagnosticsConsumer);
	resource.resolveLazyCrossReferences(CancelIndicator.NullImpl);
	resource.resolveLazyCrossReferences(CancelIndicator.NullImpl);
	Multimap<SpecificationElement, Diagnostic> diagnostics = resource.getLinkingDiagnostics();
	if (diagnostics.size() > 0) {
		throw new LinkingException(diagnostics.toString());
	}
	if (result.hasSyntaxErrors()) {
		StringBuilder errorMessages = new StringBuilder();
		Iterable<INode> syntaxErrors = result.getSyntaxErrors();
		for (INode iNode : syntaxErrors) {
			errorMessages.append(iNode.getSyntaxErrorMessage());
			errorMessages.append("\n");
		}
		throw new SyntaxException("Could not parse expression, syntax errors: " + errorMessages);
	}
	if (diagnosticsConsumer.hasConsumedDiagnostics(Severity.ERROR)) {
		throw new LinkingException("Error during linking: " + diagnosticsConsumer.getResult(Severity.ERROR));
	}
	return rootASTElement;
}
 
Example 6
Source File: AbstractSCTResource.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected IParseResult parse(SpecificationElement element, String rule) {
	ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
	parserRule.setName(rule);
	String specification = element.getSpecification();
	IParseResult result = parser.parse(parserRule, new StringReader(specification != null ? specification : ""));
	createDiagnostics(result, element);
	return result;
}
 
Example 7
Source File: STextExpressionParser.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
public Scope createInternalScope(String contextScope) {
	ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
	parserRule.setName(InternalScope.class.getSimpleName());
	IParseResult result = parser.parse(parserRule, new StringReader(contextScope));
	return (Scope) result.getRootASTElement();
}
 
Example 8
Source File: STextExpressionParser.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
public Scope createInterfaceScope(String contextScope) {
	ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
	parserRule.setName(InterfaceScope.class.getSimpleName());
	IParseResult result = parser.parse(parserRule, new StringReader(contextScope));
	return (Scope) result.getRootASTElement();
}