Skip to content

Package: LegacyDmrToRootEClassImpl

LegacyDmrToRootEClassImpl

nameinstructionbranchcomplexitylinemethod
LegacyDmrToRootEClassImpl()
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
addDmrToRootEClassConverter(DmrToRootEClassConverter)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
getRootEClass(VDomainModelReference)
M: 0 C: 42
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
lambda$0(VDomainModelReference, DmrToRootEClassConverter)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
removeDmrToRootEClassConverter(DmrToRootEClassConverter)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
setReportService(ReportService)
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%
static {...}
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%

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;
15:
16: import java.text.MessageFormat;
17: import java.util.LinkedList;
18: import java.util.List;
19: import java.util.Optional;
20:
21: import org.eclipse.core.runtime.IStatus;
22: import org.eclipse.emf.ecore.EClass;
23: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
24: import org.eclipse.emfforms.common.RankingHelper;
25: import org.eclipse.emfforms.spi.common.report.AbstractReport;
26: import org.eclipse.emfforms.spi.common.report.ReportService;
27: import org.eclipse.emfforms.spi.core.services.segments.DmrToRootEClassConverter;
28: import org.eclipse.emfforms.spi.core.services.segments.LegacyDmrToRootEClass;
29: import org.osgi.service.component.annotations.Component;
30: import org.osgi.service.component.annotations.Reference;
31: import org.osgi.service.component.annotations.ReferenceCardinality;
32:
33: /**
34: * Default implementation of {@link LegacyDmrToRootEClass}.
35: *
36: * @author Lucas Koehler
37: *
38: */
39: @Component(name = "LegacyDmrToRootEClassImpl")
40: public class LegacyDmrToRootEClassImpl implements LegacyDmrToRootEClass {
41:
42:         private static final RankingHelper<DmrToRootEClassConverter> RANKING_HELPER = new RankingHelper<>(
43:                 DmrToRootEClassConverter.class,
44:                 DmrToRootEClassConverter.NOT_APPLICABLE,
45:                 DmrToRootEClassConverter.NOT_APPLICABLE);
46:
47:         private final List<DmrToRootEClassConverter> converters = new LinkedList<>();
48:         private ReportService reportService;
49:
50:         /**
51:          * Adds a {@link DmrToRootEClassConverter}.
52:          *
53:          * @param converter The {@link DmrToRootEClassConverter}
54:          */
55:         @Reference(cardinality = ReferenceCardinality.MULTIPLE)
56:         void addDmrToRootEClassConverter(DmrToRootEClassConverter converter) {
57:                 converters.add(converter);
58:         }
59:
60:         /**
61:          * Removes a {@link DmrToRootEClassConverter}.
62:          *
63:          * @param converter The {@link DmrToRootEClassConverter}
64:          */
65:         void removeDmrToRootEClassConverter(DmrToRootEClassConverter converter) {
66:                 converters.remove(converter);
67:         }
68:
69:         /**
70:          * Sets the {@link ReportService}.
71:          *
72:          * @param reportService The {@link ReportService} to report problems during root EClass resolvement
73:          */
74:         @Reference(unbind = "-")
75:         void setReportService(ReportService reportService) {
76:                 this.reportService = reportService;
77:         }
78:
79:         @Override
80:         public Optional<EClass> getRootEClass(VDomainModelReference dmr) {
81:                 final DmrToRootEClassConverter bestConverter = RANKING_HELPER.getHighestRankingElement(converters,
82:                         converter -> converter.isApplicable(dmr));
83:•                if (bestConverter != null) {
84:                         try {
85:                                 return Optional.of(bestConverter.getRootEClass(dmr));
86:                         } catch (final IllegalArgumentException ex) {
87:                                 reportService.report(new AbstractReport(ex, "Could not determine root EClass due to an exception.")); //$NON-NLS-1$
88:                         }
89:                 } else {
90:                         reportService.report(new AbstractReport(MessageFormat.format(
91:                                 "Could not get root EClass for DMR ''{0}'' because there was no applicable DmrToRootEClassConverter.", //$NON-NLS-1$
92:                                 dmr), IStatus.WARNING));
93:                 }
94:                 return Optional.empty();
95:         }
96:
97: }