Search in sources :

Example 1 with SpecificationElement

use of org.yakindu.sct.model.sgraph.SpecificationElement in project statecharts by Yakindu.

the class STextTaskFinder method findTasks.

public List<Task> findTasks(StextResource resource) {
    TaskTags taskTags = taskTagProvider.getTaskTags(resource);
    List<Task> result = Lists.newArrayList();
    TreeIterator<EObject> allContents = resource.getAllContents();
    while (allContents.hasNext()) {
        EObject eObject = (EObject) allContents.next();
        if (eObject instanceof SpecificationElement) {
            List<Task> parseTasks = parseTasks(eObject, SGraphPackage.Literals.SPECIFICATION_ELEMENT__SPECIFICATION, taskTags);
            result.addAll(parseTasks);
        }
        if (eObject instanceof DocumentedElement) {
            result.addAll(parseTasks(eObject, BasePackage.Literals.DOCUMENTED_ELEMENT__DOCUMENTATION, taskTags));
        }
    }
    return result;
}
Also used : DocumentedElement(org.yakindu.base.base.DocumentedElement) SCTTask(org.yakindu.sct.model.stext.tasks.SCTTask) Task(org.eclipse.xtext.tasks.Task) SpecificationElement(org.yakindu.sct.model.sgraph.SpecificationElement) EObject(org.eclipse.emf.ecore.EObject) TaskTags(org.eclipse.xtext.tasks.TaskTags)

Example 2 with SpecificationElement

use of org.yakindu.sct.model.sgraph.SpecificationElement 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 3 with SpecificationElement

use of org.yakindu.sct.model.sgraph.SpecificationElement in project statecharts by Yakindu.

the class AbstractSCTResource method attachedHelper.

@Override
protected void attachedHelper(EObject eObject) {
    super.attachedHelper(eObject);
    if (eObject instanceof SpecificationElement) {
        Adapter parseAdapter = EcoreUtil.getExistingAdapter(eObject, ParseAdapter.class);
        if (parseAdapter == null) {
            parseSpecificationElement((SpecificationElement) eObject);
            linkSpecificationElement((SpecificationElement) eObject);
            eObject.eAdapters().add(new ParseAdapter());
        }
        Adapter serializeAdapter = EcoreUtil.getExistingAdapter(eObject, SerializeAdapter.class);
        if (serializeAdapter == null) {
            eObject.eAdapters().add(new SerializeAdapter());
        }
    }
}
Also used : SpecificationElement(org.yakindu.sct.model.sgraph.SpecificationElement) EContentAdapter(org.eclipse.emf.ecore.util.EContentAdapter) Adapter(org.eclipse.emf.common.notify.Adapter)

Example 4 with SpecificationElement

use of org.yakindu.sct.model.sgraph.SpecificationElement in project statecharts by Yakindu.

the class AbstractSCTResource method createDiagnostic.

protected void createDiagnostic(Triple<EObject, EReference, INode> triple) {
    SpecificationElement specificationElement = EcoreUtil2.getContainerOfType(triple.getFirst(), SpecificationElement.class);
    DiagnosticMessage message = createDiagnosticMessage(triple);
    Diagnostic diagnostic = new XtextLinkingDiagnostic(triple.getThird(), message.getMessage(), message.getIssueCode(), message.getIssueData());
    linkingDiagnostics.put(specificationElement, diagnostic);
}
Also used : XtextLinkingDiagnostic(org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic) DiagnosticMessage(org.eclipse.xtext.diagnostics.DiagnosticMessage) SpecificationElement(org.yakindu.sct.model.sgraph.SpecificationElement) XtextLinkingDiagnostic(org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic) XtextSyntaxDiagnostic(org.eclipse.xtext.resource.XtextSyntaxDiagnostic)

Example 5 with SpecificationElement

use of org.yakindu.sct.model.sgraph.SpecificationElement in project statecharts by Yakindu.

the class STextScopeProvider method getActiveStateNormalizer.

protected List<ImportNormalizer> getActiveStateNormalizer(EObject context) {
    List<ImportNormalizer> normalizer = Lists.newArrayList();
    SpecificationElement contextElement = getContextElement(context);
    if (contextElement == null)
        return normalizer;
    Region containingRegion = EcoreUtil2.getContainerOfType(contextElement, Region.class);
    if (containingRegion == null)
        return normalizer;
    QualifiedName fullyQualifiedName = nameProvider.getFullyQualifiedName(containingRegion);
    while (!fullyQualifiedName.getSegments().isEmpty()) {
        normalizer.add(new ImportNormalizer(fullyQualifiedName, true, false));
        fullyQualifiedName = fullyQualifiedName.skipLast(1);
    }
    return normalizer;
}
Also used : ImportNormalizer(org.eclipse.xtext.scoping.impl.ImportNormalizer) SpecificationElement(org.yakindu.sct.model.sgraph.SpecificationElement) QualifiedName(org.eclipse.xtext.naming.QualifiedName) Region(org.yakindu.sct.model.sgraph.Region)

Aggregations

SpecificationElement (org.yakindu.sct.model.sgraph.SpecificationElement)6 Adapter (org.eclipse.emf.common.notify.Adapter)2 EObject (org.eclipse.emf.ecore.EObject)2 EContentAdapter (org.eclipse.emf.ecore.util.EContentAdapter)2 StringReader (java.io.StringReader)1 Diagnostic (org.eclipse.emf.ecore.resource.Resource.Diagnostic)1 ParserRule (org.eclipse.xtext.ParserRule)1 DiagnosticMessage (org.eclipse.xtext.diagnostics.DiagnosticMessage)1 XtextLinkingDiagnostic (org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic)1 QualifiedName (org.eclipse.xtext.naming.QualifiedName)1 INode (org.eclipse.xtext.nodemodel.INode)1 IParseResult (org.eclipse.xtext.parser.IParseResult)1 XtextSyntaxDiagnostic (org.eclipse.xtext.resource.XtextSyntaxDiagnostic)1 ListBasedDiagnosticConsumer (org.eclipse.xtext.resource.impl.ListBasedDiagnosticConsumer)1 ImportNormalizer (org.eclipse.xtext.scoping.impl.ImportNormalizer)1 Task (org.eclipse.xtext.tasks.Task)1 TaskTags (org.eclipse.xtext.tasks.TaskTags)1 DocumentedElement (org.yakindu.base.base.DocumentedElement)1 Region (org.yakindu.sct.model.sgraph.Region)1 Statechart (org.yakindu.sct.model.sgraph.Statechart)1