Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 44786d25ed51d9925db0336b34f166e9e96254fc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 * 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.infra.gmfdiag.xtext.glue.edit.part.PopupXtextEditorHelper;
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.Reception;
import org.eclipse.uml2.uml.StateMachine;
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 ;
	}
}

Back to the top