Skip to content

Package: ECPModelElementChangeListener

ECPModelElementChangeListener

nameinstructionbranchcomplexitylinemethod
ECPModelElementChangeListener(EObject)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
notifyChanged(Notification)
M: 4 C: 9
69%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 1 C: 5
83%
M: 0 C: 1
100%
onRuntimeExceptionInListener(RuntimeException)
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
remove()
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2013 EclipseSource Muenchen GmbH 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: * Jonas Helming - initial API and implementation
13: *
14: *******************************************************************************/
15:
16: package org.eclipse.emf.ecp.edit.spi.util;
17:
18: import org.eclipse.emf.common.notify.Notification;
19: import org.eclipse.emf.common.notify.impl.AdapterImpl;
20: import org.eclipse.emf.ecore.EObject;
21:
22: /**
23: * Listens to the changes of one modelelement.
24: *
25: * @author helming
26: */
27: public abstract class ECPModelElementChangeListener extends AdapterImpl {
28:
29:         private final EObject modelelement;
30:
31:         /**
32:          * Default constructor.
33:          *
34:          * @param modelelement
35:          * the modelelement to listen on
36:          */
37:         public ECPModelElementChangeListener(EObject modelelement) {
38:                 this.modelelement = modelelement;
39:                 modelelement.eAdapters().add(this);
40:         }
41:
42:         /**
43:          * Handle changes to the model element.
44:          *
45:          * @param notification
46:          * the EMF notification, providing details on the change
47:          *
48:          */
49:         public abstract void onChange(Notification notification);
50:
51:         /**
52:          * Handle a runtime exception that occured in this listeners methods. NOTE: runtime exceptions of this method will
53:          * be
54:          * logged and silently dropped.
55:          *
56:          * @param exception
57:          * the exception
58:          */
59:         void onRuntimeExceptionInListener(RuntimeException exception) {
60:                 remove();
61:         }
62:
63:         /**
64:          * {@inheritDoc}
65:          *
66:          * @see org.eclipse.emf.common.notify.impl.AdapterImpl#notifyChanged(org.eclipse.emf.common.notify.Notification)
67:          */
68:         @Override
69:         public void notifyChanged(Notification notification) {
70:•                if (notification.isTouch()) {
71:                         return;
72:                 }
73:                 // BEGIN SUPRESS CATCH EXCEPTION
74:                 try {
75:                         onChange(notification);
76:                 } catch (final RuntimeException e) {
77:                         onRuntimeExceptionInListener(e);
78:                 }
79:                 // END SUPRESS CATCH EXCEPTION
80:         }
81:
82:         /**
83:          * Removes the {@link ECPModelElementChangeListener}.
84:          */
85:         public void remove() {
86:                 modelelement.eAdapters().remove(this);
87:         }
88:
89: }