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;
}
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;
}
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;
}
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());
}
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);
}
}
Aggregations