Skip to content

Commit

Permalink
add timeout using the diagnostic helper
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzoBettini committed May 25, 2020
1 parent 93d67f4 commit 71922cd
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions edelta.parent/edelta/src/edelta/interpreter/EdeltaInterpreter.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.util.CancelIndicator;
import org.eclipse.xtext.util.IResourceScopeCache;
import org.eclipse.xtext.validation.EObjectDiagnosticImpl;
import org.eclipse.xtext.xbase.XBlockExpression;
import org.eclipse.xtext.xbase.XExpression;
import org.eclipse.xtext.xbase.interpreter.IEvaluationContext;
Expand Down Expand Up @@ -98,12 +97,6 @@ public class EdeltaInterpreter extends XbaseInterpreter {

private EdeltaInterpreterResourceListener listener;

/**
* The current {@link XExpression} being interpreted that is worthwhile to keep
* track of.
*/
private XExpression currentExpression;

class EdeltaInterpreterCancelIndicator implements CancelIndicator {
long stopAt = System.currentTimeMillis() +
interpreterTimeout;
Expand Down Expand Up @@ -173,7 +166,7 @@ private void evaluateModifyEcoreOperation(final EdeltaModifyEcoreOperation op,
final IEvaluationResult result = evaluate(op.getBody(), context,
new EdeltaInterpreterCancelIndicator());
if (result == null) {
addTimeoutWarning(op.eResource());
addTimeoutWarning();
} else {
handleResultException(result.getException());
}
Expand All @@ -199,16 +192,10 @@ private void handleResultException(Throwable resultException) {
}
}

private void addTimeoutWarning(final Resource resource) {
resource.getWarnings().add(
new EObjectDiagnosticImpl(Severity.WARNING,
EdeltaValidator.INTERPRETER_TIMEOUT,
"Timeout while interpreting (" +
Integer.valueOf(interpreterTimeout) + "ms).",
currentExpression,
null,
-1,
new String[] {}));
private void addTimeoutWarning() {
diagnosticHelper.addWarning(null, EdeltaValidator.INTERPRETER_TIMEOUT,
"Timeout while interpreting (" +
Integer.valueOf(interpreterTimeout) + "ms).");
}

@Override
Expand All @@ -227,7 +214,6 @@ private void updateListenerCurrentExpression(XExpression expression) {
if (listener != null && shouldTrackExpression(expression)) {
listener.setCurrentExpression(expression);
diagnosticHelper.setCurrentExpression(expression);
this.currentExpression = expression;
}
}

Expand Down

0 comments on commit 71922cd

Please sign in to comment.