Skip to content

Package: ECPStaticApplicableTester

ECPStaticApplicableTester

nameinstructionbranchcomplexitylinemethod
ECPStaticApplicableTester(boolean, int, Class, Class, String)
M: 0 C: 18
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
checkAttributeInvalid(EAttribute)
M: 30 C: 23
43%
M: 5 C: 5
50%
M: 4 C: 2
33%
M: 13 C: 7
35%
M: 0 C: 1
100%
getPriority()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getSupportedClassType()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getSupportedEObject()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getSupportedFeature()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
isApplicable(EObject, EStructuralFeature)
M: 29 C: 29
50%
M: 11 C: 7
39%
M: 7 C: 3
30%
M: 8 C: 8
50%
M: 0 C: 1
100%
isApplicable(IItemPropertyDescriptor, EObject)
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%
isApplicable(VDomainModelReference)
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%
isSingleValue()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
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: * Eugen Neufeld - initial API and implementation
13: *
14: *******************************************************************************/
15: package org.eclipse.emf.ecp.edit.spi.util;
16:
17: import org.eclipse.emf.ecore.EAttribute;
18: import org.eclipse.emf.ecore.EObject;
19: import org.eclipse.emf.ecore.EReference;
20: import org.eclipse.emf.ecore.EStructuralFeature;
21: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
22: import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
23:
24: /**
25: * The implementation of the {@link ECPApplicableTester} for a static test, like defined in the staticTest element.
26: *
27: * @author Eugen Neufeld
28: *
29: */
30: @Deprecated
31: public final class ECPStaticApplicableTester implements ECPApplicableTester {
32:
33:         private final boolean singleValue;
34:         private final int priority;
35:         private final Class<?> supportedClassType;
36:         private final Class<? extends EObject> supportedEObject;
37:         private final String supportedFeature;
38:
39:         /**
40:          * The constructor of the static tester.
41:          *
42:          * @param singleValue whether the corresponding control supports only single valued features
43:          * @param priority the static priority
44:          * @param supportedClassType the class of the supported type
45:          * @param supportedEObject the eobject this tester allows
46:          * @param supportedFeature the feature this tester allows
47:          */
48:         public ECPStaticApplicableTester(boolean singleValue, int priority, Class<?> supportedClassType,
49:                 Class<? extends EObject> supportedEObject, String supportedFeature) {
50:                 this.singleValue = singleValue;
51:                 this.priority = priority;
52:                 this.supportedClassType = supportedClassType;
53:                 this.supportedEObject = supportedEObject;
54:                 this.supportedFeature = supportedFeature;
55:         }
56:
57:         /**
58:          * {@inheritDoc}
59:          */
60:         @Override
61:         @Deprecated
62:         public int isApplicable(IItemPropertyDescriptor itemPropertyDescriptor, EObject eObject) {
63:                 return isApplicable(eObject, (EStructuralFeature) itemPropertyDescriptor.getFeature(eObject));
64:         }
65:
66:         /**
67:          * {@inheritDoc}
68:          *
69:          * @see org.eclipse.emf.ecp.edit.spi.util.ECPApplicableTester#isApplicable(org.eclipse.emf.ecp.view.spi.model.VDomainModelReference)
70:          * @since 1.2
71:          * @deprecated
72:          */
73:         @Deprecated
74:         @Override
75:         public int isApplicable(VDomainModelReference domainModelReference) {
76:                 return NOT_APPLICABLE;
77:         }
78:
79:         /**
80:          * {@inheritDoc}
81:          *
82:          * @see org.eclipse.emf.ecp.edit.spi.util.ECPApplicableTester#isApplicable(org.eclipse.emf.ecore.EObject,
83:          * org.eclipse.emf.ecore.EStructuralFeature)
84:          * @since 1.2
85:          * @deprecated
86:          */
87:         @Deprecated
88:         @Override
89:         public int isApplicable(EObject eObject, EStructuralFeature feature) {
90:                 // if the feature is a multiValue and the description is a singlevalue continue
91:•                if (isSingleValue() == feature.isMany()) {
92:                         return NOT_APPLICABLE;
93:                 }
94:                 // if we have an attribute
95:•                if (EAttribute.class.isInstance(feature)) {
96:•                        if (checkAttributeInvalid((EAttribute) feature)) {
97:                                 return NOT_APPLICABLE;
98:                         }
99:                 }
100:                 // if we have an reference the the classes
101:•                else if (EReference.class.isInstance(feature)) {
102:                         Class<?> instanceClass = feature.getEType().getInstanceClass();
103:•                        if (instanceClass == null) {
104:                                 instanceClass = EObject.class;
105:                         }
106:•                        if (!getSupportedClassType().isAssignableFrom(instanceClass)) {
107:                                 return NOT_APPLICABLE;
108:                         }
109:                 }
110:                 // if the supported eobject is assignable from the current eobject and the supported feature is eitehr null or
111:                 // equals the current one
112:•                if (getSupportedEObject().isInstance(eObject)
113:•                        && (getSupportedFeature() == null || feature.equals(eObject.eClass().getEStructuralFeature(
114:•                                getSupportedFeature())))) {
115:                         return getPriority();
116:                 }
117:                 return NOT_APPLICABLE;
118:         }
119:
120:         /**
121:          * @return
122:          *
123:          */
124:         private boolean checkAttributeInvalid(EAttribute attribute) {
125:                 final Class<?> instanceClass = attribute.getEAttributeType().getInstanceClass();
126:•                if (instanceClass == null) {
127:                         return true;
128:                 }
129:•                if (Object.class.equals(getSupportedClassType())) {
130:                         return false;
131:                 }
132:                 // if the attribute class is an primitive test the primitive types
133:•                if (instanceClass.isPrimitive()) {
134:                         try {
135:                                 final Class<?> primitive = (Class<?>) getSupportedClassType().getField("TYPE").get(null); //$NON-NLS-1$
136:•                                if (!primitive.equals(instanceClass)) {
137:                                         return true;
138:                                 }
139:
140:                         } catch (final IllegalArgumentException e) {
141:                                 return true;
142:                         } catch (final SecurityException e) {
143:                                 return true;
144:                         } catch (final IllegalAccessException e) {
145:                                 return true;
146:                         } catch (final NoSuchFieldException e) {
147:                                 return true;
148:                         }
149:                 }
150:                 // otherwise test the classes itself
151:•                else if (!getSupportedClassType().isAssignableFrom(instanceClass)) {
152:                         return true;
153:                 }
154:
155:                 return false;
156:         }
157:
158:         /**
159:          * Whether the corresponding control is allowed only for single values.
160:          *
161:          * @return true if only a single value is allows
162:          */
163:         public boolean isSingleValue() {
164:                 return singleValue;
165:         }
166:
167:         /**
168:          * The static priority of the corresponding control.
169:          *
170:          * @return the priority
171:          */
172:         public int getPriority() {
173:                 return priority;
174:         }
175:
176:         /**
177:          * The eobejct which is supported by the corresponding control.
178:          *
179:          * @return the class of the supported eobejct
180:          */
181:         public Class<? extends EObject> getSupportedEObject() {
182:                 return supportedEObject;
183:         }
184:
185:         /**
186:          * The name of the feature the corresponding control supports.
187:          *
188:          * @return the name of the supported feature
189:          */
190:         public String getSupportedFeature() {
191:                 return supportedFeature;
192:         }
193:
194:         /**
195:          * The class of the type the corresponding control supports.
196:          *
197:          * @return the class of the supported type
198:          */
199:         public Class<?> getSupportedClassType() {
200:                 return supportedClassType;
201:         }
202:
203: }