Skip to content

Package: ReferenceHelperImpl

ReferenceHelperImpl

nameinstructionbranchcomplexitylinemethod
ReferenceHelperImpl()
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
addEcorePath(String)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
buildSchemaPath(VFeaturePathDomainModelReference)
M: 63 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 14 C: 0
0%
M: 1 C: 0
0%
buildSchemaPath(VTableDomainModelReference)
M: 12 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getEcorePaths()
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%
getStringRepresentation(VDomainModelReference)
M: 14 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
isArray(EReference)
M: 8 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2015 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: * Stefan Dirix - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.emf2web.json.util;
15:
16: import java.util.LinkedHashSet;
17: import java.util.Set;
18:
19: import org.eclipse.emf.ecore.EReference;
20: import org.eclipse.emf.ecp.emf2web.util.AbstractReferenceHelper;
21: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
22: import org.eclipse.emf.ecp.view.spi.model.VFeaturePathDomainModelReference;
23: import org.eclipse.emf.ecp.view.spi.table.model.VTableDomainModelReference;
24:
25: /**
26: * @author Stefan Dirix
27: *
28: */
29: public class ReferenceHelperImpl extends AbstractReferenceHelper {
30:
31:         private static final String ROOT = "#"; //$NON-NLS-1$
32:         private static final String SEPARATOR = "/"; //$NON-NLS-1$
33:         private static final String PROPERTIES = "properties"; //$NON-NLS-1$
34:         private static final String ITEMS = "items"; //$NON-NLS-1$
35:         private final Set<String> ecorePaths = new LinkedHashSet<String>();
36:
37:         @Override
38:         public String getStringRepresentation(VDomainModelReference reference) {
39:•                if (VTableDomainModelReference.class.isInstance(reference)) {
40:                         return buildSchemaPath((VTableDomainModelReference) reference);
41:                 }
42:                 return buildSchemaPath((VFeaturePathDomainModelReference) reference);
43:         }
44:
45:         private String buildSchemaPath(VTableDomainModelReference reference) {
46:•                if (reference.getDomainModelReference() == null) {
47:                         return buildSchemaPath((VFeaturePathDomainModelReference) reference);
48:                 }
49:                 return getStringRepresentation(reference.getDomainModelReference());
50:         }
51:
52:         private String buildSchemaPath(VFeaturePathDomainModelReference reference) {
53:                 final StringBuilder fragments = new StringBuilder(ROOT);
54:•                for (final EReference ref : reference.getDomainModelEReferencePath()) {
55:                         fragments.append(SEPARATOR);
56:•                        if (isArray(ref)) {
57:                                 fragments.append(ITEMS);
58:                         } else {
59:                                 fragments.append(PROPERTIES);
60:                         }
61:                         fragments.append(SEPARATOR);
62:                         fragments.append(ref.getName());
63:                 }
64:
65:                 fragments.append(SEPARATOR);
66:                 fragments.append(PROPERTIES);
67:                 fragments.append(SEPARATOR);
68:                 fragments.append(reference.getDomainModelEFeature().getName());
69:                 return fragments.toString();
70:         }
71:
72:         private static boolean isArray(EReference ref) {
73:•                return ref.getUpperBound() > 1;
74:         }
75:
76:         /**
77:          * Allows to add an ecore path to the current view model.
78:          *
79:          * @param ecorePath The path to the ecore of the current view model
80:          */
81:         public void addEcorePath(String ecorePath) {
82:                 ecorePaths.add(ecorePath);
83:         }
84:
85:         @Override
86:         protected Set<String> getEcorePaths() {
87:                 return ecorePaths;
88:         }
89: }