Skip to content

Package: TableDmrToRootEClassConverter

TableDmrToRootEClassConverter

nameinstructionbranchcomplexitylinemethod
TableDmrToRootEClassConverter()
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%
dispose()
M: 10 C: 7
41%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 3 C: 3
50%
M: 0 C: 1
100%
getLegacyDmrToRootEClass()
M: 16 C: 6
27%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 4 C: 2
33%
M: 0 C: 1
100%
getRootEClass(VDomainModelReference)
M: 0 C: 20
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
isApplicable(VDomainModelReference)
M: 0 C: 7
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
lambda$0(VTableDomainModelReference)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
setLegacyDmrToRootEClass(LegacyDmrToRootEClass)
M: 0 C: 4
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-2019 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: * Lucas Koehler - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.internal.core.services.segments.multi;
15:
16: import org.eclipse.emf.ecore.EClass;
17: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
18: import org.eclipse.emf.ecp.view.spi.table.model.VTableDomainModelReference;
19: import org.eclipse.emfforms.internal.core.services.segments.featurepath.FeatureDmrToRootEClassConverter;
20: import org.eclipse.emfforms.spi.core.services.segments.DmrToRootEClassConverter;
21: import org.eclipse.emfforms.spi.core.services.segments.LegacyDmrToRootEClass;
22: import org.osgi.framework.BundleContext;
23: import org.osgi.framework.FrameworkUtil;
24: import org.osgi.framework.ServiceReference;
25: import org.osgi.service.component.annotations.Component;
26: import org.osgi.service.component.annotations.Deactivate;
27:
28: /**
29: * Converts a {@link VTableDomainModelReference} to its root EClass.
30: *
31: * @author Lucas Koehler
32: *
33: */
34: @Component(name = "TableDmrToRootEClassConverter", service = DmrToRootEClassConverter.class)
35: public class TableDmrToRootEClassConverter extends FeatureDmrToRootEClassConverter {
36:
37:         private LegacyDmrToRootEClass dmrToRootEClass;
38:         private ServiceReference<LegacyDmrToRootEClass> dmrToRootEClassServiceRef;
39:
40:         @Override
41:         public double isApplicable(VDomainModelReference dmr) {
42:•                if (dmr instanceof VTableDomainModelReference) {
43:                         return 3d;
44:                 }
45:                 return NOT_APPLICABLE;
46:         }
47:
48:         @Override
49:         public EClass getRootEClass(VDomainModelReference dmr) throws IllegalArgumentException {
50:                 final VTableDomainModelReference tableDmr = (VTableDomainModelReference) dmr;
51:•                if (tableDmr.getDomainModelReference() == null) {
52:                         return super.getRootEClass(dmr);
53:                 }
54:
55:                 return getLegacyDmrToRootEClass().getRootEClass(tableDmr.getDomainModelReference())
56:                         .orElseThrow(() -> new IllegalArgumentException(
57:                                 "Could not determine root EClass of the table dmr's dmr: " + tableDmr.getDomainModelReference())); //$NON-NLS-1$
58:         }
59:
60:         /** Ungets manually retrieved LegacyDmrToRootEClass. */
61:         @Deactivate
62:         public void dispose() {
63:                 dmrToRootEClass = null;
64:•                if (dmrToRootEClassServiceRef != null) {
65:                         FrameworkUtil.getBundle(TableDmrToRootEClassConverter.class).getBundleContext()
66:                                 .ungetService(dmrToRootEClassServiceRef);
67:                         dmrToRootEClassServiceRef = null;
68:                 }
69:         }
70:
71:         // Lazily get the LegacyDmrToRootEClass to avoid circular dependency during service creation
72:         private LegacyDmrToRootEClass getLegacyDmrToRootEClass() {
73:•                if (dmrToRootEClass == null) {
74:                         final BundleContext bundleContext = FrameworkUtil.getBundle(TableDmrToRootEClassConverter.class)
75:                                 .getBundleContext();
76:                         dmrToRootEClassServiceRef = bundleContext.getServiceReference(LegacyDmrToRootEClass.class);
77:                         dmrToRootEClass = bundleContext.getService(dmrToRootEClassServiceRef);
78:                 }
79:                 return dmrToRootEClass;
80:         }
81:
82:         /**
83:          * Sets the {@link LegacyDmrToRootEClass}. Package visibility for testing.
84:          *
85:          * @param dmrToRootEClass The {@link LegacyDmrToRootEClass} to use
86:          */
87:         void setLegacyDmrToRootEClass(LegacyDmrToRootEClass dmrToRootEClass) {
88:                 this.dmrToRootEClass = dmrToRootEClass;
89:         }
90: }