diff options
author | Ed Willink | 2020-05-14 09:24:49 +0000 |
---|---|---|
committer | Ed Willink | 2020-05-19 09:22:42 +0000 |
commit | 8f03684ef94d47f4ae8525b99f54662db4e6b2ca (patch) | |
tree | 6643d80ef9b9208dd6f0d4c3cd7091bb4ce21d9b /plugins/org.eclipse.emf.ecore/src/org/eclipse/emf | |
parent | ddc40eebf8bee151de2556ee49a1752c7fddc601 (diff) | |
download | org.eclipse.emf-8f03684ef94d47f4ae8525b99f54662db4e6b2ca.tar.gz org.eclipse.emf-8f03684ef94d47f4ae8525b99f54662db4e6b2ca.tar.xz org.eclipse.emf-8f03684ef94d47f4ae8525b99f54662db4e6b2ca.zip |
[563242] Use try-catch to show crashed validations
Change-Id: I08ce1ba7a734a7610557db9c8dc6d8575114b6d0
Signed-off-by: Ed Willink <ed@willink.me.uk>
Diffstat (limited to 'plugins/org.eclipse.emf.ecore/src/org/eclipse/emf')
-rw-r--r-- | plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/util/Diagnostician.java | 71 |
1 files changed, 57 insertions, 14 deletions
diff --git a/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/util/Diagnostician.java b/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/util/Diagnostician.java index b6070c111..6d07adf39 100644 --- a/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/util/Diagnostician.java +++ b/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/util/Diagnostician.java @@ -224,28 +224,71 @@ public class Diagnostician implements EValidator.SubstitutionLabelProvider, EVal */ public boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) { - Object eValidator; - EClass eType = eClass; - while ((eValidator = eValidatorRegistry.get(eType.eContainer())) == null) + try { - List<EClass> eSuperTypes = eType.getESuperTypes(); - if (eSuperTypes.isEmpty()) + Object eValidator; + EClass eType = eClass; + while ((eValidator = eValidatorRegistry.get(eType.eContainer())) == null) { - eValidator = eValidatorRegistry.get(null); - break; + List<EClass> eSuperTypes = eType.getESuperTypes(); + if (eSuperTypes.isEmpty()) + { + eValidator = eValidatorRegistry.get(null); + break; + } + else + { + eType = eSuperTypes.get(0); + } } - else + boolean circular = context.get(EObjectValidator.ROOT_OBJECT) == eObject; + boolean result = doValidate((EValidator)eValidator, eClass, eObject, diagnostics, context); + if (!Boolean.FALSE.equals(context.get(VALIDATE_RECURSIVELY)) && (result || diagnostics != null) && !circular) { - eType = eSuperTypes.get(0); + result &= doValidateContents(eObject, diagnostics, context); } + return result; } - boolean circular = context.get(EObjectValidator.ROOT_OBJECT) == eObject; - boolean result = doValidate((EValidator)eValidator, eClass, eObject, diagnostics, context); - if (!Boolean.FALSE.equals(context.get(VALIDATE_RECURSIVELY)) && (result || diagnostics != null) && !circular) + catch (RuntimeException e) + { + if (!handleThrowable(eClass, eObject, diagnostics, context, e)) + { + throw e; + } + } + catch (Error e) + { + if (!handleThrowable(eClass, eObject, diagnostics, context, e)) + { + throw e; + } + } + return false; + } + + /** + * Called by {@link #validate(EClass, EObject, DiagnosticChain, Map)} when an exception is thrown during validation. + * If diagnostics are being recorded and the exception is a {@link RuntimeException} or an {@link AssertionError}, + * a diagnostic is created and added to the diagnostics to record the exception. + * + * Returns true if the throwable has been adequately handled, false if the caller should rethrow it. + * + * @since 2.22 + */ + protected boolean handleThrowable(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context, Throwable throwable) + { + if (diagnostics != null && throwable instanceof RuntimeException || throwable instanceof AssertionError) + { + Object[] messageSubstitutions = new Object []{ EObjectValidator.getObjectLabel(eObject, context) }; + String message = EcorePlugin.INSTANCE.getString("_UI_ValidationFailed_diagnostic", messageSubstitutions); + Object[] data = new Object []{ eObject, throwable }; + diagnostics.add(new BasicDiagnostic(Diagnostic.ERROR, EObjectValidator.DIAGNOSTIC_SOURCE, -1, message, data)); + return true; + } + else { - result &= doValidateContents(eObject, diagnostics, context); + return false; } - return result; } /** |