|
Lines 16-26
Link Here
|
| 16 |
*/ |
16 |
*/ |
| 17 |
package org.eclipse.emf.ecore.util; |
17 |
package org.eclipse.emf.ecore.util; |
| 18 |
|
18 |
|
| 19 |
|
|
|
| 20 |
import java.util.ArrayList; |
19 |
import java.util.ArrayList; |
| 21 |
import java.util.Collection; |
20 |
import java.util.Collection; |
|
|
21 |
import java.util.Collections; |
| 22 |
import java.util.HashMap; |
22 |
import java.util.HashMap; |
| 23 |
import java.util.Iterator; |
23 |
import java.util.Iterator; |
|
|
24 |
import java.util.LinkedList; |
| 24 |
import java.util.List; |
25 |
import java.util.List; |
| 25 |
import java.util.ListIterator; |
26 |
import java.util.ListIterator; |
| 26 |
import java.util.Map; |
27 |
import java.util.Map; |
|
Lines 37-42
Link Here
|
| 37 |
|
38 |
|
| 38 |
import org.eclipse.emf.ecore.EValidator; |
39 |
import org.eclipse.emf.ecore.EValidator; |
| 39 |
|
40 |
|
|
|
41 |
import org.eclipse.emf.ecore.EAnnotation; |
| 40 |
import org.eclipse.emf.ecore.EAttribute; |
42 |
import org.eclipse.emf.ecore.EAttribute; |
| 41 |
import org.eclipse.emf.ecore.EObject; |
43 |
import org.eclipse.emf.ecore.EObject; |
| 42 |
import org.eclipse.emf.ecore.EClass; |
44 |
import org.eclipse.emf.ecore.EClass; |
|
Lines 51-56
Link Here
|
| 51 |
|
53 |
|
| 52 |
import org.eclipse.emf.ecore.resource.Resource; |
54 |
import org.eclipse.emf.ecore.resource.Resource; |
| 53 |
import org.eclipse.emf.ecore.resource.ResourceSet; |
55 |
import org.eclipse.emf.ecore.resource.ResourceSet; |
|
|
56 |
import org.eclipse.emf.ecore.util.ConstraintsDelegator.Factory; |
| 54 |
|
57 |
|
| 55 |
import org.eclipse.emf.ecore.xml.type.util.XMLTypeUtil; |
58 |
import org.eclipse.emf.ecore.xml.type.util.XMLTypeUtil; |
| 56 |
|
59 |
|
|
Lines 60-65
Link Here
|
| 60 |
*/ |
63 |
*/ |
| 61 |
public class EObjectValidator implements EValidator |
64 |
public class EObjectValidator implements EValidator |
| 62 |
{ |
65 |
{ |
|
|
66 |
private static final String USER_CONSTRAINT_VALIDATION_EANNOTATION_FACTORY = "factory"; |
| 67 |
|
| 68 |
private static final String USER_CONSTRAINT_VALIDATION_EANNOTATION_CONSTRAINTS = "constraints"; |
| 69 |
|
| 70 |
private static final String USER_CONSTRAINT_VALIDATION_EANNOTATION_INHERITANCE = "inheritsConstraints"; |
| 71 |
|
| 72 |
private static final String USER_CONSTRAINT_VALIDATION_EANNOTATION_ECORE = "Ecore"; |
| 73 |
|
| 63 |
public static final EObjectValidator INSTANCE = new EObjectValidator(); |
74 |
public static final EObjectValidator INSTANCE = new EObjectValidator(); |
| 64 |
|
75 |
|
| 65 |
public static final String DIAGNOSTIC_SOURCE = "org.eclipse.emf.ecore"; |
76 |
public static final String DIAGNOSTIC_SOURCE = "org.eclipse.emf.ecore"; |
|
Lines 78-84
Link Here
|
| 78 |
public static final int EOBJECT__UNIQUE_ID = 12; |
89 |
public static final int EOBJECT__UNIQUE_ID = 12; |
| 79 |
public static final int EOBJECT__EVERY_KEY_UNIQUE = 13; |
90 |
public static final int EOBJECT__EVERY_KEY_UNIQUE = 13; |
| 80 |
public static final int EOBJECT__EVERY_MAP_ENTRY_UNIQUE = 14; |
91 |
public static final int EOBJECT__EVERY_MAP_ENTRY_UNIQUE = 14; |
| 81 |
|
92 |
|
| 82 |
static final int EOBJECT_DIAGNOSTIC_CODE_COUNT = EOBJECT__EVERY_MAP_ENTRY_UNIQUE; |
93 |
static final int EOBJECT_DIAGNOSTIC_CODE_COUNT = EOBJECT__EVERY_MAP_ENTRY_UNIQUE; |
| 83 |
|
94 |
|
| 84 |
/** |
95 |
/** |
|
Lines 173-182
Link Here
|
| 173 |
else |
184 |
else |
| 174 |
{ |
185 |
{ |
| 175 |
List<EClass> eSuperTypes = eClass.getESuperTypes(); |
186 |
List<EClass> eSuperTypes = eClass.getESuperTypes(); |
| 176 |
return |
187 |
return eSuperTypes.isEmpty() ? validate_EveryDefaultConstraint(eObject, diagnostics, context) : validate( |
| 177 |
eSuperTypes.isEmpty() ? |
188 |
eSuperTypes.get(0), |
| 178 |
validate_EveryDefaultConstraint(eObject, diagnostics, context) : |
189 |
eObject, |
| 179 |
validate(eSuperTypes.get(0), eObject, diagnostics, context); |
190 |
diagnostics, |
|
|
191 |
context); |
| 180 |
} |
192 |
} |
| 181 |
} |
193 |
} |
| 182 |
|
194 |
|
|
Lines 212-217
Link Here
|
| 212 |
{ |
224 |
{ |
| 213 |
result &= validate_EveryMapEntryUnique(object, theDiagnostics, context); |
225 |
result &= validate_EveryMapEntryUnique(object, theDiagnostics, context); |
| 214 |
} |
226 |
} |
|
|
227 |
// ADDS FOR MANAGING USER CONSTRAINTS |
| 228 |
if (result || theDiagnostics != null) |
| 229 |
{ |
| 230 |
result &= validate_UserConstraints(object, theDiagnostics, context); |
| 231 |
} |
| 232 |
return result; |
| 233 |
} |
| 234 |
|
| 235 |
/** |
| 236 |
* @since 2.5 |
| 237 |
* @param object |
| 238 |
* @param theDiagnostics |
| 239 |
* @param context |
| 240 |
* @return |
| 241 |
*/ |
| 242 |
protected boolean validate_UserConstraints(EObject object, DiagnosticChain theDiagnostics, Map<Object, Object> context) |
| 243 |
{ |
| 244 |
EClass theclass = object.eClass(); |
| 245 |
boolean result = validate_UserConstraintsByEClass(theclass, object, theDiagnostics, context); |
| 246 |
return result; |
| 247 |
} |
| 248 |
|
| 249 |
/** |
| 250 |
* @since 2.5 |
| 251 |
* @param theEClass |
| 252 |
* @param object |
| 253 |
* @param theDiagnostics |
| 254 |
* @param context |
| 255 |
* @return |
| 256 |
*/ |
| 257 |
protected boolean validate_UserConstraintsByEClass( |
| 258 |
EClass theEClass, |
| 259 |
EObject object, |
| 260 |
DiagnosticChain theDiagnostics, |
| 261 |
Map<Object, Object> context) |
| 262 |
{ |
| 263 |
Collection<EAnnotation> annotations = theEClass.getEAnnotations(); |
| 264 |
Collection<String> constraints = new LinkedList<String>(); |
| 265 |
String factoryName = ""; |
| 266 |
String keyName = ""; |
| 267 |
boolean result = true; |
| 268 |
boolean inheritsConstraints = true; |
| 269 |
for (EAnnotation e : annotations) |
| 270 |
{ |
| 271 |
if (USER_CONSTRAINT_VALIDATION_EANNOTATION_ECORE.equals(e.getSource())) |
| 272 |
{ |
| 273 |
if (e.getDetails().containsKey(USER_CONSTRAINT_VALIDATION_EANNOTATION_CONSTRAINTS)) |
| 274 |
{ |
| 275 |
String strConstraints = e.getDetails().get(USER_CONSTRAINT_VALIDATION_EANNOTATION_CONSTRAINTS); |
| 276 |
|
| 277 |
String[] stringSplited = strConstraints.split(" "); |
| 278 |
Collections.addAll(constraints, stringSplited); |
| 279 |
if (stringSplited != null && stringSplited.length > 0) |
| 280 |
{ |
| 281 |
if (e.getDetails().containsKey(USER_CONSTRAINT_VALIDATION_EANNOTATION_FACTORY)) |
| 282 |
{ |
| 283 |
String strFactory = e.getDetails().get(USER_CONSTRAINT_VALIDATION_EANNOTATION_FACTORY); |
| 284 |
String[] strs = strFactory.split("#"); |
| 285 |
if (strs != null && strs.length == 2) |
| 286 |
{ |
| 287 |
factoryName = strs[0]; |
| 288 |
keyName = strs[1]; |
| 289 |
} |
| 290 |
else |
| 291 |
{ |
| 292 |
factoryName = strFactory; |
| 293 |
keyName = strFactory; |
| 294 |
} |
| 295 |
// check if user specifies how to manage constraints inheritance |
| 296 |
if (e.getDetails().containsKey(USER_CONSTRAINT_VALIDATION_EANNOTATION_INHERITANCE)) |
| 297 |
{ |
| 298 |
String value = e.getDetails().get(USER_CONSTRAINT_VALIDATION_EANNOTATION_INHERITANCE); |
| 299 |
if (value != null && ("true".equals(value.trim().toLowerCase()) || "false".equals(value.trim().toLowerCase()))) |
| 300 |
{ |
| 301 |
inheritsConstraints = Boolean.valueOf(value); |
| 302 |
} |
| 303 |
} |
| 304 |
} |
| 305 |
} |
| 306 |
break; |
| 307 |
} |
| 308 |
} |
| 309 |
} |
| 310 |
if (constraints.size() > 0 && keyName.length() > 0 && factoryName.length() > 0) |
| 311 |
{ |
| 312 |
for (String currentConstraint : constraints) |
| 313 |
{ |
| 314 |
for (EAnnotation e : annotations) |
| 315 |
{ |
| 316 |
if (keyName.equals(e.getSource())) |
| 317 |
{ |
| 318 |
if (e.getDetails().containsKey(currentConstraint)) |
| 319 |
{ |
| 320 |
String rule = e.getDetails().get(currentConstraint); |
| 321 |
Factory factory = ConstraintsDelegator.Factory.Registry.INSTANCE.getFactory(factoryName); |
| 322 |
if (factory != null) |
| 323 |
{ |
| 324 |
ConstraintsDelegator constraintDelegator = factory.createConstraintDelegator(); |
| 325 |
if (constraintDelegator != null) |
| 326 |
{ |
| 327 |
if (inheritsConstraints) |
| 328 |
{ |
| 329 |
for (EClass c : theEClass.getESuperTypes()) |
| 330 |
{ |
| 331 |
result &= validate_UserConstraintsByEClass(c, object, theDiagnostics, context); |
| 332 |
} |
| 333 |
} |
| 334 |
result &= constraintDelegator.validate(rule, object, theDiagnostics, context); |
| 335 |
} |
| 336 |
} |
| 337 |
} |
| 338 |
} |
| 339 |
} |
| 340 |
} |
| 341 |
} |
| 215 |
return result; |
342 |
return result; |
| 216 |
} |
343 |
} |
| 217 |
|
344 |
|
|
Lines 229-237
Link Here
|
| 229 |
} |
356 |
} |
| 230 |
return result; |
357 |
return result; |
| 231 |
} |
358 |
} |
| 232 |
|
359 |
|
| 233 |
protected boolean validate_MultiplicityConforms |
360 |
protected boolean validate_MultiplicityConforms( |
| 234 |
(EObject eObject, EStructuralFeature eStructuralFeature, DiagnosticChain diagnostics, Map<Object, Object> context) |
361 |
EObject eObject, |
|
|
362 |
EStructuralFeature eStructuralFeature, |
| 363 |
DiagnosticChain diagnostics, |
| 364 |
Map<Object, Object> context) |
| 235 |
{ |
365 |
{ |
| 236 |
boolean result = true; |
366 |
boolean result = true; |
| 237 |
if (eStructuralFeature.isMany()) |
367 |
if (eStructuralFeature.isMany()) |
|
Lines 239-265
Link Here
|
| 239 |
int lowerBound = eStructuralFeature.getLowerBound(); |
369 |
int lowerBound = eStructuralFeature.getLowerBound(); |
| 240 |
if (lowerBound > 0) |
370 |
if (lowerBound > 0) |
| 241 |
{ |
371 |
{ |
| 242 |
int size = ((List<?>)eObject.eGet(eStructuralFeature)).size(); |
372 |
int size = ((List< ? >)eObject.eGet(eStructuralFeature)).size(); |
| 243 |
if (size < lowerBound) |
373 |
if (size < lowerBound) |
| 244 |
{ |
374 |
{ |
| 245 |
result = false; |
375 |
result = false; |
| 246 |
if (diagnostics != null) |
376 |
if (diagnostics != null) |
| 247 |
{ |
377 |
{ |
| 248 |
diagnostics.add |
378 |
diagnostics.add(createDiagnostic( |
| 249 |
(createDiagnostic |
379 |
Diagnostic.ERROR, |
| 250 |
(Diagnostic.ERROR, |
380 |
DIAGNOSTIC_SOURCE, |
| 251 |
DIAGNOSTIC_SOURCE, |
381 |
EOBJECT__EVERY_MULTIPCITY_CONFORMS, |
| 252 |
EOBJECT__EVERY_MULTIPCITY_CONFORMS, |
382 |
"_UI_FeatureHasTooFewValues_diagnostic", |
| 253 |
"_UI_FeatureHasTooFewValues_diagnostic", |
383 |
new Object []{ getFeatureLabel(eStructuralFeature, context), getObjectLabel(eObject, context), size, lowerBound }, |
| 254 |
new Object [] |
384 |
new Object []{ eObject, eStructuralFeature }, |
| 255 |
{ |
385 |
context)); |
| 256 |
getFeatureLabel(eStructuralFeature, context), |
|
|
| 257 |
getObjectLabel(eObject, context), |
| 258 |
size, |
| 259 |
lowerBound |
| 260 |
}, |
| 261 |
new Object [] { eObject, eStructuralFeature }, |
| 262 |
context)); |
| 263 |
} |
386 |
} |
| 264 |
} |
387 |
} |
| 265 |
int upperBound = eStructuralFeature.getUpperBound(); |
388 |
int upperBound = eStructuralFeature.getUpperBound(); |
|
Lines 268-288
Link Here
|
| 268 |
result = false; |
391 |
result = false; |
| 269 |
if (diagnostics != null) |
392 |
if (diagnostics != null) |
| 270 |
{ |
393 |
{ |
| 271 |
diagnostics.add |
394 |
diagnostics.add(createDiagnostic( |
| 272 |
(createDiagnostic |
395 |
Diagnostic.ERROR, |
| 273 |
(Diagnostic.ERROR, |
396 |
DIAGNOSTIC_SOURCE, |
| 274 |
DIAGNOSTIC_SOURCE, |
397 |
EOBJECT__EVERY_MULTIPCITY_CONFORMS, |
| 275 |
EOBJECT__EVERY_MULTIPCITY_CONFORMS, |
398 |
"_UI_FeatureHasTooManyValues_diagnostic", |
| 276 |
"_UI_FeatureHasTooManyValues_diagnostic", |
399 |
new Object []{ |
| 277 |
new Object [] |
400 |
getFeatureLabel(eStructuralFeature, context), |
| 278 |
{ |
401 |
getObjectLabel(eObject, context), |
| 279 |
getFeatureLabel(eStructuralFeature, context), |
402 |
new Integer(size), |
| 280 |
getObjectLabel(eObject, context), |
403 |
new Integer(upperBound) }, |
| 281 |
new Integer(size), |
404 |
new Object []{ eObject, eStructuralFeature }, |
| 282 |
new Integer(upperBound) |
405 |
context)); |
| 283 |
}, |
|
|
| 284 |
new Object [] { eObject, eStructuralFeature }, |
| 285 |
context)); |
| 286 |
} |
406 |
} |
| 287 |
} |
407 |
} |
| 288 |
} |
408 |
} |
|
Lines 291-317
Link Here
|
| 291 |
int upperBound = eStructuralFeature.getUpperBound(); |
411 |
int upperBound = eStructuralFeature.getUpperBound(); |
| 292 |
if (upperBound > 0) |
412 |
if (upperBound > 0) |
| 293 |
{ |
413 |
{ |
| 294 |
int size = ((List<?>)eObject.eGet(eStructuralFeature)).size(); |
414 |
int size = ((List< ? >)eObject.eGet(eStructuralFeature)).size(); |
| 295 |
if (size > upperBound) |
415 |
if (size > upperBound) |
| 296 |
{ |
416 |
{ |
| 297 |
result = false; |
417 |
result = false; |
| 298 |
if (diagnostics != null) |
418 |
if (diagnostics != null) |
| 299 |
{ |
419 |
{ |
| 300 |
diagnostics.add |
420 |
diagnostics.add(createDiagnostic( |
| 301 |
(createDiagnostic |
421 |
Diagnostic.ERROR, |
| 302 |
(Diagnostic.ERROR, |
422 |
DIAGNOSTIC_SOURCE, |
| 303 |
DIAGNOSTIC_SOURCE, |
423 |
EOBJECT__EVERY_MULTIPCITY_CONFORMS, |
| 304 |
EOBJECT__EVERY_MULTIPCITY_CONFORMS, |
424 |
"_UI_FeatureHasTooManyValues_diagnostic", |
| 305 |
"_UI_FeatureHasTooManyValues_diagnostic", |
425 |
new Object []{ |
| 306 |
new Object [] |
426 |
getFeatureLabel(eStructuralFeature, context), |
| 307 |
{ |
427 |
getObjectLabel(eObject, context), |
| 308 |
getFeatureLabel(eStructuralFeature, context), |
428 |
new Integer(size), |
| 309 |
getObjectLabel(eObject, context), |
429 |
new Integer(upperBound) }, |
| 310 |
new Integer(size), |
430 |
new Object []{ eObject, eStructuralFeature }, |
| 311 |
new Integer(upperBound) |
431 |
context)); |
| 312 |
}, |
|
|
| 313 |
new Object [] { eObject, eStructuralFeature }, |
| 314 |
context)); |
| 315 |
} |
432 |
} |
| 316 |
} |
433 |
} |
| 317 |
} |
434 |
} |
|
Lines 324-338
Link Here
|
| 324 |
result = false; |
441 |
result = false; |
| 325 |
if (diagnostics != null) |
442 |
if (diagnostics != null) |
| 326 |
{ |
443 |
{ |
| 327 |
diagnostics.add |
444 |
diagnostics.add(createDiagnostic( |
| 328 |
(createDiagnostic |
445 |
Diagnostic.ERROR, |
| 329 |
(Diagnostic.ERROR, |
446 |
DIAGNOSTIC_SOURCE, |
| 330 |
DIAGNOSTIC_SOURCE, |
447 |
EOBJECT__EVERY_MULTIPCITY_CONFORMS, |
| 331 |
EOBJECT__EVERY_MULTIPCITY_CONFORMS, |
448 |
"_UI_RequiredFeatureMustBeSet_diagnostic", |
| 332 |
"_UI_RequiredFeatureMustBeSet_diagnostic", |
449 |
new Object []{ getFeatureLabel(eStructuralFeature, context), getObjectLabel(eObject, context) }, |
| 333 |
new Object [] { getFeatureLabel(eStructuralFeature, context), getObjectLabel(eObject, context) }, |
450 |
new Object []{ eObject, eStructuralFeature }, |
| 334 |
new Object [] { eObject, eStructuralFeature }, |
451 |
context)); |
| 335 |
context)); |
|
|
| 336 |
} |
452 |
} |
| 337 |
} |
453 |
} |
| 338 |
} |
454 |
} |
|
Lines 343-349
Link Here
|
| 343 |
public boolean validate_EveryProxyResolves(EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) |
459 |
public boolean validate_EveryProxyResolves(EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) |
| 344 |
{ |
460 |
{ |
| 345 |
boolean result = true; |
461 |
boolean result = true; |
| 346 |
for (EContentsEList.FeatureIterator<EObject> i = (EContentsEList.FeatureIterator<EObject>)eObject.eCrossReferences().iterator(); i.hasNext(); ) |
462 |
for (EContentsEList.FeatureIterator<EObject> i = (EContentsEList.FeatureIterator<EObject>)eObject.eCrossReferences().iterator(); i.hasNext();) |
| 347 |
{ |
463 |
{ |
| 348 |
EObject eCrossReferenceObject = i.next(); |
464 |
EObject eCrossReferenceObject = i.next(); |
| 349 |
if (eCrossReferenceObject.eIsProxy()) |
465 |
if (eCrossReferenceObject.eIsProxy()) |
|
Lines 351-370
Link Here
|
| 351 |
result = false; |
467 |
result = false; |
| 352 |
if (diagnostics != null) |
468 |
if (diagnostics != null) |
| 353 |
{ |
469 |
{ |
| 354 |
diagnostics.add |
470 |
diagnostics.add(createDiagnostic( |
| 355 |
(createDiagnostic |
471 |
Diagnostic.ERROR, |
| 356 |
(Diagnostic.ERROR, |
472 |
DIAGNOSTIC_SOURCE, |
| 357 |
DIAGNOSTIC_SOURCE, |
473 |
EOBJECT__EVERY_PROXY_RESOLVES, |
| 358 |
EOBJECT__EVERY_PROXY_RESOLVES, |
474 |
"_UI_UnresolvedProxy_diagnostic", |
| 359 |
"_UI_UnresolvedProxy_diagnostic", |
475 |
new Object []{ |
| 360 |
new Object [] |
476 |
getFeatureLabel(i.feature(), context), |
| 361 |
{ |
477 |
getObjectLabel(eObject, context), |
| 362 |
getFeatureLabel(i.feature(), context), |
478 |
getObjectLabel(eCrossReferenceObject, context) }, |
| 363 |
getObjectLabel(eObject, context), |
479 |
new Object []{ eObject, i.feature(), eCrossReferenceObject }, |
| 364 |
getObjectLabel(eCrossReferenceObject, context) |
480 |
context)); |
| 365 |
}, |
|
|
| 366 |
new Object [] { eObject, i.feature(), eCrossReferenceObject }, |
| 367 |
context)); |
| 368 |
} |
481 |
} |
| 369 |
else |
482 |
else |
| 370 |
{ |
483 |
{ |
|
Lines 380-386
Link Here
|
| 380 |
boolean result = true; |
493 |
boolean result = true; |
| 381 |
if (eObject.eResource() != null) |
494 |
if (eObject.eResource() != null) |
| 382 |
{ |
495 |
{ |
| 383 |
for (EContentsEList.FeatureIterator<EObject> i = (EContentsEList.FeatureIterator<EObject>)eObject.eCrossReferences().iterator(); i.hasNext(); ) |
496 |
for (EContentsEList.FeatureIterator<EObject> i = (EContentsEList.FeatureIterator<EObject>)eObject.eCrossReferences().iterator(); i.hasNext();) |
| 384 |
{ |
497 |
{ |
| 385 |
EObject eCrossReferenceObject = i.next(); |
498 |
EObject eCrossReferenceObject = i.next(); |
| 386 |
if (eCrossReferenceObject.eResource() == null && !eCrossReferenceObject.eIsProxy() && !i.feature().isTransient()) |
499 |
if (eCrossReferenceObject.eResource() == null && !eCrossReferenceObject.eIsProxy() && !i.feature().isTransient()) |
|
Lines 388-407
Link Here
|
| 388 |
result = false; |
501 |
result = false; |
| 389 |
if (diagnostics != null) |
502 |
if (diagnostics != null) |
| 390 |
{ |
503 |
{ |
| 391 |
diagnostics.add |
504 |
diagnostics.add(createDiagnostic( |
| 392 |
(createDiagnostic |
505 |
Diagnostic.ERROR, |
| 393 |
(Diagnostic.ERROR, |
506 |
DIAGNOSTIC_SOURCE, |
| 394 |
DIAGNOSTIC_SOURCE, |
507 |
EOBJECT__EVERY_REFERENCE_IS_CONTAINED, |
| 395 |
EOBJECT__EVERY_REFERENCE_IS_CONTAINED, |
508 |
"_UI_DanglingReference_diagnostic", |
| 396 |
"_UI_DanglingReference_diagnostic", |
509 |
new Object []{ |
| 397 |
new Object [] |
510 |
getFeatureLabel(i.feature(), context), |
| 398 |
{ |
511 |
getObjectLabel(eObject, context), |
| 399 |
getFeatureLabel(i.feature(), context), |
512 |
getObjectLabel(eCrossReferenceObject, context) }, |
| 400 |
getObjectLabel(eObject, context), |
513 |
new Object []{ eObject, i.feature(), eCrossReferenceObject }, |
| 401 |
getObjectLabel(eCrossReferenceObject, context) |
514 |
context)); |
| 402 |
}, |
|
|
| 403 |
new Object [] { eObject, i.feature(), eCrossReferenceObject }, |
| 404 |
context)); |
| 405 |
} |
515 |
} |
| 406 |
else |
516 |
else |
| 407 |
{ |
517 |
{ |
|
Lines 427-434
Link Here
|
| 427 |
return result; |
537 |
return result; |
| 428 |
} |
538 |
} |
| 429 |
|
539 |
|
| 430 |
protected boolean validate_DataValueConforms |
540 |
protected boolean validate_DataValueConforms( |
| 431 |
(EObject eObject, EAttribute eAttribute, DiagnosticChain diagnostics, Map<Object, Object> context) |
541 |
EObject eObject, |
|
|
542 |
EAttribute eAttribute, |
| 543 |
DiagnosticChain diagnostics, |
| 544 |
Map<Object, Object> context) |
| 432 |
{ |
545 |
{ |
| 433 |
if (!eObject.eIsSet(eAttribute)) |
546 |
if (!eObject.eIsSet(eAttribute)) |
| 434 |
{ |
547 |
{ |
|
Lines 440-454
Link Here
|
| 440 |
Object value = eObject.eGet(eAttribute); |
553 |
Object value = eObject.eGet(eAttribute); |
| 441 |
if (FeatureMapUtil.isFeatureMap(eAttribute)) |
554 |
if (FeatureMapUtil.isFeatureMap(eAttribute)) |
| 442 |
{ |
555 |
{ |
| 443 |
@SuppressWarnings("unchecked") Collection<FeatureMap.Entry> featureMap = (Collection<FeatureMap.Entry>)value; |
556 |
@SuppressWarnings("unchecked") |
|
|
557 |
Collection<FeatureMap.Entry> featureMap = (Collection<FeatureMap.Entry>)value; |
| 444 |
EClass eClass = eObject.eClass(); |
558 |
EClass eClass = eObject.eClass(); |
| 445 |
Map<EStructuralFeature, DiagnosticChain> entryFeatureToDiagnosticChainMap = null; |
559 |
Map<EStructuralFeature, DiagnosticChain> entryFeatureToDiagnosticChainMap = null; |
| 446 |
for (Iterator<FeatureMap.Entry> i = featureMap.iterator(); i.hasNext() && (result || diagnostics != null); ) |
560 |
for (Iterator<FeatureMap.Entry> i = featureMap.iterator(); i.hasNext() && (result || diagnostics != null);) |
| 447 |
{ |
561 |
{ |
| 448 |
FeatureMap.Entry entry = i.next(); |
562 |
FeatureMap.Entry entry = i.next(); |
| 449 |
EStructuralFeature entryFeature = entry.getEStructuralFeature(); |
563 |
EStructuralFeature entryFeature = entry.getEStructuralFeature(); |
| 450 |
if (entryFeature instanceof EAttribute && |
564 |
if (entryFeature instanceof EAttribute && ExtendedMetaData.INSTANCE.getAffiliation(eClass, entryFeature) == eAttribute) |
| 451 |
ExtendedMetaData.INSTANCE.getAffiliation(eClass, entryFeature) == eAttribute) |
|
|
| 452 |
{ |
565 |
{ |
| 453 |
EDataType entryType = (EDataType)entryFeature.getEType(); |
566 |
EDataType entryType = (EDataType)entryFeature.getEType(); |
| 454 |
Object entryValue = entry.getValue(); |
567 |
Object entryValue = entry.getValue(); |
|
Lines 476-482
Link Here
|
| 476 |
} |
589 |
} |
| 477 |
else if (eAttribute.isMany()) |
590 |
else if (eAttribute.isMany()) |
| 478 |
{ |
591 |
{ |
| 479 |
for (Iterator<?> i = ((List<?>)value).iterator(); i.hasNext() && result; ) |
592 |
for (Iterator< ? > i = ((List< ? >)value).iterator(); i.hasNext() && result;) |
| 480 |
{ |
593 |
{ |
| 481 |
result &= rootValidator.validate(eDataType, i.next(), null, context); |
594 |
result &= rootValidator.validate(eDataType, i.next(), null, context); |
| 482 |
} |
595 |
} |
|
Lines 484-490
Link Here
|
| 484 |
if (!result && diagnostics != null) |
597 |
if (!result && diagnostics != null) |
| 485 |
{ |
598 |
{ |
| 486 |
DiagnosticChain diagnostic = createBadDataValueDiagnostic(eObject, eAttribute, diagnostics, context); |
599 |
DiagnosticChain diagnostic = createBadDataValueDiagnostic(eObject, eAttribute, diagnostics, context); |
| 487 |
for (Iterator<?> i = ((List<?>)value).iterator(); i.hasNext(); ) |
600 |
for (Iterator< ? > i = ((List< ? >)value).iterator(); i.hasNext();) |
| 488 |
{ |
601 |
{ |
| 489 |
rootValidator.validate(eDataType, i.next(), diagnostic, context); |
602 |
rootValidator.validate(eDataType, i.next(), diagnostic, context); |
| 490 |
} |
603 |
} |
|
Lines 503-535
Link Here
|
| 503 |
return result; |
616 |
return result; |
| 504 |
} |
617 |
} |
| 505 |
|
618 |
|
| 506 |
protected DiagnosticChain createBadDataValueDiagnostic |
619 |
protected DiagnosticChain createBadDataValueDiagnostic( |
| 507 |
(EObject eObject, EAttribute eAttribute, DiagnosticChain diagnostics, Map<Object, Object> context) |
620 |
EObject eObject, |
| 508 |
{ |
621 |
EAttribute eAttribute, |
| 509 |
BasicDiagnostic diagnostic = |
622 |
DiagnosticChain diagnostics, |
| 510 |
createDiagnostic |
623 |
Map<Object, Object> context) |
| 511 |
(Diagnostic.ERROR, |
624 |
{ |
| 512 |
DIAGNOSTIC_SOURCE, |
625 |
BasicDiagnostic diagnostic = createDiagnostic( |
| 513 |
EOBJECT__EVERY_DATA_VALUE_CONFORMS, |
626 |
Diagnostic.ERROR, |
| 514 |
"_UI_BadDataValue_diagnostic", |
627 |
DIAGNOSTIC_SOURCE, |
| 515 |
new Object [] |
628 |
EOBJECT__EVERY_DATA_VALUE_CONFORMS, |
| 516 |
{ |
629 |
"_UI_BadDataValue_diagnostic", |
| 517 |
getFeatureLabel(eAttribute, context), |
630 |
new Object []{ getFeatureLabel(eAttribute, context), getObjectLabel(eObject, context) }, |
| 518 |
getObjectLabel(eObject, context) |
631 |
new Object []{ eObject, eAttribute }, |
| 519 |
}, |
632 |
context); |
| 520 |
new Object [] { eObject, eAttribute }, |
|
|
| 521 |
context); |
| 522 |
diagnostics.add(diagnostic); |
633 |
diagnostics.add(diagnostic); |
| 523 |
return diagnostic; |
634 |
return diagnostic; |
| 524 |
} |
635 |
} |
| 525 |
|
636 |
|
| 526 |
protected boolean validatePattern |
637 |
protected boolean validatePattern( |
| 527 |
(EDataType eDataType, Object value, PatternMatcher [][] patterns, DiagnosticChain diagnostics, Map<Object, Object> context) |
638 |
EDataType eDataType, |
|
|
639 |
Object value, |
| 640 |
PatternMatcher[][] patterns, |
| 641 |
DiagnosticChain diagnostics, |
| 642 |
Map<Object, Object> context) |
| 528 |
{ |
643 |
{ |
| 529 |
String literal = EcoreUtil.convertToString(eDataType, value); |
644 |
String literal = EcoreUtil.convertToString(eDataType, value); |
| 530 |
for (int i = 0; i < patterns.length; ++i) |
645 |
for (int i = 0; i < patterns.length; ++i) |
| 531 |
{ |
646 |
{ |
| 532 |
PatternMatcher [] children = patterns[i]; |
647 |
PatternMatcher[] children = patterns[i]; |
| 533 |
boolean matches = false; |
648 |
boolean matches = false; |
| 534 |
for (int j = 0; j < children.length; ++j) |
649 |
for (int j = 0; j < children.length; ++j) |
| 535 |
{ |
650 |
{ |
|
Lines 554-560
Link Here
|
| 554 |
public class DynamicEDataTypeValidator |
669 |
public class DynamicEDataTypeValidator |
| 555 |
{ |
670 |
{ |
| 556 |
protected List<Object> effectiveEnumeration; |
671 |
protected List<Object> effectiveEnumeration; |
| 557 |
protected PatternMatcher [][] effectivePattern; |
672 |
protected PatternMatcher[][] effectivePattern; |
| 558 |
protected int effectiveTotalDigits = -1; |
673 |
protected int effectiveTotalDigits = -1; |
| 559 |
protected int effectiveFractionDigits = -1; |
674 |
protected int effectiveFractionDigits = -1; |
| 560 |
protected int effectiveMinLength = -1; |
675 |
protected int effectiveMinLength = -1; |
|
Lines 605-613
Link Here
|
| 605 |
{ |
720 |
{ |
| 606 |
patterns = new ArrayList<PatternMatcher[]>(); |
721 |
patterns = new ArrayList<PatternMatcher[]>(); |
| 607 |
} |
722 |
} |
| 608 |
PatternMatcher [] children = new PatternMatcher [pattern.size()]; |
723 |
PatternMatcher[] children = new PatternMatcher [pattern.size()]; |
| 609 |
patterns.add(children); |
724 |
patterns.add(children); |
| 610 |
for (ListIterator<String> i = pattern.listIterator(); i.hasNext(); ) |
725 |
for (ListIterator<String> i = pattern.listIterator(); i.hasNext();) |
| 611 |
{ |
726 |
{ |
| 612 |
PatternMatcher patternMatcher = XMLTypeUtil.createPatternMatcher(i.next()); |
727 |
PatternMatcher patternMatcher = XMLTypeUtil.createPatternMatcher(i.next()); |
| 613 |
children[i.previousIndex()] = patternMatcher; |
728 |
children[i.previousIndex()] = patternMatcher; |
|
Lines 691-697
Link Here
|
| 691 |
|
806 |
|
| 692 |
if (patterns != null) |
807 |
if (patterns != null) |
| 693 |
{ |
808 |
{ |
| 694 |
effectivePattern = new PatternMatcher [patterns.size()][]; |
809 |
effectivePattern = new PatternMatcher [patterns.size()] []; |
| 695 |
patterns.toArray(effectivePattern); |
810 |
patterns.toArray(effectivePattern); |
| 696 |
} |
811 |
} |
| 697 |
|
812 |
|
|
Lines 702-715
Link Here
|
| 702 |
{ |
817 |
{ |
| 703 |
digits.append("0"); |
818 |
digits.append("0"); |
| 704 |
} |
819 |
} |
| 705 |
|
820 |
|
| 706 |
try |
821 |
try |
| 707 |
{ |
822 |
{ |
| 708 |
Object lowerBound = EcoreUtil.createFromString(eDataType, "-" + digits.toString()); |
823 |
Object lowerBound = EcoreUtil.createFromString(eDataType, "-" + digits.toString()); |
| 709 |
@SuppressWarnings("unchecked") boolean lowerBounded = effectiveMin == null || |
824 |
@SuppressWarnings("unchecked") |
| 710 |
(effectiveMinIsInclusive ? |
825 |
boolean lowerBounded = effectiveMin == null |
| 711 |
((Comparable<Object>)effectiveMin).compareTo(lowerBound) <= 0: |
826 |
|| (effectiveMinIsInclusive |
| 712 |
((Comparable<Object>)effectiveMin).compareTo(lowerBound) < 0); |
827 |
? ((Comparable<Object>)effectiveMin).compareTo(lowerBound) <= 0 |
|
|
828 |
: ((Comparable<Object>)effectiveMin).compareTo(lowerBound) < 0); |
| 713 |
if (lowerBounded) |
829 |
if (lowerBounded) |
| 714 |
{ |
830 |
{ |
| 715 |
effectiveMinIsInclusive = false; |
831 |
effectiveMinIsInclusive = false; |
|
Lines 717-723
Link Here
|
| 717 |
effectiveTotalDigitsMin = effectiveTotalDigits; |
833 |
effectiveTotalDigitsMin = effectiveTotalDigits; |
| 718 |
} |
834 |
} |
| 719 |
} |
835 |
} |
| 720 |
catch (NumberFormatException exception) |
836 |
catch (NumberFormatException exception) |
| 721 |
{ |
837 |
{ |
| 722 |
// Ignore the bound if the value is too big. |
838 |
// Ignore the bound if the value is too big. |
| 723 |
} |
839 |
} |
|
Lines 725-734
Link Here
|
| 725 |
try |
841 |
try |
| 726 |
{ |
842 |
{ |
| 727 |
Object upperBound = EcoreUtil.createFromString(eDataType, digits.toString()); |
843 |
Object upperBound = EcoreUtil.createFromString(eDataType, digits.toString()); |
| 728 |
@SuppressWarnings("unchecked") boolean upperBounded = effectiveMax == null || |
844 |
@SuppressWarnings("unchecked") |
| 729 |
(effectiveMaxIsInclusive ? |
845 |
boolean upperBounded = effectiveMax == null |
| 730 |
((Comparable<Object>)effectiveMax).compareTo(upperBound) >= 0: |
846 |
|| (effectiveMaxIsInclusive |
| 731 |
((Comparable<Object>)effectiveMax).compareTo(upperBound) > 0); |
847 |
? ((Comparable<Object>)effectiveMax).compareTo(upperBound) >= 0 |
|
|
848 |
: ((Comparable<Object>)effectiveMax).compareTo(upperBound) > 0); |
| 732 |
if (upperBounded) |
849 |
if (upperBounded) |
| 733 |
{ |
850 |
{ |
| 734 |
effectiveMaxIsInclusive = false; |
851 |
effectiveMaxIsInclusive = false; |
|
Lines 736-742
Link Here
|
| 736 |
effectiveTotalDigitsMax = effectiveTotalDigits; |
853 |
effectiveTotalDigitsMax = effectiveTotalDigits; |
| 737 |
} |
854 |
} |
| 738 |
} |
855 |
} |
| 739 |
catch (NumberFormatException exception) |
856 |
catch (NumberFormatException exception) |
| 740 |
{ |
857 |
{ |
| 741 |
// Ignore the bound if the value is too big. |
858 |
// Ignore the bound if the value is too big. |
| 742 |
} |
859 |
} |
|
Lines 757-763
Link Here
|
| 757 |
{ |
874 |
{ |
| 758 |
if (!effectiveEnumeration.contains(value)) |
875 |
if (!effectiveEnumeration.contains(value)) |
| 759 |
{ |
876 |
{ |
| 760 |
if (diagnostics != null) reportEnumerationViolation(eDataType, value, effectiveEnumeration, diagnostics, context); |
877 |
if (diagnostics != null) |
|
|
878 |
reportEnumerationViolation(eDataType, value, effectiveEnumeration, diagnostics, context); |
| 761 |
result = false; |
879 |
result = false; |
| 762 |
} |
880 |
} |
| 763 |
} |
881 |
} |
|
Lines 769-778
Link Here
|
| 769 |
|
887 |
|
| 770 |
if (effectiveMin != null) |
888 |
if (effectiveMin != null) |
| 771 |
{ |
889 |
{ |
| 772 |
@SuppressWarnings("unchecked") Comparable<Object> comparableObject = (Comparable<Object>)effectiveMin; |
890 |
@SuppressWarnings("unchecked") |
| 773 |
if (effectiveMinIsInclusive ? |
891 |
Comparable<Object> comparableObject = (Comparable<Object>)effectiveMin; |
| 774 |
comparableObject.compareTo(value) > 0: |
892 |
if (effectiveMinIsInclusive ? comparableObject.compareTo(value) > 0 : comparableObject.compareTo(value) >= 0) |
| 775 |
comparableObject.compareTo(value) >= 0) |
|
|
| 776 |
{ |
893 |
{ |
| 777 |
if (diagnostics != null) |
894 |
if (diagnostics != null) |
| 778 |
{ |
895 |
{ |
|
Lines 791-800
Link Here
|
| 791 |
|
908 |
|
| 792 |
if (effectiveMax != null) |
909 |
if (effectiveMax != null) |
| 793 |
{ |
910 |
{ |
| 794 |
@SuppressWarnings("unchecked") Comparable<Object> comparableObject = (Comparable<Object>)effectiveMax; |
911 |
@SuppressWarnings("unchecked") |
| 795 |
if (effectiveMaxIsInclusive ? |
912 |
Comparable<Object> comparableObject = (Comparable<Object>)effectiveMax; |
| 796 |
comparableObject.compareTo(value) < 0: |
913 |
if (effectiveMaxIsInclusive ? comparableObject.compareTo(value) < 0 : comparableObject.compareTo(value) <= 0) |
| 797 |
comparableObject.compareTo(value) <= 0) |
|
|
| 798 |
{ |
914 |
{ |
| 799 |
if (diagnostics != null) |
915 |
if (diagnostics != null) |
| 800 |
{ |
916 |
{ |
|
Lines 813-842
Link Here
|
| 813 |
|
929 |
|
| 814 |
if (effectiveMinLength != -1) |
930 |
if (effectiveMinLength != -1) |
| 815 |
{ |
931 |
{ |
| 816 |
int length = |
932 |
int length = value instanceof String ? ((String)value).length() : value instanceof Collection |
| 817 |
value instanceof String ? |
933 |
? ((Collection< ? >)value).size() : Array.getLength(value); |
| 818 |
((String)value).length() : |
|
|
| 819 |
value instanceof Collection ? |
| 820 |
((Collection<?>)value).size() : |
| 821 |
Array.getLength(value); |
| 822 |
if (length < effectiveMinLength) |
934 |
if (length < effectiveMinLength) |
| 823 |
{ |
935 |
{ |
| 824 |
if (diagnostics != null) reportMinLengthViolation(eDataType, value, length, effectiveMinLength, diagnostics, context); |
936 |
if (diagnostics != null) |
|
|
937 |
reportMinLengthViolation(eDataType, value, length, effectiveMinLength, diagnostics, context); |
| 825 |
result = false; |
938 |
result = false; |
| 826 |
} |
939 |
} |
| 827 |
} |
940 |
} |
| 828 |
|
941 |
|
| 829 |
if (effectiveMaxLength != -1) |
942 |
if (effectiveMaxLength != -1) |
| 830 |
{ |
943 |
{ |
| 831 |
int length = |
944 |
int length = value instanceof String ? ((String)value).length() : value instanceof Collection |
| 832 |
value instanceof String ? |
945 |
? ((Collection< ? >)value).size() : Array.getLength(value); |
| 833 |
((String)value).length() : |
|
|
| 834 |
value instanceof Collection ? |
| 835 |
((Collection<?>)value).size() : |
| 836 |
Array.getLength(value); |
| 837 |
if (length > effectiveMaxLength) |
946 |
if (length > effectiveMaxLength) |
| 838 |
{ |
947 |
{ |
| 839 |
if (diagnostics != null) reportMaxLengthViolation(eDataType, value, length, effectiveMaxLength, diagnostics, context); |
948 |
if (diagnostics != null) |
|
|
949 |
reportMaxLengthViolation(eDataType, value, length, effectiveMaxLength, diagnostics, context); |
| 840 |
result = false; |
950 |
result = false; |
| 841 |
} |
951 |
} |
| 842 |
} |
952 |
} |
|
Lines 845-851
Link Here
|
| 845 |
{ |
955 |
{ |
| 846 |
if (value instanceof BigDecimal && ((BigDecimal)value).unscaledValue().abs().toString().length() > effectiveTotalDigits) |
956 |
if (value instanceof BigDecimal && ((BigDecimal)value).unscaledValue().abs().toString().length() > effectiveTotalDigits) |
| 847 |
{ |
957 |
{ |
| 848 |
if (diagnostics != null) reportTotalDigitsViolation(eDataType, value, effectiveTotalDigits, diagnostics, context); |
958 |
if (diagnostics != null) |
|
|
959 |
reportTotalDigitsViolation(eDataType, value, effectiveTotalDigits, diagnostics, context); |
| 849 |
result = false; |
960 |
result = false; |
| 850 |
} |
961 |
} |
| 851 |
} |
962 |
} |
|
Lines 854-860
Link Here
|
| 854 |
{ |
965 |
{ |
| 855 |
if (value instanceof BigDecimal && ((BigDecimal)value).scale() > effectiveFractionDigits) |
966 |
if (value instanceof BigDecimal && ((BigDecimal)value).scale() > effectiveFractionDigits) |
| 856 |
{ |
967 |
{ |
| 857 |
if (diagnostics != null) reportFractionDigitsViolation(eDataType, value, effectiveFractionDigits, diagnostics, context); |
968 |
if (diagnostics != null) |
|
|
969 |
reportFractionDigitsViolation(eDataType, value, effectiveFractionDigits, diagnostics, context); |
| 858 |
result = false; |
970 |
result = false; |
| 859 |
} |
971 |
} |
| 860 |
} |
972 |
} |
|
Lines 862-868
Link Here
|
| 862 |
if (itemType != null) |
974 |
if (itemType != null) |
| 863 |
{ |
975 |
{ |
| 864 |
EValidator rootValidator = getRootEValidator(context); |
976 |
EValidator rootValidator = getRootEValidator(context); |
| 865 |
for (Iterator<?> i = ((List<?>)value).iterator(); i.hasNext() && (result || diagnostics != null); ) |
977 |
for (Iterator< ? > i = ((List< ? >)value).iterator(); i.hasNext() && (result || diagnostics != null);) |
| 866 |
{ |
978 |
{ |
| 867 |
result &= rootValidator.validate(itemType, i.next(), diagnostics, context); |
979 |
result &= rootValidator.validate(itemType, i.next(), diagnostics, context); |
| 868 |
} |
980 |
} |
|
Lines 871-877
Link Here
|
| 871 |
else if (!memberTypes.isEmpty()) |
983 |
else if (!memberTypes.isEmpty()) |
| 872 |
{ |
984 |
{ |
| 873 |
EValidator rootValidator = getRootEValidator(context); |
985 |
EValidator rootValidator = getRootEValidator(context); |
| 874 |
|
986 |
|
| 875 |
for (EDataType memberType : memberTypes) |
987 |
for (EDataType memberType : memberTypes) |
| 876 |
{ |
988 |
{ |
| 877 |
if (rootValidator.validate(memberType, value, null, context)) |
989 |
if (rootValidator.validate(memberType, value, null, context)) |
|
Lines 905-911
Link Here
|
| 905 |
} |
1017 |
} |
| 906 |
else |
1018 |
else |
| 907 |
{ |
1019 |
{ |
| 908 |
if (diagnostics != null) reportDataValueTypeViolation(eDataType, value, diagnostics, context); |
1020 |
if (diagnostics != null) |
|
|
1021 |
reportDataValueTypeViolation(eDataType, value, diagnostics, context); |
| 909 |
return false; |
1022 |
return false; |
| 910 |
} |
1023 |
} |
| 911 |
} |
1024 |
} |
|
Lines 916-923
Link Here
|
| 916 |
} |
1029 |
} |
| 917 |
else |
1030 |
else |
| 918 |
{ |
1031 |
{ |
| 919 |
return |
1032 |
return new DynamicEDataTypeValidator(eDataType) |
| 920 |
new DynamicEDataTypeValidator(eDataType) |
|
|
| 921 |
{ |
1033 |
{ |
| 922 |
// Ensure that the class loader for this class will be used downstream. |
1034 |
// Ensure that the class loader for this class will be used downstream. |
| 923 |
// |
1035 |
// |
|
Lines 925-1126
Link Here
|
| 925 |
} |
1037 |
} |
| 926 |
} |
1038 |
} |
| 927 |
|
1039 |
|
| 928 |
protected void reportMinViolation |
1040 |
protected void reportMinViolation( |
| 929 |
(EDataType eDataType, Object value, Object bound, boolean isInclusive, DiagnosticChain diagnostics, Map<Object, Object> context) |
1041 |
EDataType eDataType, |
| 930 |
{ |
1042 |
Object value, |
| 931 |
diagnostics.add |
1043 |
Object bound, |
| 932 |
(createDiagnostic |
1044 |
boolean isInclusive, |
| 933 |
(Diagnostic.ERROR, |
1045 |
DiagnosticChain diagnostics, |
| 934 |
DIAGNOSTIC_SOURCE, |
1046 |
Map<Object, Object> context) |
| 935 |
DATA_VALUE__VALUE_IN_RANGE, |
1047 |
{ |
| 936 |
isInclusive ? "_UI_MinInclusiveConstraint_diagnostic" : "_UI_MinExclusiveConstraint_diagnostic", |
1048 |
diagnostics.add(createDiagnostic(Diagnostic.ERROR, DIAGNOSTIC_SOURCE, DATA_VALUE__VALUE_IN_RANGE, isInclusive |
| 937 |
new Object [] |
1049 |
? "_UI_MinInclusiveConstraint_diagnostic" : "_UI_MinExclusiveConstraint_diagnostic", new Object []{ |
| 938 |
{ |
1050 |
getValueLabel(eDataType, value, context), |
| 939 |
getValueLabel(eDataType, value, context), |
1051 |
isInclusive ? ">=" : ">", |
| 940 |
isInclusive ? ">=" : ">", |
1052 |
getValueLabel(eDataType, bound, context) }, new Object []{ value, bound, isInclusive ? Boolean.TRUE : Boolean.FALSE }, context)); |
| 941 |
getValueLabel(eDataType, bound, context) |
1053 |
} |
| 942 |
}, |
1054 |
|
| 943 |
new Object [] { value, bound, isInclusive ? Boolean.TRUE : Boolean.FALSE }, |
1055 |
protected void reportMaxViolation( |
| 944 |
context)); |
1056 |
EDataType eDataType, |
| 945 |
} |
1057 |
Object value, |
| 946 |
|
1058 |
Object bound, |
| 947 |
protected void reportMaxViolation |
1059 |
boolean isInclusive, |
| 948 |
(EDataType eDataType, Object value, Object bound, boolean isInclusive, DiagnosticChain diagnostics, Map<Object, Object> context) |
1060 |
DiagnosticChain diagnostics, |
| 949 |
{ |
1061 |
Map<Object, Object> context) |
| 950 |
diagnostics.add |
1062 |
{ |
| 951 |
(createDiagnostic |
1063 |
diagnostics.add(createDiagnostic(Diagnostic.ERROR, DIAGNOSTIC_SOURCE, DATA_VALUE__VALUE_IN_RANGE, isInclusive |
| 952 |
(Diagnostic.ERROR, |
1064 |
? "_UI_MaxInclusiveConstraint_diagnostic" : "_UI_MaxExclusiveConstraint_diagnostic", new Object []{ |
| 953 |
DIAGNOSTIC_SOURCE, |
1065 |
getValueLabel(eDataType, value, context), |
| 954 |
DATA_VALUE__VALUE_IN_RANGE, |
1066 |
"<", |
| 955 |
isInclusive ? "_UI_MaxInclusiveConstraint_diagnostic" : "_UI_MaxExclusiveConstraint_diagnostic", |
1067 |
getValueLabel(eDataType, bound, context) }, new Object []{ value, bound, isInclusive ? Boolean.TRUE : Boolean.FALSE }, context)); |
| 956 |
new Object [] |
1068 |
} |
| 957 |
{ |
1069 |
|
| 958 |
getValueLabel(eDataType, value, context), |
1070 |
protected void reportMinLengthViolation( |
| 959 |
"<", |
1071 |
EDataType eDataType, |
| 960 |
getValueLabel(eDataType, bound, context) |
1072 |
Object value, |
| 961 |
}, |
1073 |
int length, |
| 962 |
new Object [] { value, bound, isInclusive ? Boolean.TRUE : Boolean.FALSE }, |
1074 |
int bound, |
| 963 |
context)); |
1075 |
DiagnosticChain diagnostics, |
| 964 |
} |
1076 |
Map<Object, Object> context) |
| 965 |
|
1077 |
{ |
| 966 |
protected void reportMinLengthViolation |
1078 |
diagnostics.add(createDiagnostic( |
| 967 |
(EDataType eDataType, Object value, int length, int bound, DiagnosticChain diagnostics, Map<Object, Object> context) |
1079 |
Diagnostic.ERROR, |
| 968 |
{ |
1080 |
DIAGNOSTIC_SOURCE, |
| 969 |
diagnostics.add |
1081 |
DATA_VALUE__LENGTH_IN_RANGE, |
| 970 |
(createDiagnostic |
1082 |
"_UI_MinLengthConstraint_diagnostic", |
| 971 |
(Diagnostic.ERROR, |
1083 |
new Object []{ getValueLabel(eDataType, value, context), Integer.toString(length), Integer.toString(bound) }, |
| 972 |
DIAGNOSTIC_SOURCE, |
1084 |
new Object []{ value, eDataType, length, bound }, |
| 973 |
DATA_VALUE__LENGTH_IN_RANGE, |
1085 |
context)); |
| 974 |
"_UI_MinLengthConstraint_diagnostic", |
1086 |
} |
| 975 |
new Object [] |
1087 |
|
| 976 |
{ |
1088 |
protected void reportMaxLengthViolation( |
| 977 |
getValueLabel(eDataType, value, context), |
1089 |
EDataType eDataType, |
| 978 |
Integer.toString(length), |
1090 |
Object value, |
| 979 |
Integer.toString(bound) |
1091 |
int length, |
| 980 |
}, |
1092 |
int bound, |
| 981 |
new Object [] { value, eDataType, length, bound }, |
1093 |
DiagnosticChain diagnostics, |
| 982 |
context)); |
1094 |
Map<Object, Object> context) |
| 983 |
} |
1095 |
{ |
| 984 |
|
1096 |
diagnostics.add(createDiagnostic( |
| 985 |
protected void reportMaxLengthViolation |
1097 |
Diagnostic.ERROR, |
| 986 |
(EDataType eDataType, Object value, int length, int bound, DiagnosticChain diagnostics, Map<Object, Object> context) |
1098 |
DIAGNOSTIC_SOURCE, |
| 987 |
{ |
1099 |
DATA_VALUE__LENGTH_IN_RANGE, |
| 988 |
diagnostics.add |
1100 |
"_UI_MaxLengthConstraint_diagnostic", |
| 989 |
(createDiagnostic |
1101 |
new Object []{ getValueLabel(eDataType, value, context), Integer.toString(length), Integer.toString(bound) }, |
| 990 |
(Diagnostic.ERROR, |
1102 |
new Object []{ value, eDataType, length, bound }, |
| 991 |
DIAGNOSTIC_SOURCE, |
1103 |
context)); |
| 992 |
DATA_VALUE__LENGTH_IN_RANGE, |
1104 |
} |
| 993 |
"_UI_MaxLengthConstraint_diagnostic", |
1105 |
|
| 994 |
new Object [] |
1106 |
protected void reportTotalDigitsViolation( |
| 995 |
{ |
1107 |
EDataType eDataType, |
| 996 |
getValueLabel(eDataType, value, context), |
1108 |
Object value, |
| 997 |
Integer.toString(length), |
1109 |
int totalDigits, |
| 998 |
Integer.toString(bound) |
1110 |
DiagnosticChain diagnostics, |
| 999 |
}, |
1111 |
Map<Object, Object> context) |
| 1000 |
new Object [] { value, eDataType, length, bound }, |
1112 |
{ |
| 1001 |
context)); |
1113 |
diagnostics.add(createDiagnostic( |
| 1002 |
} |
1114 |
Diagnostic.ERROR, |
| 1003 |
|
1115 |
DIAGNOSTIC_SOURCE, |
| 1004 |
protected void reportTotalDigitsViolation |
1116 |
DATA_VALUE__TOTAL_DIGITS_IN_RANGE, |
| 1005 |
(EDataType eDataType, Object value, int totalDigits, DiagnosticChain diagnostics, Map<Object, Object> context) |
1117 |
"_UI_TotalDigitsConstraint_diagnostic", |
| 1006 |
{ |
1118 |
new Object []{ getValueLabel(eDataType, value, context), totalDigits }, |
| 1007 |
diagnostics.add |
1119 |
new Object []{ value, eDataType, totalDigits }, |
| 1008 |
(createDiagnostic |
1120 |
context)); |
| 1009 |
(Diagnostic.ERROR, |
1121 |
} |
| 1010 |
DIAGNOSTIC_SOURCE, |
1122 |
|
| 1011 |
DATA_VALUE__TOTAL_DIGITS_IN_RANGE, |
1123 |
protected void reportFractionDigitsViolation( |
| 1012 |
"_UI_TotalDigitsConstraint_diagnostic", |
1124 |
EDataType eDataType, |
| 1013 |
new Object [] |
1125 |
Object value, |
| 1014 |
{ |
1126 |
int fractionDigits, |
| 1015 |
getValueLabel(eDataType, value, context), |
1127 |
DiagnosticChain diagnostics, |
| 1016 |
totalDigits |
1128 |
Map<Object, Object> context) |
| 1017 |
}, |
1129 |
{ |
| 1018 |
new Object [] { value, eDataType, totalDigits }, |
1130 |
diagnostics.add(createDiagnostic( |
| 1019 |
context)); |
1131 |
Diagnostic.ERROR, |
| 1020 |
} |
1132 |
DIAGNOSTIC_SOURCE, |
| 1021 |
|
1133 |
DATA_VALUE__TOTAL_DIGITS_IN_RANGE, |
| 1022 |
protected void reportFractionDigitsViolation |
1134 |
"_UI_FractionDigitsConstraint_diagnostic", |
| 1023 |
(EDataType eDataType, Object value, int fractionDigits, DiagnosticChain diagnostics, Map<Object, Object> context) |
1135 |
new Object []{ getValueLabel(eDataType, value, context), fractionDigits }, |
| 1024 |
{ |
1136 |
new Object []{ value, eDataType, fractionDigits }, |
| 1025 |
diagnostics.add |
1137 |
context)); |
| 1026 |
(createDiagnostic |
1138 |
} |
| 1027 |
(Diagnostic.ERROR, |
1139 |
|
| 1028 |
DIAGNOSTIC_SOURCE, |
1140 |
protected void reportEnumerationViolation( |
| 1029 |
DATA_VALUE__TOTAL_DIGITS_IN_RANGE, |
1141 |
EDataType eDataType, |
| 1030 |
"_UI_FractionDigitsConstraint_diagnostic", |
1142 |
Object value, |
| 1031 |
new Object [] |
1143 |
Collection< ? > values, |
| 1032 |
{ |
1144 |
DiagnosticChain diagnostics, |
| 1033 |
getValueLabel(eDataType, value, context), |
1145 |
Map<Object, Object> context) |
| 1034 |
fractionDigits |
|
|
| 1035 |
}, |
| 1036 |
new Object [] { value, eDataType, fractionDigits }, |
| 1037 |
context)); |
| 1038 |
} |
| 1039 |
|
| 1040 |
protected void reportEnumerationViolation |
| 1041 |
(EDataType eDataType, Object value, Collection<?> values, DiagnosticChain diagnostics, Map<Object, Object> context) |
| 1042 |
{ |
1146 |
{ |
| 1043 |
String valueLiterals = ""; |
1147 |
String valueLiterals = ""; |
| 1044 |
Iterator<?> i = values.iterator(); |
1148 |
Iterator< ? > i = values.iterator(); |
| 1045 |
if (i.hasNext()) |
1149 |
if (i.hasNext()) |
| 1046 |
{ |
1150 |
{ |
| 1047 |
valueLiterals = |
1151 |
valueLiterals = getEcoreResourceLocator().getString( |
| 1048 |
getEcoreResourceLocator().getString("_UI_ListHead_composition", new Object [] { getValueLabel(eDataType, i.next(), context) }); |
1152 |
"_UI_ListHead_composition", |
|
|
1153 |
new Object []{ getValueLabel(eDataType, i.next(), context) }); |
| 1049 |
while (i.hasNext()) |
1154 |
while (i.hasNext()) |
| 1050 |
{ |
1155 |
{ |
| 1051 |
valueLiterals = |
1156 |
valueLiterals = getEcoreResourceLocator().getString( |
| 1052 |
getEcoreResourceLocator().getString |
1157 |
"_UI_ListTail_composition", |
| 1053 |
("_UI_ListTail_composition", |
1158 |
new Object []{ valueLiterals, getValueLabel(eDataType, i.next(), context) }); |
| 1054 |
new Object [] { valueLiterals, getValueLabel(eDataType, i.next(), context) }); |
1159 |
} |
| 1055 |
} |
1160 |
} |
| 1056 |
} |
1161 |
diagnostics.add(createDiagnostic( |
| 1057 |
diagnostics.add |
1162 |
Diagnostic.ERROR, |
| 1058 |
(createDiagnostic |
1163 |
DIAGNOSTIC_SOURCE, |
| 1059 |
(Diagnostic.ERROR, |
1164 |
DATA_VALUE__VALUE_IN_ENUMERATION, |
| 1060 |
DIAGNOSTIC_SOURCE, |
1165 |
"_UI_EnumerationConstraint_diagnostic", |
| 1061 |
DATA_VALUE__VALUE_IN_ENUMERATION, |
1166 |
new Object []{ getValueLabel(eDataType, value, context), valueLiterals }, |
| 1062 |
"_UI_EnumerationConstraint_diagnostic", |
1167 |
new Object []{ value, eDataType, values }, |
| 1063 |
new Object [] |
1168 |
context)); |
| 1064 |
{ |
1169 |
} |
| 1065 |
getValueLabel(eDataType, value, context), |
1170 |
|
| 1066 |
valueLiterals |
1171 |
protected void reportDataValuePatternViolation( |
| 1067 |
}, |
1172 |
EDataType eDataType, |
| 1068 |
new Object [] { value, eDataType, values }, |
1173 |
Object value, |
| 1069 |
context)); |
1174 |
PatternMatcher[] patterns, |
| 1070 |
} |
1175 |
DiagnosticChain diagnostics, |
| 1071 |
|
1176 |
Map<Object, Object> context) |
| 1072 |
protected void reportDataValuePatternViolation |
|
|
| 1073 |
(EDataType eDataType, Object value, PatternMatcher [] patterns, DiagnosticChain diagnostics, Map<Object, Object> context) |
| 1074 |
{ |
1177 |
{ |
| 1075 |
String patternLiterals = ""; |
1178 |
String patternLiterals = ""; |
| 1076 |
if (patterns.length > 0) |
1179 |
if (patterns.length > 0) |
| 1077 |
{ |
1180 |
{ |
| 1078 |
patternLiterals = getEcoreResourceLocator().getString("_UI_ListHead_composition", new Object [] { patterns[0] }); |
1181 |
patternLiterals = getEcoreResourceLocator().getString("_UI_ListHead_composition", new Object []{ patterns[0] }); |
| 1079 |
for (int i = 1; i < patterns.length; ++i) |
1182 |
for (int i = 1; i < patterns.length; ++i) |
| 1080 |
{ |
1183 |
{ |
| 1081 |
patternLiterals = getEcoreResourceLocator().getString("_UI_ListTail_composition", new Object [] { patternLiterals, patterns[i] }); |
1184 |
patternLiterals = getEcoreResourceLocator().getString("_UI_ListTail_composition", new Object []{ patternLiterals, patterns[i] }); |
| 1082 |
} |
1185 |
} |
| 1083 |
} |
1186 |
} |
| 1084 |
|
1187 |
|
| 1085 |
diagnostics.add |
1188 |
diagnostics.add(createDiagnostic( |
| 1086 |
(createDiagnostic |
1189 |
Diagnostic.ERROR, |
| 1087 |
(Diagnostic.ERROR, |
1190 |
DIAGNOSTIC_SOURCE, |
| 1088 |
DIAGNOSTIC_SOURCE, |
1191 |
DATA_VALUE__MATCHES_PATTERN, |
| 1089 |
DATA_VALUE__MATCHES_PATTERN, |
1192 |
"_UI_PatternConstraint_diagnostic", |
| 1090 |
"_UI_PatternConstraint_diagnostic", |
1193 |
new Object []{ getValueLabel(eDataType, value, context), patternLiterals }, |
| 1091 |
new Object [] |
1194 |
new Object []{ value, eDataType, patterns }, |
| 1092 |
{ |
1195 |
context)); |
| 1093 |
getValueLabel(eDataType, value, context), |
1196 |
} |
| 1094 |
patternLiterals |
1197 |
|
| 1095 |
}, |
1198 |
protected void reportDataValueTypeViolation(EDataType eDataType, Object value, DiagnosticChain diagnostics, Map<Object, Object> context) |
| 1096 |
new Object [] { value, eDataType, patterns }, |
1199 |
{ |
| 1097 |
context)); |
1200 |
diagnostics.add(createDiagnostic( |
| 1098 |
} |
1201 |
Diagnostic.ERROR, |
| 1099 |
|
1202 |
DIAGNOSTIC_SOURCE, |
| 1100 |
protected void reportDataValueTypeViolation |
1203 |
DATA_VALUE__TYPE_CORRECT, |
| 1101 |
(EDataType eDataType, Object value, DiagnosticChain diagnostics, Map<Object, Object> context) |
1204 |
"_UI_BadDataValueType_diagnostic", |
| 1102 |
{ |
1205 |
new Object []{ |
| 1103 |
diagnostics.add |
1206 |
getValueLabel(eDataType, value, context), |
| 1104 |
(createDiagnostic |
1207 |
value == null ? "<null>" : value.getClass().getName(), |
| 1105 |
(Diagnostic.ERROR, |
1208 |
eDataType.getInstanceClass().getName() }, |
| 1106 |
DIAGNOSTIC_SOURCE, |
1209 |
new Object []{ value, eDataType }, |
| 1107 |
DATA_VALUE__TYPE_CORRECT, |
1210 |
context)); |
| 1108 |
"_UI_BadDataValueType_diagnostic", |
|
|
| 1109 |
new Object [] |
| 1110 |
{ |
| 1111 |
getValueLabel(eDataType, value, context), |
| 1112 |
value == null ? "<null>" : value.getClass().getName(), |
| 1113 |
eDataType.getInstanceClass().getName() |
| 1114 |
}, |
| 1115 |
new Object [] { value, eDataType }, |
| 1116 |
context)); |
| 1117 |
} |
1211 |
} |
| 1118 |
|
1212 |
|
| 1119 |
protected static Collection<Object> wrapEnumerationValues(Object [] values) |
1213 |
protected static Collection<Object> wrapEnumerationValues(Object[] values) |
| 1120 |
{ |
1214 |
{ |
| 1121 |
return java.util.Arrays.asList(values); |
1215 |
return java.util.Arrays.asList(values); |
| 1122 |
} |
1216 |
} |
| 1123 |
|
1217 |
|
| 1124 |
/** |
1218 |
/** |
| 1125 |
* @since 2.2 |
1219 |
* @since 2.2 |
| 1126 |
*/ |
1220 |
*/ |
|
Lines 1137-1156
Link Here
|
| 1137 |
if (eObject != otherEObject && otherEObject != null) |
1231 |
if (eObject != otherEObject && otherEObject != null) |
| 1138 |
{ |
1232 |
{ |
| 1139 |
// ... |
1233 |
// ... |
| 1140 |
diagnostics.add |
1234 |
diagnostics.add(createDiagnostic( |
| 1141 |
(createDiagnostic |
1235 |
Diagnostic.ERROR, |
| 1142 |
(Diagnostic.ERROR, |
1236 |
DIAGNOSTIC_SOURCE, |
| 1143 |
DIAGNOSTIC_SOURCE, |
1237 |
EOBJECT__UNIQUE_ID, |
| 1144 |
EOBJECT__UNIQUE_ID, |
1238 |
"_UI_DuplicateID_diagnostic", |
| 1145 |
"_UI_DuplicateID_diagnostic", |
1239 |
new Object []{ id, getObjectLabel(eObject, context), getObjectLabel(otherEObject, context) }, |
| 1146 |
new Object [] |
1240 |
new Object []{ eObject, otherEObject, id }, |
| 1147 |
{ |
1241 |
context)); |
| 1148 |
id, |
|
|
| 1149 |
getObjectLabel(eObject, context), |
| 1150 |
getObjectLabel(otherEObject, context) |
| 1151 |
}, |
| 1152 |
new Object [] { eObject, otherEObject, id }, |
| 1153 |
context)); |
| 1154 |
} |
1242 |
} |
| 1155 |
} |
1243 |
} |
| 1156 |
} |
1244 |
} |
|
Lines 1186-1192
Link Here
|
| 1186 |
} |
1274 |
} |
| 1187 |
return result; |
1275 |
return result; |
| 1188 |
} |
1276 |
} |
| 1189 |
|
1277 |
|
| 1190 |
/** |
1278 |
/** |
| 1191 |
* @since 2.3 |
1279 |
* @since 2.3 |
| 1192 |
* @param eObject |
1280 |
* @param eObject |
|
Lines 1195-1211
Link Here
|
| 1195 |
* @param context |
1283 |
* @param context |
| 1196 |
* @return whether every key is unique. |
1284 |
* @return whether every key is unique. |
| 1197 |
*/ |
1285 |
*/ |
| 1198 |
protected boolean validate_KeyUnique |
1286 |
protected boolean validate_KeyUnique(EObject eObject, EReference eReference, DiagnosticChain diagnostics, Map<Object, Object> context) |
| 1199 |
(EObject eObject, EReference eReference, DiagnosticChain diagnostics, Map<Object, Object> context) |
|
|
| 1200 |
{ |
1287 |
{ |
| 1201 |
boolean result = true; |
1288 |
boolean result = true; |
| 1202 |
Map<List<Object>, EObject> keys = new HashMap<List<Object>, EObject>(); |
1289 |
Map<List<Object>, EObject> keys = new HashMap<List<Object>, EObject>(); |
| 1203 |
EAttribute [] eAttributes = (EAttribute[])((BasicEList<?>)eReference.getEKeys()).data(); |
1290 |
EAttribute[] eAttributes = (EAttribute[])((BasicEList< ? >)eReference.getEKeys()).data(); |
| 1204 |
@SuppressWarnings("unchecked") |
1291 |
@SuppressWarnings("unchecked") |
| 1205 |
List<EObject> values = (List<EObject>)eObject.eGet(eReference); |
1292 |
List<EObject> values = (List<EObject>)eObject.eGet(eReference); |
| 1206 |
for (EObject value : values) |
1293 |
for (EObject value : values) |
| 1207 |
{ |
1294 |
{ |
| 1208 |
ArrayList<Object> key = new ArrayList<Object>(); |
1295 |
ArrayList<Object> key = new ArrayList<Object>(); |
| 1209 |
for (int i = 0, size = eAttributes.length; i < size; ++i) |
1296 |
for (int i = 0, size = eAttributes.length; i < size; ++i) |
| 1210 |
{ |
1297 |
{ |
| 1211 |
EAttribute eAttribute = eAttributes[i]; |
1298 |
EAttribute eAttribute = eAttributes[i]; |
|
Lines 1213-1219
Link Here
|
| 1213 |
{ |
1300 |
{ |
| 1214 |
break; |
1301 |
break; |
| 1215 |
} |
1302 |
} |
| 1216 |
else |
1303 |
else |
| 1217 |
{ |
1304 |
{ |
| 1218 |
key.add(value.eGet(eAttribute)); |
1305 |
key.add(value.eGet(eAttribute)); |
| 1219 |
} |
1306 |
} |
|
Lines 1234-1254
Link Here
|
| 1234 |
{ |
1321 |
{ |
| 1235 |
uriFragmentSegment = uriFragmentSegment.substring(index); |
1322 |
uriFragmentSegment = uriFragmentSegment.substring(index); |
| 1236 |
} |
1323 |
} |
| 1237 |
diagnostics.add |
1324 |
diagnostics.add(createDiagnostic( |
| 1238 |
(createDiagnostic |
1325 |
Diagnostic.ERROR, |
| 1239 |
(Diagnostic.ERROR, |
1326 |
DIAGNOSTIC_SOURCE, |
| 1240 |
DIAGNOSTIC_SOURCE, |
1327 |
EOBJECT__EVERY_KEY_UNIQUE, |
| 1241 |
EOBJECT__EVERY_KEY_UNIQUE, |
1328 |
"_UI_DuplicateKey_diagnostic", |
| 1242 |
"_UI_DuplicateKey_diagnostic", |
1329 |
new Object []{ |
| 1243 |
new Object [] |
1330 |
getFeatureLabel(eReference, context), |
| 1244 |
{ |
1331 |
uriFragmentSegment, |
| 1245 |
getFeatureLabel(eReference, context), |
1332 |
getObjectLabel(value, context), |
| 1246 |
uriFragmentSegment, |
1333 |
getObjectLabel(otherValue, context) }, |
| 1247 |
getObjectLabel(value, context), |
1334 |
new Object []{ eObject, eReference, value, otherValue }, |
| 1248 |
getObjectLabel(otherValue, context) |
1335 |
context)); |
| 1249 |
}, |
|
|
| 1250 |
new Object [] { eObject, eReference, value, otherValue }, |
| 1251 |
context)); |
| 1252 |
} |
1336 |
} |
| 1253 |
} |
1337 |
} |
| 1254 |
} |
1338 |
} |
|
Lines 1291-1309
Link Here
|
| 1291 |
* @param context |
1375 |
* @param context |
| 1292 |
* @return whether every map entry is unique. |
1376 |
* @return whether every map entry is unique. |
| 1293 |
*/ |
1377 |
*/ |
| 1294 |
protected boolean validate_MapEntryUnique |
1378 |
protected boolean validate_MapEntryUnique(EObject eObject, EReference eReference, DiagnosticChain diagnostics, Map<Object, Object> context) |
| 1295 |
(EObject eObject, EReference eReference, DiagnosticChain diagnostics, Map<Object, Object> context) |
|
|
| 1296 |
{ |
1379 |
{ |
| 1297 |
boolean result = true; |
1380 |
boolean result = true; |
| 1298 |
Object value = eObject.eGet(eReference); |
1381 |
Object value = eObject.eGet(eReference); |
| 1299 |
if (value instanceof EMap) |
1382 |
if (value instanceof EMap) |
| 1300 |
{ |
1383 |
{ |
| 1301 |
EMap<?, ?> eMap = (EMap<?, ?>)value; |
1384 |
EMap< ? , ? > eMap = (EMap< ? , ? >)value; |
| 1302 |
for (int i = 0, size = eMap.size(); i < size; ++i) |
1385 |
for (int i = 0, size = eMap.size(); i < size; ++i) |
| 1303 |
{ |
1386 |
{ |
| 1304 |
Map.Entry<?, ?> entry = eMap.get(i); |
1387 |
Map.Entry< ? , ? > entry = eMap.get(i); |
| 1305 |
Object key = entry.getKey(); |
1388 |
Object key = entry.getKey(); |
| 1306 |
int index = eMap.indexOfKey(key); |
1389 |
int index = eMap.indexOfKey(key); |
| 1307 |
if (index != i) |
1390 |
if (index != i) |
| 1308 |
{ |
1391 |
{ |
| 1309 |
result = false; |
1392 |
result = false; |
|
Lines 1313-1332
Link Here
|
| 1313 |
} |
1396 |
} |
| 1314 |
else |
1397 |
else |
| 1315 |
{ |
1398 |
{ |
| 1316 |
diagnostics.add |
1399 |
diagnostics.add(createDiagnostic( |
| 1317 |
(createDiagnostic |
1400 |
Diagnostic.ERROR, |
| 1318 |
(Diagnostic.ERROR, |
1401 |
DIAGNOSTIC_SOURCE, |
| 1319 |
DIAGNOSTIC_SOURCE, |
1402 |
EOBJECT__EVERY_MAP_ENTRY_UNIQUE, |
| 1320 |
EOBJECT__EVERY_MAP_ENTRY_UNIQUE, |
1403 |
"_UI_DuplicateMapEntry_diagnostic", |
| 1321 |
"_UI_DuplicateMapEntry_diagnostic", |
1404 |
new Object []{ getFeatureLabel(eReference, context), i, index }, |
| 1322 |
new Object [] |
1405 |
new Object []{ eObject, eReference, entry, eMap.get(index) }, |
| 1323 |
{ |
1406 |
context)); |
| 1324 |
getFeatureLabel(eReference, context), |
|
|
| 1325 |
i, |
| 1326 |
index |
| 1327 |
}, |
| 1328 |
new Object [] { eObject, eReference, entry, eMap.get(index) }, |
| 1329 |
context)); |
| 1330 |
} |
1407 |
} |
| 1331 |
} |
1408 |
} |
| 1332 |
} |
1409 |
} |
|
Lines 1351-1363
Link Here
|
| 1351 |
* @see BasicDiagnostic#BasicDiagnostic(int, String, int, String, Object[]) |
1428 |
* @see BasicDiagnostic#BasicDiagnostic(int, String, int, String, Object[]) |
| 1352 |
* @since 2.4 |
1429 |
* @since 2.4 |
| 1353 |
*/ |
1430 |
*/ |
| 1354 |
protected BasicDiagnostic createDiagnostic |
1431 |
protected BasicDiagnostic createDiagnostic( |
| 1355 |
(int severity, String source, int code, String messageKey, Object[] messageSubstitutions, Object[] data, Map<Object, Object> context) |
1432 |
int severity, |
| 1356 |
{ |
1433 |
String source, |
| 1357 |
String message = |
1434 |
int code, |
| 1358 |
DIAGNOSTIC_SOURCE.equals(source) ? |
1435 |
String messageKey, |
| 1359 |
getEcoreString(messageKey, messageSubstitutions) : |
1436 |
Object[] messageSubstitutions, |
| 1360 |
getString(messageKey, messageSubstitutions); |
1437 |
Object[] data, |
|
|
1438 |
Map<Object, Object> context) |
| 1439 |
{ |
| 1440 |
String message = DIAGNOSTIC_SOURCE.equals(source) ? getEcoreString(messageKey, messageSubstitutions) : getString( |
| 1441 |
messageKey, |
| 1442 |
messageSubstitutions); |
| 1361 |
return new BasicDiagnostic(severity, source, code, message, data); |
1443 |
return new BasicDiagnostic(severity, source, code, message, data); |
| 1362 |
} |
1444 |
} |
| 1363 |
|
1445 |
|
|
Lines 1369-1375
Link Here
|
| 1369 |
* @return the message. |
1451 |
* @return the message. |
| 1370 |
* @since 2.4 |
1452 |
* @since 2.4 |
| 1371 |
*/ |
1453 |
*/ |
| 1372 |
protected String getEcoreString(String key, Object [] substitutions) |
1454 |
protected String getEcoreString(String key, Object[] substitutions) |
| 1373 |
{ |
1455 |
{ |
| 1374 |
return getString(getEcoreResourceLocator(), key, substitutions); |
1456 |
return getString(getEcoreResourceLocator(), key, substitutions); |
| 1375 |
} |
1457 |
} |
|
Lines 1392-1398
Link Here
|
| 1392 |
* @return the message. |
1474 |
* @return the message. |
| 1393 |
* @since 2.4 |
1475 |
* @since 2.4 |
| 1394 |
*/ |
1476 |
*/ |
| 1395 |
protected String getString(String key, Object [] substitutions) |
1477 |
protected String getString(String key, Object[] substitutions) |
| 1396 |
{ |
1478 |
{ |
| 1397 |
return getString("_UI_GenericConstraint_diagnostic".equals(key) ? getEcoreResourceLocator() : getResourceLocator(), key, substitutions); |
1479 |
return getString("_UI_GenericConstraint_diagnostic".equals(key) ? getEcoreResourceLocator() : getResourceLocator(), key, substitutions); |
| 1398 |
} |
1480 |
} |
|
Lines 1409-1415
Link Here
|
| 1409 |
return getEcoreResourceLocator(); |
1491 |
return getEcoreResourceLocator(); |
| 1410 |
} |
1492 |
} |
| 1411 |
|
1493 |
|
| 1412 |
private String getString(ResourceLocator resourceLocator, String key, Object [] substitutions) |
1494 |
private String getString(ResourceLocator resourceLocator, String key, Object[] substitutions) |
| 1413 |
{ |
1495 |
{ |
| 1414 |
return substitutions == null ? resourceLocator.getString(key) : resourceLocator.getString(key, substitutions); |
1496 |
return substitutions == null ? resourceLocator.getString(key) : resourceLocator.getString(key, substitutions); |
| 1415 |
} |
1497 |
} |