Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b47178b64707516d4f50a63d004c91b3583d49ca (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
/*******************************************************************************
 * Copyright (c) 2015 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:
 * 		Juergen Haug (initial contribution)
 * 
 *******************************************************************************/
package org.eclipse.etrice.expressions.detailcode

import java.util.List
import org.eclipse.etrice.core.room.Attribute
import org.eclipse.etrice.core.room.DataClass
import org.eclipse.etrice.core.room.InterfaceItem
import org.eclipse.etrice.core.room.Port
import org.eclipse.etrice.core.room.SAP
import org.eclipse.etrice.core.room.SPP
import org.eclipse.etrice.expressions.detailcode.GuardDetailExpressionProvider
import org.eclipse.etrice.expressions.detailcode.IDetailExpressionProvider.ExpressionFeature
import org.eclipse.etrice.expressions.detailcode.IDetailExpressionProvider.ExpressionPostfix
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor

/**
 * Defines expression for fsm detail code of an ActorClass
 */
@FinalFieldsConstructor
class DefaultDetailExpressionProvider extends GuardDetailExpressionProvider {

	override getInitialFeatures() {
		// no super call, keep it simple
		val List<ExpressionFeature> scope = newArrayList

		if(transitionEventData !== null) { 
			scope += transitionEventData.createExprFeature(ExpressionPostfix.NONE)
		}
		if (actorClass!==null) {
			scope += actorClass.latestOperations.map[createExprFeature]
			scope += actorClass.allAttributes.map[createExprFeature]
			actorClass.allInterfaceItems.forEach [
				switch it {
					SPP case isEventDriven/* fall through */,
					Port case isEventDriven && isReplicated: {
						scope += createExprFeature(ExpressionPostfix.NONE) // additional feature for broadcast 
						scope += createExprFeature(ExpressionPostfix.BRACKETS)
					}
					Port case isReplicated/* fall through  */,
					SPP:
						scope += createExprFeature(ExpressionPostfix.BRACKETS)
					default:
						scope += createExprFeature(ExpressionPostfix.NONE)
				}
			]
		}

		return scope.filterNull.filter[id !== null].toList
	}

	override getContextFeatures(ExpressionFeature ctx) {
		// no super call, keep it simple
		ctx.assertNotNull

		val List<ExpressionFeature> scope = newArrayList
		switch obj : ctx.data {
			Port case obj.multiplicity == 1/* fall through  */,
			SAP: scope +=
				obj.protocol.getAllOperations(!obj.conjugated).map[createExprFeature]
		}
		switch obj : ctx.data {
			InterfaceItem: {
				val pc = obj.protocol
				switch pc.commType {
					case EVENT_DRIVEN:
						scope += pc.getAllMessages(obj.conjugated).map[createExprFeature]
					case DATA_DRIVEN:
						if (obj.conjugated)
							scope += pc.allIncomingMessages.map[createExprFeature]
						else
							scope += pc.allIncomingMessages.map[createExprFeature(ExpressionPostfix.NONE)] // data message has no Parenthesis
					case SYNCHRONOUS: {}
				}

			// TODO Attributes ?
			}
			Attribute case obj.type.type instanceof DataClass: {
				val dc = obj.type.type as DataClass
				scope += dc.allAttributes.map[createExprFeature]
				// not supported yet by code translation:
				// scope += dc.latestOperations.map[createExprFeature(ExpressionPostfix.PARENTHESES)]
			}
		}

		return scope.filterNull.filter[id !== null].toList
	}

}

Back to the top