Skip to content

Package: IsProxyConditionImpl

IsProxyConditionImpl

nameinstructionbranchcomplexitylinemethod
IsProxyConditionImpl()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
basicSetDomainModelReference(VDomainModelReference, NotificationChain)
M: 18 C: 11
38%
M: 3 C: 1
25%
M: 2 C: 1
33%
M: 7 C: 4
36%
M: 0 C: 1
100%
doEvaluate(Collection)
M: 0 C: 27
100%
M: 1 C: 7
88%
M: 1 C: 4
80%
M: 0 C: 6
100%
M: 0 C: 1
100%
eGet(int, boolean, boolean)
M: 11 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
eInverseRemove(InternalEObject, int, NotificationChain)
M: 13 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
eIsSet(int)
M: 13 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
eSet(int, Object)
M: 12 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
eStaticClass()
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
eUnset(int)
M: 10 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
evaluate(EObject)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
evaluateChangedValues(EObject, Map)
M: 3 C: 57
95%
M: 2 C: 8
80%
M: 2 C: 4
67%
M: 1 C: 13
93%
M: 0 C: 1
100%
get(EObject, VDomainModelReference)
M: 7 C: 19
73%
M: 2 C: 4
67%
M: 2 C: 2
50%
M: 4 C: 6
60%
M: 0 C: 1
100%
getDomainModelReference()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
setDomainModelReference(VDomainModelReference)
M: 25 C: 27
52%
M: 6 C: 4
40%
M: 5 C: 1
17%
M: 7 C: 9
56%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (c) 2018 Christian W. Damus and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Christian W. Damus - initial API and implementation
13: */
14: package org.eclipse.emf.ecp.view.spi.rule.model.impl;
15:
16: import java.util.ArrayList;
17: import java.util.Collection;
18: import java.util.Collections;
19: import java.util.List;
20: import java.util.Map;
21:
22: import org.eclipse.core.databinding.observable.Observables;
23: import org.eclipse.core.databinding.observable.list.IObservableList;
24: import org.eclipse.emf.common.notify.Notification;
25: import org.eclipse.emf.common.notify.NotificationChain;
26: import org.eclipse.emf.ecore.EClass;
27: import org.eclipse.emf.ecore.EObject;
28: import org.eclipse.emf.ecore.EReference;
29: import org.eclipse.emf.ecore.EStructuralFeature;
30: import org.eclipse.emf.ecore.InternalEObject;
31: import org.eclipse.emf.ecore.impl.ENotificationImpl;
32: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
33: import org.eclipse.emf.ecp.view.spi.rule.model.Activator;
34: import org.eclipse.emf.ecp.view.spi.rule.model.IsProxyCondition;
35: import org.eclipse.emf.ecp.view.spi.rule.model.RulePackage;
36: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
37:
38: /**
39: * <!-- begin-user-doc -->
40: * An implementation of the model object '<em><b>Is Proxy</b></em>'.
41: * <!-- end-user-doc -->
42: * <p>
43: * The following features are implemented:
44: * </p>
45: * <ul>
46: * <li>{@link org.eclipse.emf.ecp.view.spi.rule.model.impl.IsProxyConditionImpl#getDomainModelReference <em>Domain Model
47: * Reference</em>}</li>
48: * </ul>
49: *
50: * @generated
51: */
52: public class IsProxyConditionImpl extends ConditionImpl implements IsProxyCondition {
53:         /**
54:          * The cached value of the '{@link #getDomainModelReference() <em>Domain Model Reference</em>}' containment
55:          * reference.
56:          * <!-- begin-user-doc -->
57:          * <!-- end-user-doc -->
58:          *
59:          * @see #getDomainModelReference()
60:          * @generated
61:          * @ordered
62:          */
63:         protected VDomainModelReference domainModelReference;
64:
65:         /**
66:          * <!-- begin-user-doc -->
67:          * <!-- end-user-doc -->
68:          *
69:          * @generated
70:          */
71:         protected IsProxyConditionImpl() {
72:                 super();
73:         }
74:
75:         /**
76:          * <!-- begin-user-doc -->
77:          * <!-- end-user-doc -->
78:          *
79:          * @generated
80:          */
81:         @Override
82:         protected EClass eStaticClass() {
83:                 return RulePackage.Literals.IS_PROXY_CONDITION;
84:         }
85:
86:         /**
87:          * <!-- begin-user-doc -->
88:          * <!-- end-user-doc -->
89:          *
90:          * @generated
91:          */
92:         @Override
93:         public VDomainModelReference getDomainModelReference() {
94:                 return domainModelReference;
95:         }
96:
97:         /**
98:          * <!-- begin-user-doc -->
99:          * <!-- end-user-doc -->
100:          *
101:          * @generated
102:          */
103:         public NotificationChain basicSetDomainModelReference(VDomainModelReference newDomainModelReference,
104:                 NotificationChain msgs) {
105:                 final VDomainModelReference oldDomainModelReference = domainModelReference;
106:                 domainModelReference = newDomainModelReference;
107:•                if (eNotificationRequired()) {
108:                         final ENotificationImpl notification = new ENotificationImpl(this, Notification.SET,
109:                                 RulePackage.IS_PROXY_CONDITION__DOMAIN_MODEL_REFERENCE, oldDomainModelReference,
110:                                 newDomainModelReference);
111:•                        if (msgs == null) {
112:                                 msgs = notification;
113:                         } else {
114:                                 msgs.add(notification);
115:                         }
116:                 }
117:                 return msgs;
118:         }
119:
120:         /**
121:          * <!-- begin-user-doc -->
122:          * <!-- end-user-doc -->
123:          *
124:          * @generated
125:          */
126:         @Override
127:         public void setDomainModelReference(VDomainModelReference newDomainModelReference) {
128:•                if (newDomainModelReference != domainModelReference) {
129:                         NotificationChain msgs = null;
130:•                        if (domainModelReference != null) {
131:                                 msgs = ((InternalEObject) domainModelReference).eInverseRemove(this,
132:                                         EOPPOSITE_FEATURE_BASE - RulePackage.IS_PROXY_CONDITION__DOMAIN_MODEL_REFERENCE, null, msgs);
133:                         }
134:•                        if (newDomainModelReference != null) {
135:                                 msgs = ((InternalEObject) newDomainModelReference).eInverseAdd(this,
136:                                         EOPPOSITE_FEATURE_BASE - RulePackage.IS_PROXY_CONDITION__DOMAIN_MODEL_REFERENCE, null, msgs);
137:                         }
138:                         msgs = basicSetDomainModelReference(newDomainModelReference, msgs);
139:•                        if (msgs != null) {
140:                                 msgs.dispatch();
141:                         }
142:•                } else if (eNotificationRequired()) {
143:                         eNotify(
144:                                 new ENotificationImpl(this, Notification.SET, RulePackage.IS_PROXY_CONDITION__DOMAIN_MODEL_REFERENCE,
145:                                         newDomainModelReference, newDomainModelReference));
146:                 }
147:         }
148:
149:         /**
150:          * <!-- begin-user-doc -->
151:          * <!-- end-user-doc -->
152:          *
153:          * @generated
154:          */
155:         @Override
156:         public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
157:•                switch (featureID) {
158:                 case RulePackage.IS_PROXY_CONDITION__DOMAIN_MODEL_REFERENCE:
159:                         return basicSetDomainModelReference(null, msgs);
160:                 }
161:                 return super.eInverseRemove(otherEnd, featureID, msgs);
162:         }
163:
164:         /**
165:          * <!-- begin-user-doc -->
166:          * <!-- end-user-doc -->
167:          *
168:          * @generated
169:          */
170:         @Override
171:         public Object eGet(int featureID, boolean resolve, boolean coreType) {
172:•                switch (featureID) {
173:                 case RulePackage.IS_PROXY_CONDITION__DOMAIN_MODEL_REFERENCE:
174:                         return getDomainModelReference();
175:                 }
176:                 return super.eGet(featureID, resolve, coreType);
177:         }
178:
179:         /**
180:          * <!-- begin-user-doc -->
181:          * <!-- end-user-doc -->
182:          *
183:          * @generated
184:          */
185:         @Override
186:         public void eSet(int featureID, Object newValue) {
187:•                switch (featureID) {
188:                 case RulePackage.IS_PROXY_CONDITION__DOMAIN_MODEL_REFERENCE:
189:                         setDomainModelReference((VDomainModelReference) newValue);
190:                         return;
191:                 }
192:                 super.eSet(featureID, newValue);
193:         }
194:
195:         /**
196:          * <!-- begin-user-doc -->
197:          * <!-- end-user-doc -->
198:          *
199:          * @generated
200:          */
201:         @Override
202:         public void eUnset(int featureID) {
203:•                switch (featureID) {
204:                 case RulePackage.IS_PROXY_CONDITION__DOMAIN_MODEL_REFERENCE:
205:                         setDomainModelReference((VDomainModelReference) null);
206:                         return;
207:                 }
208:                 super.eUnset(featureID);
209:         }
210:
211:         /**
212:          * <!-- begin-user-doc -->
213:          * <!-- end-user-doc -->
214:          *
215:          * @generated
216:          */
217:         @Override
218:         public boolean eIsSet(int featureID) {
219:•                switch (featureID) {
220:                 case RulePackage.IS_PROXY_CONDITION__DOMAIN_MODEL_REFERENCE:
221:•                        return domainModelReference != null;
222:                 }
223:                 return super.eIsSet(featureID);
224:         }
225:
226:         @Override
227:         public boolean evaluate(EObject domainModel) {
228:                 final VDomainModelReference path = getDomainModelReference();
229:                 final Collection<? extends EObject> subjects = get(domainModel, path);
230:                 return doEvaluate(subjects);
231:         }
232:
233:         /**
234:          * Obtains the objects referenced by a domain-model reference, from the given
235:          * {@code owner} object.
236:          *
237:          * @param owner the owner of the reference
238:          * @param dmr the domain-model reference to follow
239:          *
240:          * @return the referenced objects
241:          */
242:         List<? extends EObject> get(EObject owner, VDomainModelReference dmr) {
243:•                if (dmr == null) {
244:                         // Condition on the owner object, itself
245:                         return Collections.singletonList(owner);
246:                 }
247:
248:                 try {
249:                         @SuppressWarnings("unchecked")
250:                         IObservableList<? extends EObject> result = Activator.getDefault().getEMFFormsDatabinding()
251:                                 .getObservableList(dmr, owner);
252:
253:                         // We have to have EObjects, which means an EReference
254:•                        if (result == null || !(result.getElementType() instanceof EReference)) {
255:                                 result = Observables.emptyObservableList();
256:                         }
257:                         return result;
258:                 } catch (final DatabindingFailedException e) {
259:                         Activator.log(e);
260:                         return Collections.emptyList();
261:                 }
262:         }
263:
264:         /**
265:          * Evaluates me by iteration of the given {@code subjects}.
266:          *
267:          * @param subjects the objects over which to iterate my {@link #getItemCondition() condition}
268:          * @return the result of the iteration
269:          */
270:         protected boolean doEvaluate(Collection<? extends EObject> subjects) {
271:                 boolean result = false;
272:
273:•                for (final EObject next : subjects) {
274:•                        result = next != null && next.eIsProxy();
275:•                        if (result) {
276:                                 break; // Short-circuit
277:                         }
278:                 }
279:
280:                 return result;
281:         }
282:
283:         @Override
284:         public boolean evaluateChangedValues(EObject domainModel,
285:                 Map<EStructuralFeature.Setting, Object> possibleNewValues) {
286:
287:•                if (getDomainModelReference() == null) {
288:                         // Condition on the domain object, itself
289:                         return domainModel.eIsProxy();
290:                 }
291:
292:                 // We are only interested in changes to the set of objects that I iterate over (subjects)
293:                 final List<Collection<? extends EObject>> proposedNewSubjects = new ArrayList<Collection<? extends EObject>>();
294:
295:•                for (final Map.Entry<EStructuralFeature.Setting, Object> next : possibleNewValues.entrySet()) {
296:                         final EStructuralFeature.Setting setting = next.getKey();
297:
298:•                        if (setting.getEObject() == domainModel) {
299:                                 // Changing the set of objects to iterate
300:                                 @SuppressWarnings("unchecked")
301:                                 final List<? extends EObject> newValues = (List<? extends EObject>) next.getValue();
302:                                 proposedNewSubjects.add(newValues);
303:                         } // else it's a change to features of an existing subject
304:                 }
305:
306:                 boolean result = true;
307:•                for (final Collection<? extends EObject> newValues : proposedNewSubjects) {
308:                         result = doEvaluate(newValues);
309:•                        if (result) {
310:                                 break;
311:                         }
312:                 }
313:
314:                 return result;
315:         }
316:
317: } // IsProxyConditionImpl