Search in sources :

Example 1 with StatechartSpecification

use of org.yakindu.sct.model.stext.stext.StatechartSpecification in project statecharts by Yakindu.

the class STextProposalProvider method completeKeyword.

/**
 * Validates if a keyword should be viewed by the proposal view.
 *
 * Builds dependent on the ContentAssistContext a list with keywords which
 * shouldn't be displayed by the proposal view.
 */
@Override
public void completeKeyword(Keyword keyword, ContentAssistContext contentAssistContext, ICompletionProposalAcceptor acceptor) {
    List<Keyword> suppressKeywords = new ArrayList<Keyword>();
    EObject rootModel = contentAssistContext.getRootModel();
    if (rootModel instanceof TransitionSpecification) {
        suppressKeywords(suppressKeywords, (TransitionSpecification) rootModel);
    } else if (rootModel instanceof SimpleScope) {
        suppressKeywords(suppressKeywords, (SimpleScope) rootModel);
    } else if (rootModel instanceof StatechartSpecification) {
        suppressKeywords(suppressKeywords, (StatechartSpecification) rootModel);
    }
    EObject currentModel = contentAssistContext.getCurrentModel();
    if (currentModel instanceof InterfaceScope) {
        suppressKeywords(suppressKeywords, (InterfaceScope) currentModel);
    }
    if (currentModel instanceof FeatureCall) {
        suppressKeywords(suppressKeywords, (FeatureCall) currentModel);
    }
    if (currentModel instanceof ElementReferenceExpression) {
        suppressKeywords(suppressKeywords, (ElementReferenceExpression) currentModel);
    }
    if (currentModel instanceof InternalScope) {
        suppressKeywords(suppressKeywords, (InternalScope) currentModel);
    }
    if (!suppressKeywords.contains(keyword)) {
        super.completeKeyword(keyword, contentAssistContext, new AcceptorDelegate(acceptor));
    }
}
Also used : Keyword(org.eclipse.xtext.Keyword) SimpleScope(org.yakindu.sct.model.stext.stext.SimpleScope) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) InternalScope(org.yakindu.sct.model.stext.stext.InternalScope) TransitionSpecification(org.yakindu.sct.model.stext.stext.TransitionSpecification) StatechartSpecification(org.yakindu.sct.model.stext.stext.StatechartSpecification) InterfaceScope(org.yakindu.sct.model.stext.stext.InterfaceScope) FeatureCall(org.yakindu.base.expressions.expressions.FeatureCall) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression)

Example 2 with StatechartSpecification

use of org.yakindu.sct.model.stext.stext.StatechartSpecification in project statecharts by Yakindu.

the class StextResource method parseStatechart.

protected void parseStatechart(Statechart statechart) {
    IParseResult parseResult = parse(statechart, StatechartSpecification.class.getSimpleName());
    StatechartSpecification rootASTElement = (StatechartSpecification) parseResult.getRootASTElement();
    statechart.setNamespace(rootASTElement.getNamespace());
    statechart.getScopes().clear();
    EList<Scope> definitionScopes = rootASTElement.getScopes();
    if (definitionScopes != null) {
        statechart.getScopes().addAll(definitionScopes);
    }
    statechart.getAnnotations().clear();
    EList<ArgumentedAnnotation> annotations = rootASTElement.getAnnotations();
    if (annotations != null) {
        statechart.getAnnotations().addAll(annotations);
    }
}
Also used : Scope(org.yakindu.sct.model.sgraph.Scope) StatechartSpecification(org.yakindu.sct.model.stext.stext.StatechartSpecification) ArgumentedAnnotation(org.yakindu.sct.model.stext.stext.ArgumentedAnnotation) IParseResult(org.eclipse.xtext.parser.IParseResult)

Example 3 with StatechartSpecification

use of org.yakindu.sct.model.stext.stext.StatechartSpecification in project statecharts by Yakindu.

the class STextJavaValidatorTest method checkAnnotations.

@Test
public void checkAnnotations() {
    String scope;
    StatechartSpecification model;
    AssertableDiagnostics validationResult;
    statechart.setName("Annotated");
    scope = "@EventDriven";
    model = (StatechartSpecification) super.parseExpression(scope, StatechartSpecification.class.getSimpleName());
    statechart.getAnnotations().addAll(model.getAnnotations());
    validationResult = tester.validate(statechart);
    validationResult.assertOK();
    scope = "@CycleBased(200)";
    model = (StatechartSpecification) super.parseExpression(scope, StatechartSpecification.class.getSimpleName());
    statechart.getAnnotations().clear();
    statechart.getAnnotations().addAll(model.getAnnotations());
    validationResult = tester.validate(statechart);
    validationResult.assertOK();
    scope = "@CycleBased(200)\n" + "@EventDriven";
    model = (StatechartSpecification) super.parseExpression(scope, StatechartSpecification.class.getSimpleName());
    statechart.getAnnotations().clear();
    statechart.getAnnotations().addAll(model.getAnnotations());
    validationResult = tester.validate(statechart);
    validationResult.assertErrorContains(CONTRADICTORY_ANNOTATIONS.split("%s")[0]);
    scope = "@ParentFirstExecution";
    model = (StatechartSpecification) super.parseExpression(scope, StatechartSpecification.class.getSimpleName());
    statechart.getAnnotations().clear();
    statechart.getAnnotations().addAll(model.getAnnotations());
    validationResult = tester.validate(statechart);
    validationResult.assertOK();
    scope = "@ChildFirstExecution";
    model = (StatechartSpecification) super.parseExpression(scope, StatechartSpecification.class.getSimpleName());
    statechart.getAnnotations().clear();
    statechart.getAnnotations().addAll(model.getAnnotations());
    validationResult = tester.validate(statechart);
    validationResult.assertOK();
    scope = "@ParentFirstExecution\n" + "@ChildFirstExecution";
    model = (StatechartSpecification) super.parseExpression(scope, StatechartSpecification.class.getSimpleName());
    statechart.getAnnotations().clear();
    statechart.getAnnotations().addAll(model.getAnnotations());
    validationResult = tester.validate(statechart);
    validationResult.assertErrorContains(CONTRADICTORY_ANNOTATIONS.split("%s")[0]);
}
Also used : AssertableDiagnostics(org.eclipse.xtext.junit4.validation.AssertableDiagnostics) StatechartSpecification(org.yakindu.sct.model.stext.stext.StatechartSpecification) Test(org.junit.Test)

Example 4 with StatechartSpecification

use of org.yakindu.sct.model.stext.stext.StatechartSpecification in project statecharts by Yakindu.

the class StatechartRootImpl method basicSetDef.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetDef(StatechartSpecification newDef, NotificationChain msgs) {
    StatechartSpecification oldDef = def;
    def = newDef;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, StextPackage.STATECHART_ROOT__DEF, oldDef, newDef);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) StatechartSpecification(org.yakindu.sct.model.stext.stext.StatechartSpecification)

Aggregations

StatechartSpecification (org.yakindu.sct.model.stext.stext.StatechartSpecification)4 ArrayList (java.util.ArrayList)1 EObject (org.eclipse.emf.ecore.EObject)1 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)1 Keyword (org.eclipse.xtext.Keyword)1 AssertableDiagnostics (org.eclipse.xtext.junit4.validation.AssertableDiagnostics)1 IParseResult (org.eclipse.xtext.parser.IParseResult)1 Test (org.junit.Test)1 ElementReferenceExpression (org.yakindu.base.expressions.expressions.ElementReferenceExpression)1 FeatureCall (org.yakindu.base.expressions.expressions.FeatureCall)1 Scope (org.yakindu.sct.model.sgraph.Scope)1 ArgumentedAnnotation (org.yakindu.sct.model.stext.stext.ArgumentedAnnotation)1 InterfaceScope (org.yakindu.sct.model.stext.stext.InterfaceScope)1 InternalScope (org.yakindu.sct.model.stext.stext.InternalScope)1 SimpleScope (org.yakindu.sct.model.stext.stext.SimpleScope)1 TransitionSpecification (org.yakindu.sct.model.stext.stext.TransitionSpecification)1