Search in sources :

Example 1 with Scope

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

the class STextScopeProvider method scope_FeatureCall_feature.

public IScope scope_FeatureCall_feature(final FeatureCall context, EReference reference) {
    Predicate<IEObjectDescription> predicate = calculateFilterPredicate(context, reference);
    Expression owner = context.getOwner();
    EObject element = null;
    if (owner instanceof ElementReferenceExpression) {
        element = ((ElementReferenceExpression) owner).getReference();
    } else if (owner instanceof FeatureCall) {
        element = ((FeatureCall) owner).getFeature();
    } else {
        return getDelegate().getScope(context, reference);
    }
    IScope scope = IScope.NULLSCOPE;
    InferenceResult result = typeInferrer.infer(owner);
    Type ownerType = result != null ? result.getType() : null;
    if (element instanceof Scope) {
        scope = Scopes.scopeFor(((Scope) element).getDeclarations());
        return new FilteringScope(scope, predicate);
    } else if (ownerType != null) {
        scope = Scopes.scopeFor(typeSystem.getPropertyExtensions(ownerType));
        scope = Scopes.scopeFor(typeSystem.getOperationExtensions(ownerType), scope);
    }
    if (ownerType instanceof ComplexType) {
        return addScopeForComplexType((ComplexType) ownerType, scope, predicate);
    }
    if (ownerType instanceof EnumerationType) {
        return addScopeForEnumType((EnumerationType) ownerType, scope, predicate);
    }
    return scope;
}
Also used : InferenceResult(org.yakindu.base.types.inferrer.ITypeSystemInferrer.InferenceResult) EnumerationType(org.yakindu.base.types.EnumerationType) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) ComplexType(org.yakindu.base.types.ComplexType) EnumerationType(org.yakindu.base.types.EnumerationType) Type(org.yakindu.base.types.Type) FilteringScope(org.eclipse.xtext.scoping.impl.FilteringScope) InterfaceScope(org.yakindu.sct.model.stext.stext.InterfaceScope) Scope(org.yakindu.sct.model.sgraph.Scope) IScope(org.eclipse.xtext.scoping.IScope) SimpleScope(org.eclipse.xtext.scoping.impl.SimpleScope) InternalScope(org.yakindu.sct.model.stext.stext.InternalScope) ImportScope(org.eclipse.xtext.scoping.impl.ImportScope) Expression(org.yakindu.base.expressions.expressions.Expression) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) EObject(org.eclipse.emf.ecore.EObject) IScope(org.eclipse.xtext.scoping.IScope) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) FeatureCall(org.yakindu.base.expressions.expressions.FeatureCall) ComplexType(org.yakindu.base.types.ComplexType) FilteringScope(org.eclipse.xtext.scoping.impl.FilteringScope)

Example 2 with Scope

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

the class FoldIncomingActionsRefactoring method createEntryBlock.

private EList<Expression> createEntryBlock(List<Expression> actionsToAdd) {
    EList<Expression> actionsOriginal;
    LocalReaction newLocalReaction = StextFactory.eINSTANCE.createLocalReaction();
    ReactionTrigger newReactionTrigger = StextFactory.eINSTANCE.createReactionTrigger();
    EntryEvent entryEvent = StextFactory.eINSTANCE.createEntryEvent();
    ReactionEffect newReactionEffect = StextFactory.eINSTANCE.createReactionEffect();
    newLocalReaction.setTrigger(newReactionTrigger);
    newReactionTrigger.getTriggers().add(entryEvent);
    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) EntryEvent(org.yakindu.sct.model.stext.stext.EntryEvent) ReactionEffect(org.yakindu.sct.model.stext.stext.ReactionEffect)

Example 3 with Scope

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

the class RenameElementHandler method findElementForFakeInStatechart.

private NamedElement findElementForFakeInStatechart(NamedElement fakeElement) {
    Resource resource = fakeElement.eResource();
    // only do something if element is really from fake resource
    if (resource instanceof LazyLinkingResource) {
        Statechart sct = getStatechartFromFakeResource((LazyLinkingResource) resource);
        EList<Scope> scopes = sct.getScopes();
        for (Scope scope : scopes) {
            // check all declarations
            EList<Declaration> declarations = scope.getDeclarations();
            for (Declaration decl : declarations) {
                if (decl.eClass().getName().equals(fakeElement.eClass().getName()) && decl.getName().equals(fakeElement.getName())) {
                    return decl;
                }
            }
            // check scope itself it is a named one
            if (scope instanceof NamedElement) {
                NamedElement namedScope = (NamedElement) scope;
                if (namedScope.eClass().getName().equals(fakeElement.eClass().getName()) && namedScope.getName().equals(fakeElement.getName())) {
                    return namedScope;
                }
            }
        }
    }
    return fakeElement;
}
Also used : Scope(org.yakindu.sct.model.sgraph.Scope) LazyLinkingResource(org.eclipse.xtext.linking.lazy.LazyLinkingResource) LazyLinkingResource(org.eclipse.xtext.linking.lazy.LazyLinkingResource) Resource(org.eclipse.emf.ecore.resource.Resource) Statechart(org.yakindu.sct.model.sgraph.Statechart) Declaration(org.yakindu.base.types.Declaration) NamedElement(org.yakindu.base.base.NamedElement)

Example 4 with Scope

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

the class StextResource method serializeStatechart.

protected void serializeStatechart(Statechart statechart) {
    StringBuilder builder = new StringBuilder();
    if (statechart.getNamespace() != null) {
        builder.append("namespace " + statechart.getNamespace());
        builder.append(NEW_LINE);
    }
    for (Annotation annotation : statechart.getAnnotations()) {
        builder.append(serialize(annotation));
        builder.append(NEW_LINE);
    }
    for (Scope scope : statechart.getScopes()) {
        builder.append(serialize(scope));
        builder.append(NEW_LINE);
    }
    statechart.setSpecification(builder.toString());
}
Also used : Scope(org.yakindu.sct.model.sgraph.Scope) Annotation(org.yakindu.base.types.Annotation) ArgumentedAnnotation(org.yakindu.sct.model.stext.stext.ArgumentedAnnotation)

Example 5 with Scope

use of org.yakindu.sct.model.sgraph.Scope 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)

Aggregations

Scope (org.yakindu.sct.model.sgraph.Scope)45 Test (org.junit.Test)27 InterfaceScope (org.yakindu.sct.model.stext.stext.InterfaceScope)27 Statechart (org.yakindu.sct.model.sgraph.Statechart)25 StextTestFactory._createInterfaceScope (org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope)18 ExecutionFlow (org.yakindu.sct.model.sexec.ExecutionFlow)16 ExecutionState (org.yakindu.sct.model.sexec.ExecutionState)16 Region (org.yakindu.sct.model.sgraph.Region)16 SGraphTestFactory._createRegion (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion)16 SGraphTestFactory._createStatechart (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createStatechart)16 InternalScope (org.yakindu.sct.model.stext.stext.InternalScope)16 LocalReaction (org.yakindu.sct.model.stext.stext.LocalReaction)16 VariableDefinition (org.yakindu.sct.model.stext.stext.VariableDefinition)16 StextTestFactory._createVariableDefinition (org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition)16 State (org.yakindu.sct.model.sgraph.State)14 SGraphTestFactory._createState (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createState)14 StextTestFactory._createLocalReaction (org.yakindu.sct.model.stext.test.util.StextTestFactory._createLocalReaction)11 ExecutionScope (org.yakindu.sct.model.sexec.ExecutionScope)9 Entry (org.yakindu.sct.model.sgraph.Entry)9 FinalState (org.yakindu.sct.model.sgraph.FinalState)9