-
Notifications
You must be signed in to change notification settings - Fork 3
/
AbstractModuleElementService.java
196 lines (173 loc) · 5.09 KB
/
AbstractModuleElementService.java
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*******************************************************************************
* Copyright (c) 2016, 2024 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.acceleo.aql.evaluation;
import java.util.List;
import java.util.Set;
import org.eclipse.acceleo.ModuleElement;
import org.eclipse.acceleo.Variable;
import org.eclipse.acceleo.VisibilityKind;
import org.eclipse.acceleo.query.runtime.impl.NullValue;
import org.eclipse.acceleo.query.runtime.impl.namespace.AbstractQualifiedNameService;
import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameLookupEngine;
import org.eclipse.acceleo.query.services.EObjectServices;
import org.eclipse.acceleo.query.validation.type.IType;
/**
* Abstract implementation of a service that can wrap an Acceleo module element for AQL uses.
*
* @param <O>
* the kind of {@link ModuleElement}
* @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
*/
public abstract class AbstractModuleElementService<O extends ModuleElement> extends AbstractQualifiedNameService<O> {
/**
* The {@link Visibility}.
*/
private final Visibility visibility;
/**
* The {@link AcceleoEvaluator}.
*/
private final AcceleoEvaluator evaluator;
/**
* Constructor.
*
* @param moduleElement
* the (non-{@code null}) {@link ModuleElement} wrapped by this service.
* @param evaluator
* the {@link AcceleoEvaluator}
* @param lookupEngine
* the {@link IQualifiedNameLookupEngine}
* @param contextQualifiedName
* the qualified name containing this service
*/
public AbstractModuleElementService(O moduleElement, AcceleoEvaluator evaluator,
IQualifiedNameLookupEngine lookupEngine, String contextQualifiedName) {
super(moduleElement, lookupEngine, contextQualifiedName);
this.visibility = getVisibility(moduleElement);
this.evaluator = evaluator;
}
/**
* Gets the {@link Visibility} from the given {@link VisibilityKind}.
*
* @param visibilityKind
* the {@link VisibilityKind}
* @return the {@link Visibility} from the given {@link VisibilityKind}
*/
protected Visibility getVisibility(VisibilityKind visibilityKind) {
final Visibility res;
switch (visibilityKind) {
case PRIVATE:
res = Visibility.PRIVATE;
break;
case PROTECTED:
res = Visibility.PROTECTED;
break;
case PUBLIC:
res = Visibility.PUBLIC;
break;
default:
res = Visibility.PUBLIC;
break;
}
return res;
}
/**
* Gets the {@link AcceleoEvaluator}.
*
* @return the {@link AcceleoEvaluator}
*/
protected AcceleoEvaluator getEvaluator() {
return evaluator;
}
/**
* Gets the {@link Visibility} of the given {@link ModuleElement}.
*
* @param moduleElement
* the {@link ModuleElement}
* @return the {@link Visibility} of the given {@link ModuleElement}
*/
protected abstract Visibility getVisibility(O moduleElement);
@Override
public Visibility getVisibility() {
return visibility;
}
/**
* {@inheritDoc}
*
* @see org.eclipse.acceleo.query.runtime.IService#getShortSignature()
*/
@Override
public String getShortSignature() {
final List<IType> parameterTypes = getParameterTypes(getLookupEngine().getQueryEnvironment());
final IType[] argumentTypes = parameterTypes.toArray(new IType[parameterTypes.size()]);
return serviceShortSignature(argumentTypes);
}
/**
* {@inheritDoc}
*
* @see org.eclipse.acceleo.query.runtime.IService#getLongSignature()
*/
@Override
public String getLongSignature() {
String namespace = getContextQualifiedName();
if (namespace != null) {
return namespace + "::" + getShortSignature();
}
return getShortSignature();
}
/**
* {@inheritDoc}
*
* @see org.eclipse.acceleo.query.runtime.IService#getPriority()
*/
@Override
public int getPriority() {
return 0;
}
/**
* {@inheritDoc}
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
return obj instanceof AbstractModuleElementService
&& getOrigin() == ((AbstractModuleElementService<?>)obj).getOrigin();
}
/**
* {@inheritDoc}
*
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
return getOrigin().hashCode();
}
/**
* Gets the variable value for the given {@link Variable} and value.
*
* @param variable
* the {@link Variable}
* @param value
* the value
* @return the variable value for the given {@link Variable} and value
*/
protected Object getArgumentValue(Variable variable, Object value) {
final Object res;
if (value == null) {
final Set<IType> types = EObjectServices.getTypes(getLookupEngine().getQueryEnvironment(),
variable.getTypeAql());
res = new NullValue(types);
} else {
res = value;
}
return res;
}
}