Search in sources :

Example 31 with Expression

use of org.yakindu.base.expressions.expressions.Expression in project statecharts by Yakindu.

the class CheckImpl method basicSetCondition.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetCondition(Expression newCondition, NotificationChain msgs) {
    Expression oldCondition = condition;
    condition = newCondition;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, SexecPackage.CHECK__CONDITION, oldCondition, newCondition);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : Expression(org.yakindu.base.expressions.expressions.Expression) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 32 with Expression

use of org.yakindu.base.expressions.expressions.Expression in project statecharts by Yakindu.

the class FoldOutgoingActionsRefactoring method createExitBlock.

private EList<Expression> createExitBlock(List<Expression> actionsToAdd) {
    EList<Expression> actionsOriginal;
    LocalReaction newLocalReaction = StextFactory.eINSTANCE.createLocalReaction();
    ReactionTrigger newReactionTrigger = StextFactory.eINSTANCE.createReactionTrigger();
    ExitEvent exitEvent = StextFactory.eINSTANCE.createExitEvent();
    ReactionEffect newReactionEffect = StextFactory.eINSTANCE.createReactionEffect();
    newLocalReaction.setTrigger(newReactionTrigger);
    newReactionTrigger.getTriggers().add(exitEvent);
    newReactionEffect.getActions().addAll(actionsToAdd);
    newLocalReaction.setEffect(newReactionEffect);
    Scope scope = getContextObject().getScopes().get(0);
    scope.getReactions().add(newLocalReaction);
    actionsOriginal = newReactionEffect.getActions();
    return actionsOriginal;
}
Also used : LocalReaction(org.yakindu.sct.model.stext.stext.LocalReaction) Scope(org.yakindu.sct.model.sgraph.Scope) Expression(org.yakindu.base.expressions.expressions.Expression) ReactionTrigger(org.yakindu.sct.model.stext.stext.ReactionTrigger) ReactionEffect(org.yakindu.sct.model.stext.stext.ReactionEffect) ExitEvent(org.yakindu.sct.model.stext.stext.ExitEvent)

Example 33 with Expression

use of org.yakindu.base.expressions.expressions.Expression in project statecharts by Yakindu.

the class STextJavaValidator method checkValueDefinitionExpression.

@Check(CheckType.FAST)
public void checkValueDefinitionExpression(VariableDefinition definition) {
    // applies only to constants
    if (!definition.isConst())
        return;
    Expression initialValue = definition.getInitialValue();
    if (initialValue == null) {
        error(CONST_MUST_HAVE_VALUE_MSG, definition, null, CONST_MUST_HAVE_VALUE_CODE);
        return;
    }
    List<Expression> toCheck = Lists.newArrayList(initialValue);
    TreeIterator<EObject> eAllContents = initialValue.eAllContents();
    while (eAllContents.hasNext()) {
        EObject next = eAllContents.next();
        if (next instanceof Expression)
            toCheck.add((Expression) next);
    }
    for (Expression expression : toCheck) {
        EObject referencedObject = null;
        if (expression instanceof FeatureCall)
            referencedObject = ((FeatureCall) expression).getFeature();
        else if (expression instanceof ElementReferenceExpression)
            referencedObject = ((ElementReferenceExpression) expression).getReference();
        if (referencedObject instanceof VariableDefinition) {
            if (!((VariableDefinition) referencedObject).isConst()) {
                error(REFERENCE_TO_VARIABLE, StextPackage.Literals.VARIABLE_DEFINITION__INITIAL_VALUE);
            }
        }
    }
}
Also used : VariableDefinition(org.yakindu.sct.model.stext.stext.VariableDefinition) EventRaisingExpression(org.yakindu.sct.model.stext.stext.EventRaisingExpression) Expression(org.yakindu.base.expressions.expressions.Expression) AssignmentExpression(org.yakindu.base.expressions.expressions.AssignmentExpression) EventValueReferenceExpression(org.yakindu.sct.model.stext.stext.EventValueReferenceExpression) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) PostFixUnaryExpression(org.yakindu.base.expressions.expressions.PostFixUnaryExpression) EObject(org.eclipse.emf.ecore.EObject) FeatureCall(org.yakindu.base.expressions.expressions.FeatureCall) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) Check(org.eclipse.xtext.validation.Check)

Example 34 with Expression

use of org.yakindu.base.expressions.expressions.Expression in project statecharts by Yakindu.

the class STextJavaValidator method checkValueReferenedBeforeDefined.

@Check(CheckType.NORMAL)
public void checkValueReferenedBeforeDefined(Scope scope) {
    EList<Declaration> declarations = scope.getDeclarations();
    Set<QualifiedName> defined = Sets.newHashSet();
    for (Declaration declaration : declarations) {
        if (declaration instanceof VariableDefinition) {
            VariableDefinition definition = (VariableDefinition) declaration;
            if (!definition.isConst())
                return;
            Expression initialValue = definition.getInitialValue();
            List<Expression> toCheck = Lists.newArrayList(initialValue);
            TreeIterator<EObject> eAllContents = initialValue.eAllContents();
            while (eAllContents.hasNext()) {
                EObject next = eAllContents.next();
                if (next instanceof Expression)
                    toCheck.add((Expression) next);
            }
            for (Expression expression : toCheck) {
                EObject referencedObject = null;
                if (expression instanceof FeatureCall)
                    referencedObject = ((FeatureCall) expression).getFeature();
                else if (expression instanceof ElementReferenceExpression)
                    referencedObject = ((ElementReferenceExpression) expression).getReference();
                if (referencedObject instanceof VariableDefinition) {
                    if (!defined.contains(nameProvider.getFullyQualifiedName(referencedObject)))
                        error(REFERENCE_CONSTANT_BEFORE_DEFINED, definition, StextPackage.Literals.VARIABLE_DEFINITION__INITIAL_VALUE);
                }
            }
            defined.add(nameProvider.getFullyQualifiedName(definition));
        }
    }
}
Also used : VariableDefinition(org.yakindu.sct.model.stext.stext.VariableDefinition) EventRaisingExpression(org.yakindu.sct.model.stext.stext.EventRaisingExpression) Expression(org.yakindu.base.expressions.expressions.Expression) AssignmentExpression(org.yakindu.base.expressions.expressions.AssignmentExpression) EventValueReferenceExpression(org.yakindu.sct.model.stext.stext.EventValueReferenceExpression) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) PostFixUnaryExpression(org.yakindu.base.expressions.expressions.PostFixUnaryExpression) QualifiedName(org.eclipse.xtext.naming.QualifiedName) EObject(org.eclipse.emf.ecore.EObject) Declaration(org.yakindu.base.types.Declaration) FeatureCall(org.yakindu.base.expressions.expressions.FeatureCall) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) Check(org.eclipse.xtext.validation.Check)

Example 35 with Expression

use of org.yakindu.base.expressions.expressions.Expression in project statecharts by Yakindu.

the class STextJavaValidator method checkValueOfNoEvent.

@Check(CheckType.FAST)
public void checkValueOfNoEvent(EventValueReferenceExpression exp) {
    Expression eventExpr = exp.getValue();
    EObject element = null;
    if (eventExpr instanceof ElementReferenceExpression) {
        element = ((ElementReferenceExpression) eventExpr).getReference();
    } else if (eventExpr instanceof FeatureCall) {
        element = ((FeatureCall) eventExpr).getFeature();
    }
    if (element != null && (!(element instanceof Event))) {
        String elementName = "";
        if (element instanceof NamedElement) {
            elementName = "'" + ((NamedElement) element).getName() + "' ";
        }
        error(elementName + "is no event.", StextPackage.Literals.EVENT_VALUE_REFERENCE_EXPRESSION__VALUE, 0, VALUE_OF_REQUIRES_EVENT);
    }
}
Also used : EventRaisingExpression(org.yakindu.sct.model.stext.stext.EventRaisingExpression) Expression(org.yakindu.base.expressions.expressions.Expression) AssignmentExpression(org.yakindu.base.expressions.expressions.AssignmentExpression) EventValueReferenceExpression(org.yakindu.sct.model.stext.stext.EventValueReferenceExpression) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) PostFixUnaryExpression(org.yakindu.base.expressions.expressions.PostFixUnaryExpression) EObject(org.eclipse.emf.ecore.EObject) ExitEvent(org.yakindu.sct.model.stext.stext.ExitEvent) EntryEvent(org.yakindu.sct.model.stext.stext.EntryEvent) Event(org.yakindu.base.types.Event) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) FeatureCall(org.yakindu.base.expressions.expressions.FeatureCall) NamedElement(org.yakindu.base.base.NamedElement) Check(org.eclipse.xtext.validation.Check)

Aggregations

Expression (org.yakindu.base.expressions.expressions.Expression)48 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)24 AssignmentExpression (org.yakindu.base.expressions.expressions.AssignmentExpression)11 ElementReferenceExpression (org.yakindu.base.expressions.expressions.ElementReferenceExpression)10 ReactionEffect (org.yakindu.sct.model.stext.stext.ReactionEffect)9 EObject (org.eclipse.emf.ecore.EObject)7 FeatureCall (org.yakindu.base.expressions.expressions.FeatureCall)6 PrimitiveValueExpression (org.yakindu.base.expressions.expressions.PrimitiveValueExpression)6 Effect (org.yakindu.sct.model.sgraph.Effect)6 ArrayList (java.util.ArrayList)5 ParenthesizedExpression (org.yakindu.base.expressions.expressions.ParenthesizedExpression)5 PostFixUnaryExpression (org.yakindu.base.expressions.expressions.PostFixUnaryExpression)5 ReactionTrigger (org.yakindu.sct.model.stext.stext.ReactionTrigger)5 Test (org.junit.Test)4 ConditionalExpression (org.yakindu.base.expressions.expressions.ConditionalExpression)4 LogicalAndExpression (org.yakindu.base.expressions.expressions.LogicalAndExpression)4 LogicalOrExpression (org.yakindu.base.expressions.expressions.LogicalOrExpression)4 NumericalMultiplyDivideExpression (org.yakindu.base.expressions.expressions.NumericalMultiplyDivideExpression)4 Scope (org.yakindu.sct.model.sgraph.Scope)4 Transition (org.yakindu.sct.model.sgraph.Transition)4