Skip to main content
summaryrefslogtreecommitdiffstats
blob: 8314d53ebede29956a6e75593e58414b163cf022 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*******************************************************************************
 * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * CONTRIBUTORS:
 * 		Henrik Rentz-Reichert (initial contribution)
 * 
 *******************************************************************************/

package org.eclipse.etrice.core.etmap.scoping;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.etrice.core.etmap.eTMap.Mapping;
import org.eclipse.etrice.core.etmap.eTMap.SubSystemMapping;
import org.eclipse.etrice.core.etmap.eTMap.ThreadMapping;
import org.eclipse.etrice.core.etphys.eTPhys.NodeRef;
import org.eclipse.etrice.core.etphys.eTPhys.PhysicalThread;
import org.eclipse.etrice.core.room.LogicalThread;
import org.eclipse.etrice.core.room.SubSystemRef;
import org.eclipse.xtext.resource.EObjectDescription;
import org.eclipse.xtext.resource.IEObjectDescription;
import org.eclipse.xtext.scoping.IScope;
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 ETMapScopeProvider extends AbstractDeclarativeScopeProvider {
	
	public IScope scope_SubSystemMapping_logicalSubSys(SubSystemMapping ssm, EReference ref) {
		final List<IEObjectDescription> scopes = new ArrayList<IEObjectDescription>();

		Mapping map = (Mapping) ssm.eContainer();
		if (map.getLogicalSys()!=null)
			for (SubSystemRef subsys : map.getLogicalSys().getSubSystems()) {
				scopes.add(EObjectDescription.create(subsys.getName(), subsys));
			}

		return new SimpleScope(IScope.NULLSCOPE, scopes);
	}
	
	public IScope scope_SubSystemMapping_node(SubSystemMapping ssm, EReference ref) {
		final List<IEObjectDescription> scopes = new ArrayList<IEObjectDescription>();

		Mapping map = (Mapping) ssm.eContainer();
		if (map.getPhysicalSys()!=null)
			for (NodeRef node : map.getPhysicalSys().getNodeRefs()) {
				scopes.add(EObjectDescription.create(node.getName(), node));
			}

		return new SimpleScope(IScope.NULLSCOPE, scopes);
	}
	
	public IScope scope_ThreadMapping_physicalThread(ThreadMapping aim, EReference ref) {
		final List<IEObjectDescription> scopes = new ArrayList<IEObjectDescription>();

		EObject parent = aim.eContainer();
		while (parent!=null) {
			if (parent instanceof SubSystemMapping)
				break;
			parent = parent.eContainer();
		}
		
		if (parent instanceof SubSystemMapping) {
			SubSystemMapping ssm = (SubSystemMapping) parent;
			for (PhysicalThread thread : ssm.getNode().getType().getThreads()) {
				scopes.add(EObjectDescription.create(thread.getName(), thread));
			}
		}
		
		return new SimpleScope(IScope.NULLSCOPE, scopes);
	}
	
	public IScope scope_ThreadMapping_logicalThread(ThreadMapping tm, EReference ref) {
		final List<IEObjectDescription> scopes = new ArrayList<IEObjectDescription>();

		EObject parent = tm.eContainer();
		while (parent!=null) {
			if (parent instanceof SubSystemMapping)
				break;
			parent = parent.eContainer();
		}
		
		if (parent instanceof SubSystemMapping) {
			SubSystemMapping ssm = (SubSystemMapping) parent;
			for (LogicalThread thread : ssm.getLogicalSubSys().getType().getThreads()) {
				scopes.add(EObjectDescription.create(thread.getName(), thread));
			}
		}
		
		return new SimpleScope(IScope.NULLSCOPE, scopes);
	}
}

Back to the top