Skip to content

Package: ECPProjectAdapterFactory

ECPProjectAdapterFactory

nameinstructionbranchcomplexitylinemethod
ECPProjectAdapterFactory()
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%
adapt(Object, Class)
M: 29 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
getAdapter(Object, Class)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getAdapterList()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011 Eike Stepper (Berlin, Germany) 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: *******************************************************************************/
14: package org.eclipse.emf.ecp.cdo.internal.core;
15:
16: import org.eclipse.core.runtime.IAdapterFactory;
17: import org.eclipse.emf.cdo.workspace.CDOWorkspace;
18: import org.eclipse.emf.ecp.core.ECPProject;
19: import org.eclipse.emf.ecp.spi.core.InternalProject;
20:
21: /**
22: * @author Eike Stepper
23: */
24: @SuppressWarnings({ "unchecked", "rawtypes" })
25: public class ECPProjectAdapterFactory implements IAdapterFactory {
26:         private static final Class[] CLASSES = { CDOWorkspace.class };
27:
28:         /**
29:          * {@inheritDoc}
30:          *
31:          * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
32:          */
33:         @Override
34:         public Class[] getAdapterList() {
35:                 return CLASSES;
36:         }
37:
38:         /**
39:          * {@inheritDoc}
40:          *
41:          * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
42:          */
43:         @Override
44:         public Object getAdapter(Object adaptable, Class adapterType) {
45:                 return adapt(adaptable, adapterType);
46:         }
47:
48:         /**
49:          * Adapt the given adaptable to the given type.
50:          *
51:          * @param adaptable an adaptable
52:          * @param adapterType the target type
53:          * @param <T> the type of the adapter
54:          * @return an object of type <T> if supported or null
55:          */
56:         public static <T> T adapt(Object adaptable, Class<T> adapterType) {
57:•                if (adapterType == CLASSES[0]) {
58:•                        if (adaptable instanceof ECPProject) {
59:                                 final ECPProject project = (ECPProject) adaptable;
60:•                                if (project.isOpen() && project.getProvider().getName().equals(CDOProvider.NAME)) {
61:                                         final CDOProjectData data = CDOProvider.getProjectData((InternalProject) project);
62:                                         return (T) data.getWorkspace();
63:                                 }
64:                         }
65:                 }
66:
67:                 return null;
68:         }
69: }