Search in sources :

Example 21 with ElementReferenceExpression

use of org.yakindu.base.expressions.expressions.ElementReferenceExpression 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 22 with ElementReferenceExpression

use of org.yakindu.base.expressions.expressions.ElementReferenceExpression 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)

Example 23 with ElementReferenceExpression

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

the class SGenSemanticHighlightingCalculator method provideHighlightingFor.

public void provideHighlightingFor(XtextResource resource, IHighlightedPositionAcceptor acceptor) {
    if (resource == null || resource.getParseResult() == null)
        return;
    TreeIterator<EObject> allContents = resource.getAllContents();
    while (allContents.hasNext()) {
        final EObject object = allContents.next();
        if (object instanceof GeneratorEntry) {
            GeneratorEntry entry = (GeneratorEntry) object;
            List<INode> nodes = NodeModelUtils.findNodesForFeature(entry, SGenPackage.Literals.GENERATOR_ENTRY__CONTENT_TYPE);
            List<INode> features = NodeModelUtils.findNodesForFeature(entry, SGenPackage.Literals.GENERATOR_ENTRY__FEATURES);
            for (INode node : nodes) {
                if (node instanceof LeafNode && !((LeafNode) node).isHidden()) {
                    acceptor.addPosition(node.getTotalOffset(), node.getTotalLength(), DefaultHighlightingConfiguration.KEYWORD_ID);
                }
            }
            for (INode node : features) {
                if (node.getSemanticElement() instanceof FeatureConfigurationImpl) {
                    FeatureConfigurationImpl feature = (FeatureConfigurationImpl) node.getSemanticElement();
                    DeprecatableElement deprecatableElement = feature.getType();
                    if (deprecatableElement != null && deprecatableElement.isDeprecated()) {
                        acceptor.addPosition(node.getTotalOffset(), node.getTotalLength(), SGenHighlightingConfiguration.DEPRECATION);
                    }
                }
            }
        // allContents.prune();
        } else if (object instanceof ElementReferenceExpression && !((ElementReferenceExpression) object).getReference().eIsProxy()) {
            List<INode> nodes = NodeModelUtils.findNodesForFeature(object, ExpressionsPackage.Literals.ELEMENT_REFERENCE_EXPRESSION__REFERENCE);
            for (INode node : nodes) {
                String name = ((Property) ((ElementReferenceExpression) object).getReference()).getName();
                switch(name) {
                    case SCT_VERSION_VAR:
                    case SHA256:
                    case SCTFILE:
                    case TIMESTAMP_VAR:
                    case USER_VAR:
                    case HOSTNAME_VAR:
                        acceptor.addPosition(node.getTotalOffset(), node.getTotalLength(), DefaultHighlightingConfiguration.KEYWORD_ID);
                }
            }
        }
    }
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) GeneratorEntry(org.yakindu.sct.model.sgen.GeneratorEntry) EObject(org.eclipse.emf.ecore.EObject) LeafNode(org.eclipse.xtext.nodemodel.impl.LeafNode) DeprecatableElement(org.yakindu.sct.model.sgen.DeprecatableElement) FeatureConfigurationImpl(org.yakindu.sct.model.sgen.impl.FeatureConfigurationImpl) List(java.util.List) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression)

Aggregations

ElementReferenceExpression (org.yakindu.base.expressions.expressions.ElementReferenceExpression)23 EObject (org.eclipse.emf.ecore.EObject)10 Test (org.junit.Test)10 AssignmentExpression (org.yakindu.base.expressions.expressions.AssignmentExpression)9 FeatureCall (org.yakindu.base.expressions.expressions.FeatureCall)9 ReactionTrigger (org.yakindu.sct.model.stext.stext.ReactionTrigger)9 Expression (org.yakindu.base.expressions.expressions.Expression)7 Statechart (org.yakindu.sct.model.sgraph.Statechart)7 EventDefinition (org.yakindu.sct.model.stext.stext.EventDefinition)7 StextTestFactory._createReactionTrigger (org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionTrigger)7 Transition (org.yakindu.sct.model.sgraph.Transition)6 VariableDefinition (org.yakindu.sct.model.stext.stext.VariableDefinition)6 Check (org.eclipse.xtext.validation.Check)5 PrimitiveValueExpression (org.yakindu.base.expressions.expressions.PrimitiveValueExpression)5 NamedElement (org.yakindu.base.base.NamedElement)4 PostFixUnaryExpression (org.yakindu.base.expressions.expressions.PostFixUnaryExpression)4 ExecutionFlow (org.yakindu.sct.model.sexec.ExecutionFlow)4 If (org.yakindu.sct.model.sexec.If)4 Region (org.yakindu.sct.model.sgraph.Region)4 SGraphTestFactory._createRegion (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion)4