Skip to content

Package: ECPUtil

ECPUtil

nameinstructionbranchcomplexitylinemethod
createProperties()
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%
getAllRegisteredEPackages()
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%
getECPObserverBus()
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%
getECPProjectManager()
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%
getECPProviderRegistry()
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%
getECPRepositoryManager()
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%
getModelContext(ECPModelContextProvider, Object[])
M: 38 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
getResolvedElement(ECPElement)
M: 2 C: 9
82%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 3
75%
M: 0 C: 1
100%
getSubClasses(EClass)
M: 65 C: 0
0%
M: 14 C: 0
0%
M: 8 C: 0
0%
M: 15 C: 0
0%
M: 1 C: 0
0%
isClosed(Object)
M: 15 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
isDisposed(Object)
M: 11 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%

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: * Eike Stepper - initial API and implementation
13: * Eugen Neufeld - JavaDoc
14: *
15: *******************************************************************************/
16:
17: package org.eclipse.emf.ecp.core.util;
18:
19: import java.util.ArrayList;
20: import java.util.Collection;
21: import java.util.HashSet;
22: import java.util.List;
23: import java.util.Set;
24:
25: import org.eclipse.emf.ecore.EClass;
26: import org.eclipse.emf.ecore.EClassifier;
27: import org.eclipse.emf.ecore.EPackage;
28: import org.eclipse.emf.ecore.EPackage.Registry;
29: import org.eclipse.emf.ecp.common.spi.EMFUtils;
30: import org.eclipse.emf.ecp.core.ECPProject;
31: import org.eclipse.emf.ecp.core.ECPProjectManager;
32: import org.eclipse.emf.ecp.core.ECPProviderRegistry;
33: import org.eclipse.emf.ecp.core.ECPRepositoryManager;
34: import org.eclipse.emf.ecp.core.util.observer.ECPObserverBus;
35: import org.eclipse.emf.ecp.internal.core.Activator;
36: import org.eclipse.emf.ecp.internal.core.util.ElementDescriptor;
37: import org.eclipse.emf.ecp.internal.core.util.Properties;
38: import org.eclipse.emf.ecp.spi.core.util.ECPDisposable;
39:
40: /**
41: * This class provides common functionality.
42: *
43: * @author Eike Stepper
44: * @author Eugen Neufeld
45: */
46: public final class ECPUtil {
47:
48:         private ECPUtil() {
49:         }
50:
51:         /**
52:          * Return the common {@link ECPContainer} for the provided elements.
53:          *
54:          * @param contextProvider the {@link ECPModelContextProvider} to use
55:          * @param elements the elements to check
56:          * @return the common {@link ECPContainer} for the elements or null
57:          */
58:         public static ECPContainer getModelContext(ECPModelContextProvider contextProvider, Object... elements) {
59:                 ECPContainer commonContext = null;
60:•                for (final Object element : elements) {
61:                         final ECPContainer elementContext = contextProvider.getModelContext(element);
62:•                        if (elementContext == null) {
63:                                 return null;
64:                         }
65:
66:•                        if (elementContext != commonContext) {
67:•                                if (commonContext == null) {
68:                                         commonContext = elementContext;
69:                                 } else {
70:                                         return null;
71:                                 }
72:                         }
73:                 }
74:
75:                 return commonContext;
76:         }
77:
78:         /**
79:          * This creates an empty {@link ECPProperties}.
80:          *
81:          * @return an empty {@link ECPProperties}
82:          */
83:         public static ECPProperties createProperties() {
84:                 return new Properties();
85:         }
86:
87:         /**
88:          * Checks whether an object is an {@link ECPDisposable} and disposed.
89:          *
90:          * @param object the object to check
91:          * @return true if the object is an instance of {@link ECPDisposable} and {@link ECPDisposable#isDisposed()} returns
92:          * true, false otherwise
93:          */
94:         public static boolean isDisposed(Object object) {
95:•                if (object instanceof ECPDisposable) {
96:                         final ECPDisposable disposable = (ECPDisposable) object;
97:                         return disposable.isDisposed();
98:                 }
99:
100:                 return false;
101:         }
102:
103:         /**
104:          * Checks whether an object is an {@link ECPProject} and closed.
105:          *
106:          * @param object the object to check
107:          * @return true if the object is an instance of {@link ECPProject} and not open, false otherwise
108:          */
109:         public static boolean isClosed(Object object) {
110:•                if (object instanceof ECPProject) {
111:                         final ECPProject closeable = (ECPProject) object;
112:•                        return !closeable.isOpen();
113:                 }
114:
115:                 return false;
116:         }
117:
118:         /**
119:          * Checks whether the {@link ECPElement} is an {@link ElementDescriptor} and resolves it when necessary.
120:          *
121:          * @param elementOrDescriptor the {@link ECPElement} to check
122:          * @return the resolved Object or the original object if it is not an descriptor
123:          */
124:         public static ECPElement getResolvedElement(ECPElement elementOrDescriptor) {
125:•                if (elementOrDescriptor instanceof ElementDescriptor) {
126:                         final ElementDescriptor<?> descriptor = (ElementDescriptor<?>) elementOrDescriptor;
127:                         return descriptor.getResolvedElement();
128:                 }
129:
130:                 return elementOrDescriptor;
131:         }
132:
133:         /**
134:          * This method looks through all known {@link EPackage}s to find all subclasses for the provided super class.
135:          *
136:          * @param superClass
137:          * - the class for which to get the subclasses
138:          * @return a {@link Collection} of {@link EClass EClasses}
139:          * @deprecated Use {@link EMFUtils}.getSubClasses instead
140:          */
141:         @Deprecated
142:         public static Collection<EClass> getSubClasses(EClass superClass) {
143:                 final Collection<EClass> classes = new HashSet<EClass>();
144:
145:                 // avoid ConcurrentModificationException while iterating over the registry's key set
146:                 final List<String> keySet = new ArrayList<String>(Registry.INSTANCE.keySet());
147:•                for (final String nsURI : keySet) {
148:                         EPackage ePackage;
149:                         try {
150:                                 ePackage = Registry.INSTANCE.getEPackage(nsURI);
151:                         }
152:                         // BEGIN SUPRESS CATCH EXCEPTION
153:                         catch (final Exception ex) {// END SUPRESS CATCH EXCEPTION
154:                                 /* If there is a wrongly configured EPackage the call to getEPackage might throw a runtime exception */
155:                                 /* Catch here, so we can still loop through the whole registry */
156:                                 continue;
157:                         }
158:•                        if (ePackage == null) {
159:                                 /* possible! */
160:                                 continue;
161:                         }
162:•                        for (final EClassifier eClassifier : ePackage.getEClassifiers()) {
163:•                                if (eClassifier instanceof EClass) {
164:                                         final EClass eClass = (EClass) eClassifier;
165:•                                        if (superClass.isSuperTypeOf(eClass) && !eClass.isAbstract() && !eClass.isInterface()) {
166:                                                 classes.add(eClass);
167:                                         }
168:                                 }
169:                         }
170:                 }
171:                 return classes;
172:         }
173:
174:         /**
175:          * Returns the set of all known {@link EPackage EPackages}.
176:          *
177:          * @return the Set of all known {@link EPackage Epackages}
178:          */
179:         public static Set<EPackage> getAllRegisteredEPackages() {
180:                 return EMFUtils.getAllRegisteredEPackages();
181:         }
182:
183:         /**
184:          * Helper method to get the instance of the {@link ECPProjectManager}.
185:          *
186:          * @return the {@link ECPProjectManager}
187:          */
188:         public static ECPProjectManager getECPProjectManager() {
189:
190:                 final ECPProjectManager ecpProjectManagerInstance = Activator.getECPProjectManager();
191:
192:                 return ecpProjectManagerInstance;
193:         }
194:
195:         /**
196:          * Helper method to get the instance of the {@link ECPRepositoryManager}.
197:          *
198:          * @return the {@link ECPRepositoryManager}
199:          */
200:         public static ECPRepositoryManager getECPRepositoryManager() {
201:
202:                 final ECPRepositoryManager epm = Activator.getECPRepositoryManager();
203:
204:                 return epm;
205:         }
206:
207:         /**
208:          * Helper method to get the instance of the {@link ECPProviderRegistry}.
209:          *
210:          * @return the {@link ECPProviderRegistry}
211:          */
212:         public static ECPProviderRegistry getECPProviderRegistry() {
213:
214:                 final ECPProviderRegistry ecpProviderRegistryInstance = Activator.getECPProviderRegistry();
215:
216:                 return ecpProviderRegistryInstance;
217:         }
218:
219:         /**
220:          * Helper method to get the instance of the {@link ECPObserverBus}.
221:          *
222:          * @return the {@link ECPObserverBus}
223:          */
224:         public static ECPObserverBus getECPObserverBus() {
225:                 return Activator.getECPObserverBus();
226:         }
227:
228: }