Skip to content

Package: EcoreHelpers

EcoreHelpers

nameinstructionbranchcomplexitylinemethod
filterGenericElements(Object[])
M: 0 C: 30
100%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 5
100%
M: 0 C: 1
100%
isGenericElement(Object)
M: 2 C: 10
83%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 0 C: 2
100%
M: 0 C: 1
100%
isGenericFeature(Object)
M: 0 C: 19
100%
M: 3 C: 7
70%
M: 3 C: 3
50%
M: 0 C: 5
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: * Clemens Elflein - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.internal.editor.ecore.helpers;
15:
16: import java.util.LinkedList;
17: import java.util.List;
18:
19: import org.eclipse.emf.ecore.EcorePackage;
20:
21: /**
22: * Provides methods to simplify working with Ecore files.
23: */
24: public final class EcoreHelpers {
25:
26:         private EcoreHelpers() {
27:         }
28:
29:         /**
30:          * Checks if the feature is generic.
31:          *
32:          * @param feature The feature to check
33:          * @return true, if the provided feature is generic
34:          */
35:         public static boolean isGenericFeature(Object feature) {
36:•                return feature == EcorePackage.Literals.ECLASS__EGENERIC_SUPER_TYPES ||
37:•                        feature == EcorePackage.Literals.ECLASSIFIER__ETYPE_PARAMETERS ||
38:•                        feature == EcorePackage.Literals.EOPERATION__EGENERIC_EXCEPTIONS ||
39:•                        feature == EcorePackage.Literals.EOPERATION__ETYPE_PARAMETERS ||
40:•                        feature == EcorePackage.Literals.ETYPED_ELEMENT__EGENERIC_TYPE;
41:         }
42:
43:         /**
44:          * Checks if the given element is generic.
45:          *
46:          * @param element The element to check
47:          * @return true, if the element is generic.
48:          */
49:         public static boolean isGenericElement(Object element) {
50:•                return EcorePackage.Literals.EGENERIC_TYPE.isInstance(element) ||
51:•                        EcorePackage.Literals.ETYPE_PARAMETER.isInstance(element);
52:         }
53:
54:         /**
55:          * Removes all generic elements from a list of elements.
56:          *
57:          * @param elements The list of elements to be filtered
58:          * @return a list without generic elements
59:          */
60:         public static Object[] filterGenericElements(Object[] elements) {
61:                 final List<Object> elementList = new LinkedList<Object>();
62:•                for (final Object e : elements) {
63:•                        if (!isGenericElement(e)) {
64:                                 elementList.add(e);
65:                         }
66:                 }
67:                 return elementList.toArray();
68:         }
69: }