Skip to content

Package: SubstitutionAdapter$1

SubstitutionAdapter$1

nameinstructionbranchcomplexitylinemethod
notifyChanged(Notification)
M: 30 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
{...}
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /**
2: * Copyright (c) 2009-2010 Thales Corporate Services S.A.S.
3: * This program and the accompanying materials
4: * are made available under the terms of the Eclipse Public License v2.0
5: * which accompanies this distribution, and is available at
6: * https://www.eclipse.org/legal/epl-v2.0
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Thales Corporate Services S.A.S - initial API and implementation
12: *
13: */
14: package org.eclipse.egf.model.pattern.adapter;
15:
16: import org.eclipse.egf.model.fcore.FcorePackage;
17: import org.eclipse.egf.model.pattern.Pattern;
18: import org.eclipse.egf.model.pattern.PatternPackage;
19: import org.eclipse.egf.model.pattern.Substitution;
20: import org.eclipse.emf.common.notify.Notification;
21: import org.eclipse.emf.common.notify.impl.AdapterImpl;
22: import org.eclipse.emf.ecore.EObject;
23: import org.eclipse.emf.ecore.EStructuralFeature;
24: import org.eclipse.emf.ecore.InternalEObject;
25: import org.eclipse.emf.ecore.impl.ENotificationImpl;
26: import org.eclipse.emf.ecore.util.EcoreUtil;
27:
28: /**
29: * @author Xavier Maysonnave
30: *
31: */
32: public class SubstitutionAdapter extends AdapterImpl {
33:
34: private EObject _root;
35:
36: private Substitution _substitution;
37:
38: private EStructuralFeature _nameFeature = FcorePackage.Literals.NAMED_MODEL_ELEMENT__NAME;
39:
40: private EStructuralFeature _substitutionReplacedElementFeature = PatternPackage.Literals.SUBSTITUTION__REPLACED_ELEMENT;
41:
42: private AdapterImpl _nameAdapter = new AdapterImpl() {
43:
44: @Override
45: public void notifyChanged(Notification msg) {
46:• if (msg.getEventType() == Notification.SET && msg.getFeature().equals(_nameFeature)) {
47: _substitution.eNotify(new ENotificationImpl((InternalEObject) _substitution, -1, _substitutionReplacedElementFeature, null, null) {
48:
49: @Override
50: public boolean isTouch() {
51: return true;
52: }
53:
54: });
55: }
56: }
57: };
58:
59: public SubstitutionAdapter(Substitution substitution) {
60: super();
61: _substitution = substitution;
62: _substitution.eAdapters().add(this);
63: }
64:
65: @Override
66: public void notifyChanged(Notification notification) {
67: if (notification.getFeature() == null || notification.getFeature().equals(_substitutionReplacedElementFeature)) {
68: switch (notification.getEventType()) {
69: case Notification.SET:
70: case Notification.RESOLVE:
71: EObject newValue = EcoreUtil.getRootContainer((Pattern) notification.getNewValue(), true);
72: EObject oldValue = EcoreUtil.getRootContainer((Pattern) notification.getOldValue(), true);
73: if (oldValue != null && oldValue != notification.getOldValue()) {
74: oldValue.eAdapters().remove(_nameAdapter);
75: }
76: if (newValue != null && newValue != notification.getNewValue() && newValue.eAdapters().contains(_nameAdapter) == false) {
77: newValue.eAdapters().add(_nameAdapter);
78: _root = newValue;
79: }
80: break;
81: case Notification.REMOVING_ADAPTER:
82: if (_root != null) {
83: _root.eAdapters().remove(_nameAdapter);
84: }
85: break;
86: default:
87: return; // No notification
88: }
89: }
90: }
91:
92: }