From 426a3951f28a216f28b4d808c02f3d8defa73e4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Galland?= Date: Tue, 6 Mar 2018 10:16:12 +0100 Subject: [PATCH] [lang] Internal errors within the type computer should not stop the compilation. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Internal error are reported with a diagnostic object. see #813 Signed-off-by: Stéphane Galland --- .../sarl/lang/typesystem/SARLTypeComputer.java | 17 +++++++++++++---- .../src/io/sarl/lang/validation/IssueCodes.java | 7 +++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/main/coreplugins/io.sarl.lang/src/io/sarl/lang/typesystem/SARLTypeComputer.java b/main/coreplugins/io.sarl.lang/src/io/sarl/lang/typesystem/SARLTypeComputer.java index 29bfff3216..0e4952f988 100644 --- a/main/coreplugins/io.sarl.lang/src/io/sarl/lang/typesystem/SARLTypeComputer.java +++ b/main/coreplugins/io.sarl.lang/src/io/sarl/lang/typesystem/SARLTypeComputer.java @@ -25,7 +25,7 @@ import javax.inject.Inject; -import org.eclipse.emf.ecore.EObject; +import com.google.common.base.Throwables; import org.eclipse.xtend.core.typesystem.XtendTypeComputer; import org.eclipse.xtext.EcoreUtil2; import org.eclipse.xtext.common.types.JvmAnnotationReference; @@ -33,6 +33,8 @@ import org.eclipse.xtext.common.types.JvmIdentifiableElement; import org.eclipse.xtext.common.types.JvmOperation; import org.eclipse.xtext.common.types.util.AnnotationLookup; +import org.eclipse.xtext.diagnostics.Severity; +import org.eclipse.xtext.validation.EObjectDiagnosticImpl; import org.eclipse.xtext.xbase.XExpression; import org.eclipse.xtext.xbase.typesystem.computation.ILinkingCandidate; import org.eclipse.xtext.xbase.typesystem.computation.ITypeComputationState; @@ -42,7 +44,7 @@ import io.sarl.lang.sarl.SarlAssertExpression; import io.sarl.lang.sarl.SarlBreakExpression; import io.sarl.lang.sarl.SarlContinueExpression; -import io.sarl.lang.util.Utils; +import io.sarl.lang.validation.IssueCodes; /** Customized type computer for SARL specific expressions. * @@ -136,8 +138,15 @@ public void computeTypes(XExpression expression, ITypeComputationState state) { try { super.computeTypes(expression, state); } catch (Throwable exception) { - final EObject resourceContent = expression.eResource().getContents().get(0); - throw new Error(Utils.dump(resourceContent), exception); + final Throwable cause = Throwables.getRootCause(exception); + state.addDiagnostic(new EObjectDiagnosticImpl( + Severity.ERROR, + IssueCodes.INTERNAL_ERROR, + cause.getLocalizedMessage(), + expression, + null, + -1, + null)); } } } diff --git a/main/coreplugins/io.sarl.lang/src/io/sarl/lang/validation/IssueCodes.java b/main/coreplugins/io.sarl.lang/src/io/sarl/lang/validation/IssueCodes.java index 8270d6052c..50224a1b4f 100644 --- a/main/coreplugins/io.sarl.lang/src/io/sarl/lang/validation/IssueCodes.java +++ b/main/coreplugins/io.sarl.lang/src/io/sarl/lang/validation/IssueCodes.java @@ -211,6 +211,13 @@ public final class IssueCodes { public static final String POTENTIAL_FIELD_SYNCHRONIZATION_PROBLEM = ISSUE_CODE_PREFIX + "potential_field_synchronization_problem"; //$NON-NLS-1$ + /** + * Internal error. + * @since 0.8 + */ + public static final String INTERNAL_ERROR = + ISSUE_CODE_PREFIX + "internal_error"; //$NON-NLS-1$ + private IssueCodes() { // }