Search in sources :

Example 1 with StackedConstantExpressionEvaluationException

use of org.eclipse.xtext.xbase.interpreter.StackedConstantExpressionEvaluationException in project xtext-xtend by eclipse.

the class ConstantExpressionsInterpreter method evaluateField.

protected Object evaluateField(final XAbstractFeatureCall call, final JvmField field, final Context context) {
    if ((field.isSetConstant() || (field.eResource() instanceof TypeResource))) {
        boolean _isConstant = field.isConstant();
        if (_isConstant) {
            return field.getConstantValue();
        } else {
            String _simpleName = field.getDeclaringType().getSimpleName();
            String _plus = ("Field " + _simpleName);
            String _plus_1 = (_plus + ".");
            String _simpleName_1 = field.getSimpleName();
            String _plus_2 = (_plus_1 + _simpleName_1);
            String _plus_3 = (_plus_2 + " is not a constant");
            throw new ConstantExpressionEvaluationException(_plus_3);
        }
    }
    final XExpression expression = this.containerProvider.getAssociatedExpression(field);
    boolean _contains = context.getAlreadyEvaluating().contains(expression);
    if (_contains) {
        throw new ConstantExpressionEvaluationException("Endless recursive evaluation detected.");
    }
    try {
        final Map<String, JvmIdentifiableElement> visibleFeatures = this.findVisibleFeatures(expression);
        JvmTypeReference _type = field.getType();
        ClassFinder _classFinder = context.getClassFinder();
        Set<XExpression> _alreadyEvaluating = context.getAlreadyEvaluating();
        final Context ctx = new Context(_type, _classFinder, visibleFeatures, _alreadyEvaluating);
        return this.evaluate(expression, ctx);
    } catch (final Throwable _t) {
        if (_t instanceof ConstantExpressionEvaluationException) {
            final ConstantExpressionEvaluationException e = (ConstantExpressionEvaluationException) _t;
            throw new StackedConstantExpressionEvaluationException(call, field, e);
        } else {
            throw Exceptions.sneakyThrow(_t);
        }
    }
}
Also used : Context(org.eclipse.xtext.xbase.interpreter.Context) TypeResource(org.eclipse.xtext.common.types.access.TypeResource) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) ConstantExpressionEvaluationException(org.eclipse.xtext.xbase.interpreter.ConstantExpressionEvaluationException) StackedConstantExpressionEvaluationException(org.eclipse.xtext.xbase.interpreter.StackedConstantExpressionEvaluationException) StackedConstantExpressionEvaluationException(org.eclipse.xtext.xbase.interpreter.StackedConstantExpressionEvaluationException) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) ClassFinder(org.eclipse.xtext.common.types.access.impl.ClassFinder) XExpression(org.eclipse.xtext.xbase.XExpression)

Aggregations

JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)1 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)1 TypeResource (org.eclipse.xtext.common.types.access.TypeResource)1 ClassFinder (org.eclipse.xtext.common.types.access.impl.ClassFinder)1 XExpression (org.eclipse.xtext.xbase.XExpression)1 ConstantExpressionEvaluationException (org.eclipse.xtext.xbase.interpreter.ConstantExpressionEvaluationException)1 Context (org.eclipse.xtext.xbase.interpreter.Context)1 StackedConstantExpressionEvaluationException (org.eclipse.xtext.xbase.interpreter.StackedConstantExpressionEvaluationException)1