Search in sources :

Example 1 with StextResource

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;
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) INode(org.eclipse.xtext.nodemodel.INode) StextResource(org.yakindu.sct.model.stext.resource.StextResource) SpecificationElement(org.yakindu.sct.model.sgraph.SpecificationElement) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) EObject(org.eclipse.emf.ecore.EObject) StringReader(java.io.StringReader) ListBasedDiagnosticConsumer(org.eclipse.xtext.resource.impl.ListBasedDiagnosticConsumer) Statechart(org.yakindu.sct.model.sgraph.Statechart) IParseResult(org.eclipse.xtext.parser.IParseResult)

Example 2 with StextResource

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);
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) StextResource(org.yakindu.sct.model.stext.resource.StextResource) Injector(com.google.inject.Injector) IContextElementProvider(org.yakindu.sct.model.sgraph.util.ContextElementAdapter.IContextElementProvider) ContextElementAdapter(org.yakindu.sct.model.sgraph.util.ContextElementAdapter) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Before(org.junit.Before)

Example 3 with StextResource

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);
}
Also used : StextResource(org.yakindu.sct.model.stext.resource.StextResource) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) STextJavaValidator(org.yakindu.sct.model.stext.validation.STextJavaValidator) Before(org.junit.Before)

Example 4 with StextResource

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;
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) StextResource(org.yakindu.sct.model.stext.resource.StextResource) EObject(org.eclipse.emf.ecore.EObject) ContextElementAdapter(org.yakindu.sct.model.sgraph.util.ContextElementAdapter) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet)

Aggregations

StextResource (org.yakindu.sct.model.stext.resource.StextResource)4 EObject (org.eclipse.emf.ecore.EObject)2 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)2 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)2 Before (org.junit.Before)2 ContextElementAdapter (org.yakindu.sct.model.sgraph.util.ContextElementAdapter)2 Injector (com.google.inject.Injector)1 StringReader (java.io.StringReader)1 BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)1 Diagnostic (org.eclipse.emf.ecore.resource.Resource.Diagnostic)1 ParserRule (org.eclipse.xtext.ParserRule)1 INode (org.eclipse.xtext.nodemodel.INode)1 IParseResult (org.eclipse.xtext.parser.IParseResult)1 ListBasedDiagnosticConsumer (org.eclipse.xtext.resource.impl.ListBasedDiagnosticConsumer)1 SpecificationElement (org.yakindu.sct.model.sgraph.SpecificationElement)1 Statechart (org.yakindu.sct.model.sgraph.Statechart)1 IContextElementProvider (org.yakindu.sct.model.sgraph.util.ContextElementAdapter.IContextElementProvider)1 STextJavaValidator (org.yakindu.sct.model.stext.validation.STextJavaValidator)1