use of org.eclipse.xtext.xbase.interpreter.Context in project xtext-xtend by eclipse.
the class ConstantExpressionsInterpreter method evaluate.
public Object evaluate(final XExpression expression, final JvmTypeReference expectedType) {
final ClassLoader classLoader = this.classLoaderProvider.getClassLoader(expression);
final Map<String, JvmIdentifiableElement> visibleFeatures = this.findVisibleFeatures(expression);
JvmTypeReference _xifexpression = null;
if ((expectedType instanceof XComputedTypeReference)) {
_xifexpression = null;
} else {
_xifexpression = expectedType;
}
ClassFinder _classFinder = new ClassFinder(classLoader);
LinkedHashSet<XExpression> _newLinkedHashSet = CollectionLiterals.<XExpression>newLinkedHashSet();
Context _context = new Context(_xifexpression, _classFinder, visibleFeatures, _newLinkedHashSet);
final Object result = this.evaluate(expression, _context);
return result;
}
use of org.eclipse.xtext.xbase.interpreter.Context 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);
}
}
}
Aggregations