Skip to content

Package: BookImpl

BookImpl

nameinstructionbranchcomplexitylinemethod
BookImpl()
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
basicGetWriters()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
basicSetWriters(Writer, NotificationChain)
M: 0 C: 29
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
eGet(int, boolean, boolean)
M: 13 C: 10
43%
M: 3 C: 3
50%
M: 3 C: 2
40%
M: 3 C: 4
57%
M: 0 C: 1
100%
eInverseAdd(InternalEObject, int, NotificationChain)
M: 15 C: 11
42%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 2 C: 3
60%
M: 0 C: 1
100%
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: 18 C: 21
54%
M: 7 C: 7
50%
M: 6 C: 3
33%
M: 1 C: 4
80%
M: 0 C: 1
100%
eSet(int, Object)
M: 16 C: 7
30%
M: 3 C: 1
25%
M: 3 C: 1
25%
M: 6 C: 3
33%
M: 0 C: 1
100%
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: 18 C: 0
0%
M: 4 C: 0
0%
M: 4 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
getPages()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getTitle()
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%
getWriters()
M: 28 C: 10
26%
M: 5 C: 3
38%
M: 3 C: 2
40%
M: 6 C: 2
25%
M: 0 C: 1
100%
setPages(int)
M: 21 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
setTitle(String)
M: 11 C: 10
48%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 4
80%
M: 0 C: 1
100%
setWriters(Writer)
M: 13 C: 39
75%
M: 3 C: 7
70%
M: 2 C: 4
67%
M: 1 C: 11
92%
M: 0 C: 1
100%
static {...}
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%
toString()
M: 37 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
validate(DiagnosticChain, Map)
M: 116 C: 43
27%
M: 22 C: 6
21%
M: 14 C: 1
7%
M: 28 C: 14
33%
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: * Eugen Neufeld - initial API and implementation
13: *******************************************************************************/
14: package org.eclipse.emf.ecp.view.validation.test.model.impl;
15:
16: import java.util.Map;
17:
18: import org.eclipse.emf.common.notify.Notification;
19: import org.eclipse.emf.common.notify.NotificationChain;
20: import org.eclipse.emf.common.util.BasicDiagnostic;
21: import org.eclipse.emf.common.util.Diagnostic;
22: import org.eclipse.emf.common.util.DiagnosticChain;
23: import org.eclipse.emf.ecore.EClass;
24: import org.eclipse.emf.ecore.InternalEObject;
25: import org.eclipse.emf.ecore.impl.ENotificationImpl;
26: import org.eclipse.emf.ecore.impl.EObjectImpl;
27: import org.eclipse.emf.ecp.view.validation.test.model.Book;
28: import org.eclipse.emf.ecp.view.validation.test.model.TestPackage;
29: import org.eclipse.emf.ecp.view.validation.test.model.Writer;
30: import org.eclipse.emf.ecp.view.validation.test.model.util.TestValidator;
31:
32: /**
33: * <!-- begin-user-doc -->
34: * An implementation of the model object '<em><b>Book</b></em>'.
35: * <!-- end-user-doc -->
36: * <p>
37: * The following features are implemented:
38: * </p>
39: * <ul>
40: * <li>{@link org.eclipse.emf.ecp.view.validation.test.model.impl.BookImpl#getTitle <em>Title</em>}</li>
41: * <li>{@link org.eclipse.emf.ecp.view.validation.test.model.impl.BookImpl#getPages <em>Pages</em>}</li>
42: * <li>{@link org.eclipse.emf.ecp.view.validation.test.model.impl.BookImpl#getWriters <em>Writers</em>}</li>
43: * </ul>
44: *
45: * @generated
46: */
47: public class BookImpl extends EObjectImpl implements Book {
48:         /**
49:          * The default value of the '{@link #getTitle() <em>Title</em>}' attribute.
50:          * <!-- begin-user-doc -->
51:          * <!-- end-user-doc -->
52:          *
53:          * @see #getTitle()
54:          * @generated
55:          * @ordered
56:          */
57:         protected static final String TITLE_EDEFAULT = null;
58:
59:         /**
60:          * The cached value of the '{@link #getTitle() <em>Title</em>}' attribute.
61:          * <!-- begin-user-doc -->
62:          * <!-- end-user-doc -->
63:          *
64:          * @see #getTitle()
65:          * @generated
66:          * @ordered
67:          */
68:         protected String title = TITLE_EDEFAULT;
69:
70:         /**
71:          * The default value of the '{@link #getPages() <em>Pages</em>}' attribute.
72:          * <!-- begin-user-doc -->
73:          * <!-- end-user-doc -->
74:          *
75:          * @see #getPages()
76:          * @generated
77:          * @ordered
78:          */
79:         protected static final int PAGES_EDEFAULT = 100;
80:
81:         /**
82:          * The cached value of the '{@link #getPages() <em>Pages</em>}' attribute.
83:          * <!-- begin-user-doc -->
84:          * <!-- end-user-doc -->
85:          *
86:          * @see #getPages()
87:          * @generated
88:          * @ordered
89:          */
90:         protected int pages = PAGES_EDEFAULT;
91:
92:         /**
93:          * The cached value of the '{@link #getWriters() <em>Writers</em>}' reference.
94:          * <!-- begin-user-doc -->
95:          * <!-- end-user-doc -->
96:          *
97:          * @see #getWriters()
98:          * @generated
99:          * @ordered
100:          */
101:         protected Writer writers;
102:
103:         /**
104:          * <!-- begin-user-doc -->
105:          * <!-- end-user-doc -->
106:          *
107:          * @generated
108:          */
109:         protected BookImpl() {
110:                 super();
111:         }
112:
113:         /**
114:          * <!-- begin-user-doc -->
115:          * <!-- end-user-doc -->
116:          *
117:          * @generated
118:          */
119:         @Override
120:         protected EClass eStaticClass() {
121:                 return TestPackage.Literals.BOOK;
122:         }
123:
124:         /**
125:          * <!-- begin-user-doc -->
126:          * <!-- end-user-doc -->
127:          *
128:          * @generated
129:          */
130:         @Override
131:         public String getTitle() {
132:                 return title;
133:         }
134:
135:         /**
136:          * <!-- begin-user-doc -->
137:          * <!-- end-user-doc -->
138:          *
139:          * @generated
140:          */
141:         @Override
142:         public void setTitle(String newTitle) {
143:                 final String oldTitle = title;
144:                 title = newTitle;
145:•                if (eNotificationRequired()) {
146:                         eNotify(new ENotificationImpl(this, Notification.SET, TestPackage.BOOK__TITLE, oldTitle, title));
147:                 }
148:         }
149:
150:         /**
151:          * <!-- begin-user-doc -->
152:          * <!-- end-user-doc -->
153:          *
154:          * @generated
155:          */
156:         @Override
157:         public int getPages() {
158:                 return pages;
159:         }
160:
161:         /**
162:          * <!-- begin-user-doc -->
163:          * <!-- end-user-doc -->
164:          *
165:          * @generated
166:          */
167:         @Override
168:         public void setPages(int newPages) {
169:                 final int oldPages = pages;
170:                 pages = newPages;
171:•                if (eNotificationRequired()) {
172:                         eNotify(new ENotificationImpl(this, Notification.SET, TestPackage.BOOK__PAGES, oldPages, pages));
173:                 }
174:         }
175:
176:         /**
177:          * <!-- begin-user-doc -->
178:          * <!-- end-user-doc -->
179:          *
180:          * @generated
181:          */
182:         @Override
183:         public Writer getWriters() {
184:•                if (writers != null && writers.eIsProxy()) {
185:                         final InternalEObject oldWriters = (InternalEObject) writers;
186:                         writers = (Writer) eResolveProxy(oldWriters);
187:•                        if (writers != oldWriters) {
188:•                                if (eNotificationRequired()) {
189:                                         eNotify(new ENotificationImpl(this, Notification.RESOLVE, TestPackage.BOOK__WRITERS, oldWriters,
190:                                                 writers));
191:                                 }
192:                         }
193:                 }
194:                 return writers;
195:         }
196:
197:         /**
198:          * <!-- begin-user-doc -->
199:          * <!-- end-user-doc -->
200:          *
201:          * @generated
202:          */
203:         public Writer basicGetWriters() {
204:                 return writers;
205:         }
206:
207:         /**
208:          * <!-- begin-user-doc -->
209:          * <!-- end-user-doc -->
210:          *
211:          * @generated
212:          */
213:         public NotificationChain basicSetWriters(Writer newWriters, NotificationChain msgs) {
214:                 final Writer oldWriters = writers;
215:                 writers = newWriters;
216:•                if (eNotificationRequired()) {
217:                         final ENotificationImpl notification = new ENotificationImpl(this, Notification.SET,
218:                                 TestPackage.BOOK__WRITERS,
219:                                 oldWriters, newWriters);
220:•                        if (msgs == null) {
221:                                 msgs = notification;
222:                         } else {
223:                                 msgs.add(notification);
224:                         }
225:                 }
226:                 return msgs;
227:         }
228:
229:         /**
230:          * <!-- begin-user-doc -->
231:          * <!-- end-user-doc -->
232:          *
233:          * @generated
234:          */
235:         @Override
236:         public void setWriters(Writer newWriters) {
237:•                if (newWriters != writers) {
238:                         NotificationChain msgs = null;
239:•                        if (writers != null) {
240:                                 msgs = ((InternalEObject) writers).eInverseRemove(this, TestPackage.WRITER__BOOKS, Writer.class, msgs);
241:                         }
242:•                        if (newWriters != null) {
243:                                 msgs = ((InternalEObject) newWriters).eInverseAdd(this, TestPackage.WRITER__BOOKS, Writer.class, msgs);
244:                         }
245:                         msgs = basicSetWriters(newWriters, msgs);
246:•                        if (msgs != null) {
247:                                 msgs.dispatch();
248:                         }
249:•                } else if (eNotificationRequired()) {
250:                         eNotify(new ENotificationImpl(this, Notification.SET, TestPackage.BOOK__WRITERS, newWriters, newWriters));
251:                 }
252:         }
253:
254:         /**
255:          * <!-- begin-user-doc -->
256:          * <!-- end-user-doc -->
257:          *
258:          * @generated NOT
259:          */
260:         // BEGIN COMPLEX CODE
261:         @Override
262:         public boolean validate(DiagnosticChain chain, Map<Object, Object> context) {
263:
264:                 boolean wasSuccesful = true;
265:
266:                 // cancel if name is offensive
267:•                if (getTitle() != null && getTitle().equals("Offensive")) {
268:•                        if (chain != null) {
269:                                 chain.add(new BasicDiagnostic(Diagnostic.CANCEL,
270:                                         TestValidator.DIAGNOSTIC_SOURCE,
271:                                         TestValidator.BOOK__VALIDATE,
272:                                         "Title is too offensive to validate",
273:                                         new Object[] { this, TestPackage.eINSTANCE.getBook_Title() }));
274:                         }
275:                         wasSuccesful = false;
276:                 }
277:
278:                 // error when no title
279:•                if (getTitle() == null || getTitle().equals("")) {
280:•                        if (chain != null) {
281:                                 chain.add(new BasicDiagnostic(Diagnostic.ERROR,
282:                                         TestValidator.DIAGNOSTIC_SOURCE,
283:                                         TestValidator.BOOK__VALIDATE,
284:                                         "Books need to have a title",
285:                                         new Object[] { this, TestPackage.eINSTANCE.getBook_Title() }));
286:                         }
287:                         wasSuccesful = false;
288:                 }
289:
290:                 // warning title equals warning
291:•                if (getTitle() != null && getTitle().equals("Warning")) {
292:•                        if (chain != null) {
293:                                 chain.add(new BasicDiagnostic(Diagnostic.WARNING,
294:                                         TestValidator.DIAGNOSTIC_SOURCE,
295:                                         TestValidator.BOOK__VALIDATE,
296:                                         "Title says warning",
297:                                         new Object[] { this, TestPackage.eINSTANCE.getBook_Title() }));
298:                         }
299:                         wasSuccesful = false;
300:                 }
301:
302:                 // warning when no writer
303:•                if (getWriters() == null) {
304:•                        if (chain != null) {
305:                                 chain.add(new BasicDiagnostic(Diagnostic.WARNING,
306:                                         TestValidator.DIAGNOSTIC_SOURCE,
307:                                         TestValidator.BOOK__VALIDATE,
308:                                         "Warning: A book without a writer?",
309:                                         new Object[] { this, TestPackage.eINSTANCE.getBook_Writers() }));
310:                         }
311:                         wasSuccesful = false;
312:                 }
313:
314:                 // info when title short
315:•                if (getTitle() != null && getTitle().length() == 1) {
316:•                        if (chain != null) {
317:                                 chain.add(new BasicDiagnostic(Diagnostic.INFO,
318:                                         TestValidator.DIAGNOSTIC_SOURCE,
319:                                         TestValidator.BOOK__VALIDATE,
320:                                         "Very short title.",
321:                                         new Object[] { this, TestPackage.eINSTANCE.getBook_Title() }));
322:                         }
323:                         wasSuccesful = false;
324:                 }
325:
326:                 return wasSuccesful;
327:         }
328:
329:         // END COMPLEX CODE
330:
331:         /**
332:          * <!-- begin-user-doc -->
333:          * <!-- end-user-doc -->
334:          *
335:          * @generated
336:          */
337:         @Override
338:         public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
339:•                switch (featureID) {
340:                 case TestPackage.BOOK__WRITERS:
341:•                        if (writers != null) {
342:                                 msgs = ((InternalEObject) writers).eInverseRemove(this, TestPackage.WRITER__BOOKS, Writer.class, msgs);
343:                         }
344:                         return basicSetWriters((Writer) otherEnd, msgs);
345:                 }
346:                 return super.eInverseAdd(otherEnd, featureID, msgs);
347:         }
348:
349:         /**
350:          * <!-- begin-user-doc -->
351:          * <!-- end-user-doc -->
352:          *
353:          * @generated
354:          */
355:         @Override
356:         public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
357:•                switch (featureID) {
358:                 case TestPackage.BOOK__WRITERS:
359:                         return basicSetWriters(null, msgs);
360:                 }
361:                 return super.eInverseRemove(otherEnd, featureID, msgs);
362:         }
363:
364:         /**
365:          * <!-- begin-user-doc -->
366:          * <!-- end-user-doc -->
367:          *
368:          * @generated
369:          */
370:         @Override
371:         public Object eGet(int featureID, boolean resolve, boolean coreType) {
372:•                switch (featureID) {
373:                 case TestPackage.BOOK__TITLE:
374:                         return getTitle();
375:                 case TestPackage.BOOK__PAGES:
376:                         return getPages();
377:                 case TestPackage.BOOK__WRITERS:
378:•                        if (resolve) {
379:                                 return getWriters();
380:                         }
381:                         return basicGetWriters();
382:                 }
383:                 return super.eGet(featureID, resolve, coreType);
384:         }
385:
386:         /**
387:          * <!-- begin-user-doc -->
388:          * <!-- end-user-doc -->
389:          *
390:          * @generated
391:          */
392:         @Override
393:         public void eSet(int featureID, Object newValue) {
394:•                switch (featureID) {
395:                 case TestPackage.BOOK__TITLE:
396:                         setTitle((String) newValue);
397:                         return;
398:                 case TestPackage.BOOK__PAGES:
399:                         setPages((Integer) newValue);
400:                         return;
401:                 case TestPackage.BOOK__WRITERS:
402:                         setWriters((Writer) newValue);
403:                         return;
404:                 }
405:                 super.eSet(featureID, newValue);
406:         }
407:
408:         /**
409:          * <!-- begin-user-doc -->
410:          * <!-- end-user-doc -->
411:          *
412:          * @generated
413:          */
414:         @Override
415:         public void eUnset(int featureID) {
416:•                switch (featureID) {
417:                 case TestPackage.BOOK__TITLE:
418:                         setTitle(TITLE_EDEFAULT);
419:                         return;
420:                 case TestPackage.BOOK__PAGES:
421:                         setPages(PAGES_EDEFAULT);
422:                         return;
423:                 case TestPackage.BOOK__WRITERS:
424:                         setWriters((Writer) null);
425:                         return;
426:                 }
427:                 super.eUnset(featureID);
428:         }
429:
430:         /**
431:          * <!-- begin-user-doc -->
432:          * <!-- end-user-doc -->
433:          *
434:          * @generated
435:          */
436:         @Override
437:         public boolean eIsSet(int featureID) {
438:•                switch (featureID) {
439:                 case TestPackage.BOOK__TITLE:
440:•                        return TITLE_EDEFAULT == null ? title != null : !TITLE_EDEFAULT.equals(title);
441:                 case TestPackage.BOOK__PAGES:
442:•                        return pages != PAGES_EDEFAULT;
443:                 case TestPackage.BOOK__WRITERS:
444:•                        return writers != null;
445:                 }
446:                 return super.eIsSet(featureID);
447:         }
448:
449:         /**
450:          * <!-- begin-user-doc -->
451:          * <!-- end-user-doc -->
452:          *
453:          * @generated
454:          */
455:         @Override
456:         public String toString() {
457:•                if (eIsProxy()) {
458:                         return super.toString();
459:                 }
460:
461:                 final StringBuffer result = new StringBuffer(super.toString());
462:                 result.append(" (title: ");
463:                 result.append(title);
464:                 result.append(", pages: ");
465:                 result.append(pages);
466:                 result.append(')');
467:                 return result.toString();
468:         }
469:
470: } // BookImpl