use of org.eclipse.xtext.xbase.interpreter.IExpressionInterpreter in project smarthome by eclipse.
the class ScriptImpl method execute.
@Override
public Object execute(final IEvaluationContext evaluationContext) throws ScriptExecutionException {
if (xExpression != null) {
Resource resource = xExpression.eResource();
IExpressionInterpreter interpreter = null;
if (resource instanceof XtextResource) {
IResourceServiceProvider provider = ((XtextResource) resource).getResourceServiceProvider();
interpreter = provider.get(IExpressionInterpreter.class);
}
if (interpreter == null) {
throw new ScriptExecutionException("Script interpreter couldn't be obtain");
}
try {
IEvaluationResult result = interpreter.evaluate(xExpression, evaluationContext, CancelIndicator.NullImpl);
if (result == null) {
// i.e. NEVER ;-)
return null;
}
if (result.getException() != null) {
throw new ScriptExecutionException(result.getException().getMessage(), result.getException());
}
return result.getResult();
} catch (Throwable e) {
if (e instanceof ScriptExecutionException) {
throw (ScriptExecutionException) e;
} else {
throw new ScriptExecutionException("An error occurred during the script execution: " + e.getMessage(), e);
}
}
} else {
throw new ScriptExecutionException("Script does not contain any expression");
}
}
Aggregations