org.eclipse.xtext.xbase.interpreter.impl.DefaultEvaluationContext Java Examples

The following examples show how to use org.eclipse.xtext.xbase.interpreter.impl.DefaultEvaluationContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InterpreterTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testInfiniteLoopInJava() throws Exception {
	XExpression expression = expression(
			"try " +
			"  new testdata.ClosureClient().infiniteApply(|{null})" +
			"catch(Exception e)" +
			"  'literal' ", true);
	assertNull(interpreter.evaluate(expression, new DefaultEvaluationContext(), new CancelIndicator() {
		private int i = 0;
		@Override
		public boolean isCanceled() {
			if (i == 500)
				return true;
			i++;
			return false;
		}
	}));
}
 
Example #2
Source File: DSLScriptEngine.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
private DefaultEvaluationContext createEvaluationContext(IEvaluationContext specificContext) {
    DefaultEvaluationContext evalContext = new DefaultEvaluationContext(specificContext);
    for (Map.Entry<String, String> entry : implicitVars.entrySet()) {
        Object value = context.getAttribute(entry.getKey());
        if (value != null) {
            evalContext.newValue(QualifiedName.create(entry.getValue()), value);
        }
    }
    return evalContext;
}
 
Example #3
Source File: DefaultXbaseRuntimeModule.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IEvaluationContext> bindIEvaluationContext() {
	return DefaultEvaluationContext.class;
}
 
Example #4
Source File: ReplAutoEdit.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected String computeResultText(final IDocument document, final DocumentCommand command, XtextResource resource)
		throws BadLocationException {
	if (resource.getContents().isEmpty())
		return null;
	if (!(resource.getContents().get(0) instanceof Model))
		return null;
	Model model = (Model) resource.getContents().get(0);
	if (model.getBlock() == null)
		return null;
	EList<XExpression> expressions = model.getBlock().getExpressions();
	if (expressions.isEmpty())
		return null;
	XExpression expression = expressions.get(expressions.size() - 1);
	if (expression == null) {
		return null;
	}
	ICompositeNode node = NodeModelUtils.getNode(expression);
	if (node == null || document.getLineOfOffset(command.offset) + 1 != node.getEndLine())
		return null;
	List<Issue> issues = validator.validate(resource, CheckMode.NORMAL_AND_FAST, CancelIndicator.NullImpl);
	if (issues.stream().anyMatch(i -> i.getSeverity() == Severity.ERROR)) {
		return null;
	}
	XbaseInterpreter xbaseInterpreter = getConfiguredInterpreter(resource);
	IEvaluationResult result = xbaseInterpreter.evaluate(model.getBlock(), new DefaultEvaluationContext(),
			new CancelIndicator() {
				private long stopAt = System.currentTimeMillis() + 2000;

				@Override
				public boolean isCanceled() {
					return System.currentTimeMillis() > stopAt;
				}
			});
	if (result == null)
		return null;

	String value = "" + result.getResult();
	if (result.getException() != null)
		value = "threw " + result.getException().getClass().getSimpleName();

	LightweightTypeReference expressionType = typeResolver.resolveTypes(expression).getActualType(expression);
	if (expressionType != null) {
		String newText = command.text + "// " + value + " ("
				+ expressionType.getSimpleName() + ")" + command.text;
		return newText;
	}
	return command.text + "// " + value;
}
 
Example #5
Source File: RuleEvaluationContext.java    From openhab-core with Eclipse Public License 2.0 4 votes vote down vote up
public RuleEvaluationContext() {
    super(new DefaultEvaluationContext());
}
 
Example #6
Source File: RuleEvaluationContext.java    From smarthome with Eclipse Public License 2.0 4 votes vote down vote up
public RuleEvaluationContext() {
    super(new DefaultEvaluationContext());
}