Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 685ddec5975ed2f5344b214c1c1ed60d808d90c3 (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
/*******************************************************************************
 * Copyright (c) 2014 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 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 * 
 * CONTRIBUTORS:
 * 		Henrik Rentz-Reichert (initial contribution)
 * 
 *******************************************************************************/

package org.eclipse.etrice.core.fsm.naming;

import java.util.HashMap;

import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.etrice.core.fsm.fSM.ModelComponent;
import org.eclipse.etrice.core.fsm.fSM.RefinedState;
import org.eclipse.etrice.core.fsm.fSM.State;
import org.eclipse.etrice.core.fsm.fSM.StateGraph;
import org.eclipse.xtext.naming.DefaultDeclarativeQualifiedNameProvider;
import org.eclipse.xtext.naming.QualifiedName;

/**
 * @author Henrik Rentz-Reichert
 *
 */
public class FSMQualifiedNameProvider extends DefaultDeclarativeQualifiedNameProvider {
	
	public FSMQualifiedNameProvider() {
		super();
	}
	
	private HashMap<RefinedState, String> rs2uuid = new HashMap<RefinedState, String>();
	
    public QualifiedName qualifiedName(RefinedState rs) {
    	// RefinedStates can never be in conflict, whether the target reference is resolved or not
    	String uuid = rs2uuid.get(rs);
    	if (uuid==null) {
    		uuid = EcoreUtil.generateUUID();
    		rs2uuid.put(rs, uuid);
    	}
    	return getFullyQualifiedName(rs.eContainer()).append(uuid);
    }
    
    public QualifiedName qualifiedName(StateGraph sg) {
    	if (sg.eContainer() instanceof State)
    		return getFullyQualifiedName(sg.eContainer()).append("sg");
    	else if (sg.eContainer() instanceof ModelComponent)
    		return getFullyQualifiedName(sg.eContainer()).append("sm");
    	
    	assert(false): "unexpected state graph container";
    	return null;
    }

}

Back to the top