|
Lines 1-7
Link Here
|
| 1 |
/** |
1 |
/** |
| 2 |
* <copyright> |
2 |
* <copyright> |
| 3 |
* |
3 |
* |
| 4 |
* Copyright (c) 2004-2007 IBM Corporation and others. |
4 |
* Copyright (c) 2004-2009 IBM Corporation and others. |
| 5 |
* All rights reserved. This program and the accompanying materials |
5 |
* All rights reserved. This program and the accompanying materials |
| 6 |
* are made available under the terms of the Eclipse Public License v1.0 |
6 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 7 |
* which accompanies this distribution, and is available at |
7 |
* which accompanies this distribution, and is available at |
|
Lines 35-50
Link Here
|
| 35 |
import org.eclipse.emf.common.util.EMap; |
35 |
import org.eclipse.emf.common.util.EMap; |
| 36 |
import org.eclipse.emf.common.util.ResourceLocator; |
36 |
import org.eclipse.emf.common.util.ResourceLocator; |
| 37 |
|
37 |
|
| 38 |
import org.eclipse.emf.ecore.EValidator; |
|
|
| 39 |
|
| 40 |
import org.eclipse.emf.ecore.EAttribute; |
38 |
import org.eclipse.emf.ecore.EAttribute; |
| 41 |
import org.eclipse.emf.ecore.EObject; |
|
|
| 42 |
import org.eclipse.emf.ecore.EClass; |
39 |
import org.eclipse.emf.ecore.EClass; |
| 43 |
import org.eclipse.emf.ecore.EReference; |
|
|
| 44 |
import org.eclipse.emf.ecore.EcorePackage; |
| 45 |
import org.eclipse.emf.ecore.EDataType; |
40 |
import org.eclipse.emf.ecore.EDataType; |
|
|
41 |
import org.eclipse.emf.ecore.EObject; |
| 42 |
import org.eclipse.emf.ecore.EOperation; |
| 46 |
import org.eclipse.emf.ecore.EPackage; |
43 |
import org.eclipse.emf.ecore.EPackage; |
|
|
44 |
import org.eclipse.emf.ecore.EReference; |
| 47 |
import org.eclipse.emf.ecore.EStructuralFeature; |
45 |
import org.eclipse.emf.ecore.EStructuralFeature; |
|
|
46 |
import org.eclipse.emf.ecore.EValidator; |
| 47 |
import org.eclipse.emf.ecore.EcorePackage; |
| 48 |
import org.eclipse.emf.ecore.InternalEObject; |
48 |
import org.eclipse.emf.ecore.InternalEObject; |
| 49 |
|
49 |
|
| 50 |
import org.eclipse.emf.ecore.plugin.EcorePlugin; |
50 |
import org.eclipse.emf.ecore.plugin.EcorePlugin; |
|
Lines 166-171
Link Here
|
| 166 |
} |
166 |
} |
| 167 |
|
167 |
|
| 168 |
/** |
168 |
/** |
|
|
169 |
* @since 2.6 |
| 170 |
*/ |
| 171 |
protected static EValidator.ValidationDelegate.Registry getValidationDelegateRegistry(Map<Object, Object> context) |
| 172 |
{ |
| 173 |
if (context != null) |
| 174 |
{ |
| 175 |
EValidator.ValidationDelegate.Registry result = (EValidator.ValidationDelegate.Registry)context.get(EValidator.ValidationDelegate.Registry.class); |
| 176 |
if (result != null) |
| 177 |
{ |
| 178 |
return result; |
| 179 |
} |
| 180 |
} |
| 181 |
|
| 182 |
return EValidator.ValidationDelegate.Registry.INSTANCE; |
| 183 |
} |
| 184 |
|
| 185 |
/** |
| 186 |
* @since 2.6 |
| 187 |
*/ |
| 188 |
public static boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context, String validationDelegate, EOperation invariant, String expression, int severity, String source, int code) |
| 189 |
{ |
| 190 |
ValidationDelegate delegate = getValidationDelegateRegistry(context).getValidationDelegate(validationDelegate); |
| 191 |
if (delegate != null) |
| 192 |
{ |
| 193 |
try |
| 194 |
{ |
| 195 |
if (!delegate.validate(eClass, eObject, context, invariant, expression)) |
| 196 |
{ |
| 197 |
if (diagnostics != null) |
| 198 |
reportInvariantDelegateViolation(eClass, eObject, diagnostics, context, invariant, severity, source, code); |
| 199 |
return false; |
| 200 |
} |
| 201 |
} |
| 202 |
catch (Throwable throwable) |
| 203 |
{ |
| 204 |
if (diagnostics != null) |
| 205 |
reportInvariantDelegateException(eClass, eObject, diagnostics, context, invariant, severity, source, code, throwable); |
| 206 |
} |
| 207 |
} |
| 208 |
else |
| 209 |
{ |
| 210 |
if (diagnostics != null) |
| 211 |
reportInvariantDelegateNotFound(eClass, eObject, diagnostics, context, invariant, severity, source, code, validationDelegate); |
| 212 |
} |
| 213 |
return true; |
| 214 |
} |
| 215 |
|
| 216 |
/** |
| 217 |
* @since 2.6 |
| 218 |
*/ |
| 219 |
public static boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context, String validationDelegate, String constraint, String expression, int severity, String source, int code) |
| 220 |
{ |
| 221 |
ValidationDelegate delegate = getValidationDelegateRegistry(context).getValidationDelegate(validationDelegate); |
| 222 |
if (delegate != null) |
| 223 |
{ |
| 224 |
try |
| 225 |
{ |
| 226 |
if (!delegate.validate(eClass, eObject, context, constraint, expression)) |
| 227 |
{ |
| 228 |
if (diagnostics != null) |
| 229 |
reportConstraintDelegateViolation(eClass, eObject, diagnostics, context, constraint, severity, source, code); |
| 230 |
return false; |
| 231 |
} |
| 232 |
} |
| 233 |
catch (Throwable throwable) |
| 234 |
{ |
| 235 |
if (diagnostics != null) |
| 236 |
reportConstraintDelegateException(eClass, eObject, diagnostics, context, constraint, severity, source, code, throwable); |
| 237 |
} |
| 238 |
} |
| 239 |
else |
| 240 |
{ |
| 241 |
if (diagnostics != null) |
| 242 |
reportConstraintDelegateNotFound(eClass, eObject, diagnostics, context, constraint, severity, source, code, validationDelegate); |
| 243 |
} |
| 244 |
return true; |
| 245 |
} |
| 246 |
|
| 247 |
/** |
| 248 |
* @since 2.6 |
| 249 |
*/ |
| 250 |
public static boolean validate(EDataType eDataType, Object value, DiagnosticChain diagnostics, Map<Object, Object> context, String validationDelegate, String constraint, String expression, int severity, String source, int code) |
| 251 |
{ |
| 252 |
ValidationDelegate delegate = getValidationDelegateRegistry(context).getValidationDelegate(validationDelegate); |
| 253 |
if (delegate != null) |
| 254 |
{ |
| 255 |
try |
| 256 |
{ |
| 257 |
if (!delegate.validate(eDataType, value, context, constraint, expression)) |
| 258 |
{ |
| 259 |
if (diagnostics != null) |
| 260 |
reportConstraintDelegateViolation(eDataType, value, diagnostics, context, constraint, severity, source, code); |
| 261 |
return false; |
| 262 |
} |
| 263 |
} |
| 264 |
catch (Throwable throwable) |
| 265 |
{ |
| 266 |
if (diagnostics != null) |
| 267 |
reportConstraintDelegateException(eDataType, value, diagnostics, context, constraint, severity, source, code, throwable); |
| 268 |
} |
| 269 |
} |
| 270 |
else |
| 271 |
{ |
| 272 |
if (diagnostics != null) |
| 273 |
reportConstraintDelegateNotFound(eDataType, value, diagnostics, context, constraint, severity, source, code, validationDelegate); |
| 274 |
} |
| 275 |
return true; |
| 276 |
} |
| 277 |
|
| 278 |
/** |
| 169 |
* Validates the object in the given context, optionally producing diagnostics. |
279 |
* Validates the object in the given context, optionally producing diagnostics. |
| 170 |
* @param diagnostics a place to accumulate diagnostics; if it's <code>null</code>, no diagnostics should be produced. |
280 |
* @param diagnostics a place to accumulate diagnostics; if it's <code>null</code>, no diagnostics should be produced. |
| 171 |
* @param context a place to cache information, if it's <code>null</code>, no cache is supported. |
281 |
* @param context a place to cache information, if it's <code>null</code>, no cache is supported. |
|
Lines 184-194
Link Here
|
| 184 |
} |
294 |
} |
| 185 |
else |
295 |
else |
| 186 |
{ |
296 |
{ |
| 187 |
List<EClass> eSuperTypes = eClass.getESuperTypes(); |
297 |
return new DynamicEClassValidator() |
| 188 |
return |
298 |
{ |
| 189 |
eSuperTypes.isEmpty() ? |
299 |
// Ensure that the class loader for this class will be used downstream. |
| 190 |
validate_EveryDefaultConstraint(eObject, diagnostics, context) : |
300 |
// |
| 191 |
validate(eSuperTypes.get(0), eObject, diagnostics, context); |
301 |
}.validate(eClass, eObject, diagnostics, context); |
| 192 |
} |
302 |
} |
| 193 |
} |
303 |
} |
| 194 |
|
304 |
|
|
Lines 836-849
Link Here
|
| 836 |
} |
946 |
} |
| 837 |
} |
947 |
} |
| 838 |
|
948 |
|
| 839 |
public boolean validate(EDataType eDataType, Object value, DiagnosticChain diagnostics, Map<Object, Object> context) |
949 |
protected boolean validateDelegatedConstraints(EDataType eDataType, Object value, DiagnosticChain diagnostics, Map<Object, Object> context) |
| 840 |
{ |
950 |
{ |
| 841 |
boolean result = true; |
951 |
boolean result = true; |
|
|
952 |
List<String> validationDelegates = EcoreUtil.getValidationDelegates(eDataType.getEPackage()); |
| 953 |
|
| 954 |
if (!validationDelegates.isEmpty()) |
| 955 |
{ |
| 956 |
CONSTRAINTS: for (String constraint : EcoreUtil.getConstraints(eDataType)) |
| 957 |
{ |
| 958 |
for (String validationDelegate : validationDelegates) |
| 959 |
{ |
| 960 |
String expression = EcoreUtil.getAnnotation(eDataType, validationDelegate, constraint); |
| 961 |
if (expression != null) |
| 962 |
{ |
| 963 |
result &= EObjectValidator.validate(eDataType, value, diagnostics, context, validationDelegate, constraint, expression, Diagnostic.ERROR, DIAGNOSTIC_SOURCE, 0); |
| 964 |
if (!result && diagnostics == null) |
| 965 |
break CONSTRAINTS; |
| 966 |
} |
| 967 |
} |
| 968 |
} |
| 969 |
} |
| 970 |
|
| 971 |
return result; |
| 972 |
} |
| 973 |
|
| 974 |
protected boolean validateSchemaConstraints(EDataType eDataType, Object value, DiagnosticChain diagnostics, Map<Object, Object> context) |
| 975 |
{ |
| 976 |
boolean result = true; |
| 977 |
|
| 842 |
if (effectiveEnumeration != null) |
978 |
if (effectiveEnumeration != null) |
| 843 |
{ |
979 |
{ |
| 844 |
if (!effectiveEnumeration.contains(value)) |
980 |
if (!effectiveEnumeration.contains(value)) |
| 845 |
{ |
981 |
{ |
| 846 |
if (diagnostics != null) reportEnumerationViolation(eDataType, value, effectiveEnumeration, diagnostics, context); |
982 |
if (diagnostics != null) |
|
|
983 |
reportEnumerationViolation(eDataType, value, effectiveEnumeration, diagnostics, context); |
| 847 |
result = false; |
984 |
result = false; |
| 848 |
} |
985 |
} |
| 849 |
} |
986 |
} |
|
Lines 855-864
Link Here
|
| 855 |
|
992 |
|
| 856 |
if (effectiveMin != null) |
993 |
if (effectiveMin != null) |
| 857 |
{ |
994 |
{ |
| 858 |
@SuppressWarnings("unchecked") Comparable<Object> comparableObject = (Comparable<Object>)effectiveMin; |
995 |
@SuppressWarnings("unchecked") |
| 859 |
if (effectiveMinIsInclusive ? |
996 |
Comparable<Object> comparableObject = (Comparable<Object>)effectiveMin; |
| 860 |
comparableObject.compareTo(value) > 0: |
997 |
if (effectiveMinIsInclusive ? comparableObject.compareTo(value) > 0 : comparableObject.compareTo(value) >= 0) |
| 861 |
comparableObject.compareTo(value) >= 0) |
|
|
| 862 |
{ |
998 |
{ |
| 863 |
if (diagnostics != null) |
999 |
if (diagnostics != null) |
| 864 |
{ |
1000 |
{ |
|
Lines 877-886
Link Here
|
| 877 |
|
1013 |
|
| 878 |
if (effectiveMax != null) |
1014 |
if (effectiveMax != null) |
| 879 |
{ |
1015 |
{ |
| 880 |
@SuppressWarnings("unchecked") Comparable<Object> comparableObject = (Comparable<Object>)effectiveMax; |
1016 |
@SuppressWarnings("unchecked") |
| 881 |
if (effectiveMaxIsInclusive ? |
1017 |
Comparable<Object> comparableObject = (Comparable<Object>)effectiveMax; |
| 882 |
comparableObject.compareTo(value) < 0: |
1018 |
if (effectiveMaxIsInclusive ? comparableObject.compareTo(value) < 0 : comparableObject.compareTo(value) <= 0) |
| 883 |
comparableObject.compareTo(value) <= 0) |
|
|
| 884 |
{ |
1019 |
{ |
| 885 |
if (diagnostics != null) |
1020 |
if (diagnostics != null) |
| 886 |
{ |
1021 |
{ |
|
Lines 944-983
Link Here
|
| 944 |
result = false; |
1079 |
result = false; |
| 945 |
} |
1080 |
} |
| 946 |
} |
1081 |
} |
|
|
1082 |
|
| 1083 |
return result; |
| 1084 |
} |
| 1085 |
|
| 1086 |
public boolean validate(EDataType eDataType, Object value, DiagnosticChain diagnostics, Map<Object, Object> context) |
| 1087 |
{ |
| 1088 |
boolean result = validateDelegatedConstraints(eDataType, value, diagnostics, context); |
| 947 |
|
1089 |
|
| 948 |
if (itemType != null) |
1090 |
if (result || diagnostics != null) |
| 949 |
{ |
1091 |
{ |
| 950 |
EValidator rootValidator = getRootEValidator(context); |
1092 |
result &= validateSchemaConstraints(eDataType, value, diagnostics, context); |
| 951 |
for (Iterator<?> i = ((List<?>)value).iterator(); i.hasNext() && (result || diagnostics != null); ) |
1093 |
|
|
|
1094 |
if (itemType != null) |
| 1095 |
{ |
| 1096 |
EValidator rootValidator = getRootEValidator(context); |
| 1097 |
for (Iterator< ? > i = ((List< ? >)value).iterator(); i.hasNext() && (result || diagnostics != null);) |
| 1098 |
{ |
| 1099 |
result &= rootValidator.validate(itemType, i.next(), diagnostics, context); |
| 1100 |
} |
| 1101 |
return result; |
| 1102 |
} |
| 1103 |
else if (!memberTypes.isEmpty()) |
| 952 |
{ |
1104 |
{ |
| 953 |
result &= rootValidator.validate(itemType, i.next(), diagnostics, context); |
1105 |
EValidator rootValidator = getRootEValidator(context); |
|
|
1106 |
|
| 1107 |
for (EDataType memberType : memberTypes) |
| 1108 |
{ |
| 1109 |
if (rootValidator.validate(memberType, value, null, context)) |
| 1110 |
{ |
| 1111 |
return true; |
| 1112 |
} |
| 1113 |
} |
| 1114 |
for (EDataType memberType : memberTypes) |
| 1115 |
{ |
| 1116 |
if (memberType.isInstance(value)) |
| 1117 |
{ |
| 1118 |
return rootValidator.validate(memberType, value, diagnostics, context); |
| 1119 |
} |
| 1120 |
} |
| 1121 |
return false; |
| 1122 |
} |
| 1123 |
else |
| 1124 |
{ |
| 1125 |
return result; |
| 954 |
} |
1126 |
} |
| 955 |
return result; |
|
|
| 956 |
} |
1127 |
} |
| 957 |
else if (!memberTypes.isEmpty()) |
1128 |
|
|
|
1129 |
return result; |
| 1130 |
} |
| 1131 |
} |
| 1132 |
|
| 1133 |
public class DynamicEClassValidator |
| 1134 |
{ |
| 1135 |
protected boolean validateDelegatedInvariants(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) |
| 1136 |
{ |
| 1137 |
boolean result = true; |
| 1138 |
List<String> validationDelegates = EcoreUtil.getValidationDelegates(eClass.getEPackage()); |
| 1139 |
|
| 1140 |
if (!validationDelegates.isEmpty()) |
| 958 |
{ |
1141 |
{ |
| 959 |
EValidator rootValidator = getRootEValidator(context); |
1142 |
INVARIANTS: for (EOperation eOperation : eClass.getEOperations()) |
| 960 |
|
|
|
| 961 |
for (EDataType memberType : memberTypes) |
| 962 |
{ |
1143 |
{ |
| 963 |
if (rootValidator.validate(memberType, value, null, context)) |
1144 |
if (EcoreUtil.isInvariant(eOperation)) |
| 964 |
{ |
1145 |
{ |
| 965 |
return true; |
1146 |
for (String validationDelegate : validationDelegates) |
|
|
1147 |
{ |
| 1148 |
String expression = EcoreUtil.getAnnotation(eOperation, validationDelegate, "body"); |
| 1149 |
if (expression != null) |
| 1150 |
{ |
| 1151 |
result &= EObjectValidator.validate(eClass, eObject, diagnostics, context, validationDelegate, eOperation, expression, Diagnostic.ERROR, DIAGNOSTIC_SOURCE, 0); |
| 1152 |
if (!result && diagnostics == null) |
| 1153 |
break INVARIANTS; |
| 1154 |
} |
| 1155 |
} |
| 966 |
} |
1156 |
} |
| 967 |
} |
1157 |
} |
| 968 |
for (EDataType memberType : memberTypes) |
1158 |
} |
|
|
1159 |
|
| 1160 |
return result; |
| 1161 |
} |
| 1162 |
|
| 1163 |
protected boolean validateDelegatedConstraints(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) |
| 1164 |
{ |
| 1165 |
boolean result = true; |
| 1166 |
List<String> validationDelegates = EcoreUtil.getValidationDelegates(eClass.getEPackage()); |
| 1167 |
|
| 1168 |
if (!validationDelegates.isEmpty()) |
| 1169 |
{ |
| 1170 |
CONSTRAINTS: for (String constraint : EcoreUtil.getConstraints(eClass)) |
| 969 |
{ |
1171 |
{ |
| 970 |
if (memberType.isInstance(value)) |
1172 |
for (String validationDelegate : validationDelegates) |
| 971 |
{ |
1173 |
{ |
| 972 |
return rootValidator.validate(memberType, value, diagnostics, context); |
1174 |
String expression = EcoreUtil.getAnnotation(eClass, validationDelegate, constraint); |
|
|
1175 |
if (expression != null) |
| 1176 |
{ |
| 1177 |
result &= EObjectValidator.validate(eClass, eObject, diagnostics, context, validationDelegate, constraint, expression, Diagnostic.ERROR, DIAGNOSTIC_SOURCE, 0); |
| 1178 |
if (!result && diagnostics == null) |
| 1179 |
break CONSTRAINTS; |
| 1180 |
} |
| 973 |
} |
1181 |
} |
| 974 |
} |
1182 |
} |
| 975 |
return false; |
|
|
| 976 |
} |
1183 |
} |
| 977 |
else |
1184 |
|
|
|
1185 |
return result; |
| 1186 |
} |
| 1187 |
|
| 1188 |
public boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) |
| 1189 |
{ |
| 1190 |
boolean result = validateDelegatedInvariants(eClass, eObject, diagnostics, context); |
| 1191 |
|
| 1192 |
if (result || diagnostics != null) |
| 978 |
{ |
1193 |
{ |
| 979 |
return result; |
1194 |
result &= validateDelegatedConstraints(eClass, eObject, diagnostics, context); |
|
|
1195 |
|
| 1196 |
if (result || diagnostics != null) |
| 1197 |
{ |
| 1198 |
List<EClass> eSuperTypes = eClass.getESuperTypes(); |
| 1199 |
result &= eSuperTypes.isEmpty() ? |
| 1200 |
validate_EveryDefaultConstraint(eObject, diagnostics, context) : |
| 1201 |
validate(eSuperTypes.get(0), eObject, diagnostics, context); |
| 1202 |
} |
| 980 |
} |
1203 |
} |
|
|
1204 |
|
| 1205 |
return result; |
| 981 |
} |
1206 |
} |
| 982 |
} |
1207 |
} |
| 983 |
|
1208 |
|
|
Lines 1202-1207
Link Here
|
| 1202 |
context)); |
1427 |
context)); |
| 1203 |
} |
1428 |
} |
| 1204 |
|
1429 |
|
|
|
1430 |
/** |
| 1431 |
* @since 2.6 |
| 1432 |
*/ |
| 1433 |
protected static void reportConstraintDelegateViolation(EDataType eDataType, Object value, DiagnosticChain diagnostics, Map<Object, Object> context, String constraint, int severity, String source, int code) |
| 1434 |
{ |
| 1435 |
diagnostics.add |
| 1436 |
(new BasicDiagnostic |
| 1437 |
(severity, |
| 1438 |
source, |
| 1439 |
code, |
| 1440 |
EcorePlugin.INSTANCE.getString("_UI_GenericConstraint_diagnostic", new Object[] { constraint, getValueLabel(eDataType, value, context) }), |
| 1441 |
new Object [] { value })); |
| 1442 |
} |
| 1443 |
|
| 1444 |
/** |
| 1445 |
* @since 2.6 |
| 1446 |
*/ |
| 1447 |
protected static void reportConstraintDelegateException(EDataType eDataType, Object value, DiagnosticChain diagnostics, Map<Object, Object> context, String constraint, int severity, String source, int code, Throwable throwable) |
| 1448 |
{ |
| 1449 |
diagnostics.add |
| 1450 |
(new BasicDiagnostic |
| 1451 |
(severity, |
| 1452 |
source, |
| 1453 |
code, |
| 1454 |
EcorePlugin.INSTANCE.getString("_UI_ConstraintDelegateException_diagnostic", new Object[] { constraint, getValueLabel(eDataType, value, context), throwable.getLocalizedMessage() }), |
| 1455 |
new Object [] { value })); |
| 1456 |
} |
| 1457 |
|
| 1458 |
/** |
| 1459 |
* @since 2.6 |
| 1460 |
*/ |
| 1461 |
protected static void reportConstraintDelegateNotFound(EDataType eDataType, Object value, DiagnosticChain diagnostics, Map<Object, Object> context, String constraint, int severity, String source, int code, String validationDelegate) |
| 1462 |
{ |
| 1463 |
diagnostics.add |
| 1464 |
(new BasicDiagnostic |
| 1465 |
(severity, |
| 1466 |
source, |
| 1467 |
code, |
| 1468 |
EcorePlugin.INSTANCE.getString("_UI_ConstraintDelegateNotFound_diagnostic", new Object[] { constraint, getValueLabel(eDataType, value, context), validationDelegate }), |
| 1469 |
new Object [] { value })); |
| 1470 |
} |
| 1471 |
|
| 1472 |
/** |
| 1473 |
* @since 2.6 |
| 1474 |
*/ |
| 1475 |
protected static void reportConstraintDelegateViolation(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context, String constraint, int severity, String source, int code) |
| 1476 |
{ |
| 1477 |
diagnostics.add |
| 1478 |
(new BasicDiagnostic |
| 1479 |
(severity, |
| 1480 |
source, |
| 1481 |
code, |
| 1482 |
EcorePlugin.INSTANCE.getString("_UI_GenericConstraint_diagnostic", new Object[] { constraint, getObjectLabel(eObject, context) }), |
| 1483 |
new Object [] { eObject })); |
| 1484 |
} |
| 1485 |
|
| 1486 |
/** |
| 1487 |
* @since 2.6 |
| 1488 |
*/ |
| 1489 |
protected static void reportConstraintDelegateException(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context, String constraint, int severity, String source, int code, Throwable throwable) |
| 1490 |
{ |
| 1491 |
diagnostics.add |
| 1492 |
(new BasicDiagnostic |
| 1493 |
(severity, |
| 1494 |
source, |
| 1495 |
code, |
| 1496 |
EcorePlugin.INSTANCE.getString("_UI_ConstraintDelegateException_diagnostic", new Object[] { constraint, getObjectLabel(eObject, context), throwable.getLocalizedMessage() }), |
| 1497 |
new Object [] { eObject })); |
| 1498 |
} |
| 1499 |
|
| 1500 |
/** |
| 1501 |
* @since 2.6 |
| 1502 |
*/ |
| 1503 |
protected static void reportConstraintDelegateNotFound(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context, String constraint, int severity, String source, int code, String validationDelegate) |
| 1504 |
{ |
| 1505 |
diagnostics.add |
| 1506 |
(new BasicDiagnostic |
| 1507 |
(severity, |
| 1508 |
source, |
| 1509 |
code, |
| 1510 |
EcorePlugin.INSTANCE.getString("_UI_ConstraintDelegateNotFound_diagnostic", new Object[] { constraint, getObjectLabel(eObject, context), validationDelegate }), |
| 1511 |
new Object [] { eObject })); |
| 1512 |
} |
| 1513 |
|
| 1514 |
/** |
| 1515 |
* @since 2.6 |
| 1516 |
*/ |
| 1517 |
protected static void reportInvariantDelegateViolation(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context, EOperation invariant, int severity, String source, int code) |
| 1518 |
{ |
| 1519 |
diagnostics.add |
| 1520 |
(new BasicDiagnostic |
| 1521 |
(severity, |
| 1522 |
source, |
| 1523 |
code, |
| 1524 |
EcorePlugin.INSTANCE.getString("_UI_GenericInvariant_diagnostic", new Object[] { invariant.getName(), getObjectLabel(eObject, context) }), |
| 1525 |
new Object [] { eObject })); |
| 1526 |
} |
| 1527 |
|
| 1528 |
/** |
| 1529 |
* @since 2.6 |
| 1530 |
*/ |
| 1531 |
protected static void reportInvariantDelegateException(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context, EOperation invariant, int severity, String source, int code, Throwable throwable) |
| 1532 |
{ |
| 1533 |
diagnostics.add |
| 1534 |
(new BasicDiagnostic |
| 1535 |
(severity, |
| 1536 |
source, |
| 1537 |
code, |
| 1538 |
EcorePlugin.INSTANCE.getString("_UI_InvariantDelegateException_diagnostic", new Object[] { invariant.getName(), getObjectLabel(eObject, context), throwable.getLocalizedMessage() }), |
| 1539 |
new Object [] { eObject })); |
| 1540 |
} |
| 1541 |
|
| 1542 |
/** |
| 1543 |
* @since 2.6 |
| 1544 |
*/ |
| 1545 |
protected static void reportInvariantDelegateNotFound(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context, EOperation invariant, int severity, String source, int code, String validationDelegate) |
| 1546 |
{ |
| 1547 |
diagnostics.add |
| 1548 |
(new BasicDiagnostic |
| 1549 |
(severity, |
| 1550 |
source, |
| 1551 |
code, |
| 1552 |
EcorePlugin.INSTANCE.getString("_UI_InvariantDelegateNotFound_diagnostic", new Object[] { invariant.getName(), getObjectLabel(eObject, context), validationDelegate }), |
| 1553 |
new Object [] { eObject })); |
| 1554 |
} |
| 1555 |
|
| 1205 |
protected static Collection<Object> wrapEnumerationValues(Object [] values) |
1556 |
protected static Collection<Object> wrapEnumerationValues(Object [] values) |
| 1206 |
{ |
1557 |
{ |
| 1207 |
return java.util.Arrays.asList(values); |
1558 |
return java.util.Arrays.asList(values); |
|
Lines 1471-1476
Link Here
|
| 1471 |
} |
1822 |
} |
| 1472 |
|
1823 |
|
| 1473 |
/** |
1824 |
/** |
|
|
1825 |
* @since 2.6 |
| 1826 |
*/ |
| 1827 |
protected boolean isEcoreString(String key) |
| 1828 |
{ |
| 1829 |
return "_UI_GenericConstraint_diagnostic".equals(key) || "_UI_GenericInvariant_diagnostic".equals(key) |
| 1830 |
|| "_UI_ConstraintDelegateException_diagnostic".equals(key) || "_UI_InvariantDelegateException_diagnostic".equals(key) |
| 1831 |
|| "_UI_ConstraintDelegateNotFound_diagnostic".equals(key) || "_UI_InvariantDelegateNotFound_diagnostic".equals(key); |
| 1832 |
} |
| 1833 |
|
| 1834 |
/** |
| 1474 |
* Returns a translated message with the given substitutions. |
1835 |
* Returns a translated message with the given substitutions. |
| 1475 |
* The {@link #getResourceLocator() resource locator} is used. |
1836 |
* The {@link #getResourceLocator() resource locator} is used. |
| 1476 |
* @param key the key for the message. |
1837 |
* @param key the key for the message. |
|
Lines 1480-1486
Link Here
|
| 1480 |
*/ |
1841 |
*/ |
| 1481 |
protected String getString(String key, Object [] substitutions) |
1842 |
protected String getString(String key, Object [] substitutions) |
| 1482 |
{ |
1843 |
{ |
| 1483 |
return getString("_UI_GenericConstraint_diagnostic".equals(key) ? getEcoreResourceLocator() : getResourceLocator(), key, substitutions); |
1844 |
return getString(isEcoreString(key) ? getEcoreResourceLocator() : getResourceLocator(), key, substitutions); |
| 1484 |
} |
1845 |
} |
| 1485 |
|
1846 |
|
| 1486 |
/** |
1847 |
/** |