/* * generated by Xtext */ package org.eclipse.papyrus.uml.textedit.transition.xtext.scoping; import java.util.ArrayList; import java.util.List; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EReference; import org.eclipse.papyrus.uml.textedit.transition.xtext.umlTransition.CallOrSignalEventRule; import org.eclipse.uml2.uml.Classifier; import org.eclipse.uml2.uml.Element; import org.eclipse.uml2.uml.NamedElement; import org.eclipse.uml2.uml.Reception; import org.eclipse.uml2.uml.StateMachine; import org.eclipse.xtext.gmf.glue.edit.part.PopupXtextEditorHelper; import org.eclipse.xtext.resource.IEObjectDescription; import org.eclipse.xtext.scoping.IScope; import org.eclipse.xtext.scoping.Scopes; import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider; import org.eclipse.xtext.scoping.impl.SimpleScope; /** * This class contains custom scoping description. * * see : http://www.eclipse.org/Xtext/documentation/latest/xtext.html#scoping * on how and when to use it * */ public class UmlTransitionScopeProvider extends AbstractDeclarativeScopeProvider { /** * Rule for computing the scope of TriggerRule * @param ctx * @param ref * @return */ public IScope scope_CallOrSignalEventRule_operationOrSignal(CallOrSignalEventRule ctx, EReference ref) { return create___CallOrSignalEventRule_operationOrSignal___Scope(ctx) ; } private IScope create___CallOrSignalEventRule_operationOrSignal___Scope(CallOrSignalEventRule ctx) { List<EObject> allOperationsAndSignals = getVisibleOperationAndSignals(PopupXtextEditorHelper.context) ; Iterable<IEObjectDescription> visibleOperationsAndSignals = Scopes.scopedElementsFor(allOperationsAndSignals) ; return new SimpleScope(visibleOperationsAndSignals) ; } public static List<EObject> getVisibleOperationAndSignals(EObject context) { List<EObject> allOperationsAndSignals = new ArrayList<EObject>() ; Element tmpContext = (Element) context ; while (tmpContext != null && !(tmpContext instanceof Classifier && !(tmpContext instanceof StateMachine))) { tmpContext = tmpContext.getOwner() ; } if (tmpContext != null) { Classifier behavioredClassifier = (Classifier) tmpContext ; allOperationsAndSignals.addAll(behavioredClassifier.getAllOperations()) ; if (behavioredClassifier instanceof org.eclipse.uml2.uml.Class) { org.eclipse.uml2.uml.Class behavioredClass = (org.eclipse.uml2.uml.Class) behavioredClassifier ; for (Reception r : behavioredClass.getOwnedReceptions()) { if (r.getSignal() != null) { if (!(allOperationsAndSignals.contains(r.getSignal()))) { allOperationsAndSignals.add(r.getSignal()) ; } } } } } return allOperationsAndSignals ; } }