use of org.yakindu.sct.model.stext.resource.StextResource in project statecharts by Yakindu.
the class STextExpressionParser method parseExpression.
public EObject parseExpression(String expression, String ruleName, String specification) {
StextResource resource = getResource();
resource.setURI(URI.createURI(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;
}
use of org.yakindu.sct.model.stext.resource.StextResource in project statecharts by Yakindu.
the class SCTResourceTest method setUp.
@Before
public void setUp() throws Exception {
Injector injector = STextActivator.getInstance().getInjector(STextActivator.ORG_YAKINDU_SCT_MODEL_STEXT_STEXT);
ResourceSet resourceSet = new ResourceSetImpl();
res = new StextResource(URI.createURI("test.test"));
res.eAdapters().add(new ContextElementAdapter(new IContextElementProvider() {
public EObject getContextObject() {
return res.getContents().get(0);
}
}));
resourceSet.getResources().add(res);
injector.injectMembers(res);
}
use of org.yakindu.sct.model.stext.resource.StextResource in project statecharts by Yakindu.
the class AbstractSTextValidationTest method setup.
@Before
public void setup() {
factory = SGraphFactory.eINSTANCE;
resource = new StextResource(URI.createURI(""));
injector.injectMembers(resource);
statechart = factory.createStatechart();
resource.getContents().add(statechart);
diagnostics = new BasicDiagnostic();
tester = new ValidatorTester<STextJavaValidator>(validator, injector);
}
use of org.yakindu.sct.model.stext.resource.StextResource in project statecharts by Yakindu.
the class STextExpressionParser method getResource.
public StextResource getResource() {
final StextResource resource = new StextResource();
injector.injectMembers(resource);
resource.eAdapters().add(new ContextElementAdapter(new ContextElementAdapter.IContextElementProvider() {
public EObject getContextObject() {
return (EObject) EcoreUtil.getObjectByType(resource.getContents(), SGraphPackage.Literals.STATECHART);
}
}));
ResourceSet set = new ResourceSetImpl();
set.getResources().add(resource);
return resource;
}
Aggregations