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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
/*******************************************************************************
* 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.ui.contentassist
import com.google.common.base.Strings
import com.google.inject.Inject
import com.google.inject.Singleton
import org.eclipse.core.runtime.Assert
import org.eclipse.emf.ecore.EObject
import org.eclipse.etrice.core.room.Attribute
import org.eclipse.etrice.core.room.InterfaceItem
import org.eclipse.etrice.core.room.Message
import org.eclipse.etrice.core.room.MessageData
import org.eclipse.etrice.core.room.Operation
import org.eclipse.etrice.core.room.Port
import org.eclipse.etrice.core.room.SPP
import org.eclipse.etrice.core.room.VarDecl
import org.eclipse.etrice.core.room.util.RoomHelpers
import org.eclipse.etrice.expressions.detailcode.IDetailExpressionProvider.ExpressionFeature
import org.eclipse.etrice.expressions.detailcode.IDetailExpressionProvider.ExpressionPostfix
import org.eclipse.etrice.generator.generic.ILanguageExtension
import org.eclipse.jface.viewers.ILabelProvider
import org.eclipse.swt.graphics.Image
import org.eclipse.swt.graphics.Point
@Singleton
class DetailExpressionProposalConfig{
// static val String IMAGE_RT_METHOD = "icons/rt_method.png"
@Inject
protected ILabelProvider labelProvider
@Inject
protected RoomHelpers roomHelpers
/**
* Return postfix string and its selection (relative start, length), e.g. <code>[argument]</code>
*/
def Pair<String, Point> getPostfixReplacement(ExpressionFeature feature) {
feature.assertNotNull
var String[] brackets = switch feature.postfix {
case PARENTHESES: #['(', ')']
case BRACKETS: #['[', ']']
default: return "" -> null
}
var String replacement = switch data : feature.data {
Operation:
data.arguments.map[name].join(', ')
Message case data.data !== null:
ILanguageExtension.GENERIC_DATA_NAME
Attribute, // fall through
InterfaceItem:
'0'
default:
''
}
val selection = if(!replacement.empty) new Point(1, replacement.length)
brackets.head + replacement + brackets.last -> selection
}
/**
* Return completion string and its selection (relative start, length)
*/
def Pair<String, Point> getCompletion(ExpressionFeature feature) {
feature.assertNotNull
var postfix = getPostfixReplacement(feature)
var point = postfix.value
if (point !== null)
point.x += feature.id.length
return feature.id + postfix.key -> point
}
/**
* Text format:
* {@code completionInfo : typedInfo - classInfo}
*/
def String getDisplayString(ExpressionFeature feature) {
feature.assertNotNull
val data = feature.data
var completionInfo = feature.id + feature.getPostfixReplacement.key
var typedInfo = ""
var classInfo = if(data instanceof EObject) data.eClass.name else ""
switch data {
Attribute:
typedInfo = data?.type?.type?.name
InterfaceItem:
typedInfo = roomHelpers.getProtocol(data)?.name
// RuntimeMethodExpressionData case feature.id == RuntimeDetailExpressionProvider.RT_METHOD_GET_REPLICATION:
// typedInfo = 'int'
VarDecl: {
typedInfo = data?.refType?.type?.name
classInfo = ""
}
MessageData: {
typedInfo = data?.refType?.type?.name
}
default: {
val label = labelProvider.getText(data)
// if label starts with completion then label might be better
if(label !== null && !Strings.commonPrefix(label, completionInfo).empty) completionInfo = label
}
}
// mark port as broadcast
if (feature.postfix == ExpressionPostfix.NONE) {
switch data {
SPP case data.isEventDriven /* fall through */ ,
Port case data.isReplicated && data.isEventDriven:
completionInfo = completionInfo + " (broadcast)"
}
}
if(!typedInfo.empty) typedInfo = " : " + typedInfo
if(!classInfo.empty) classInfo = " - " + classInfo
return completionInfo + typedInfo + classInfo
}
def Image getImage(ExpressionFeature feature) {
feature.assertNotNull
switch feature.data {
EObject: labelProvider.getImage(feature.data)
// RuntimeMethodExpressionData: Activator.getImage(IMAGE_RT_METHOD)
}
}
// /**
// * Filter by prefix
// */
// def getContextFeaturesWithPrefix(ExpressionFeature ctx, String prefix) {
// delegate.getContextFeatures(ctx).filter[id.startsWith(prefix)]
// }
//
// /**
// * Filter by prefix
// */
// def getInitialFeaturesWithPrefix(String prefix) {
// delegate.initialFeatures.filter[id.startsWith(prefix)]
// }
def protected assertNotNull(ExpressionFeature feature) {
Assert.isTrue(!Strings.isNullOrEmpty(feature.id))
Assert.isNotNull(feature.postfix)
Assert.isNotNull(feature.data)
}
}
|