Search in sources :

Example 1 with ClassFinder

use of org.eclipse.xtext.common.types.access.impl.ClassFinder 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;
}
Also used : Context(org.eclipse.xtext.xbase.interpreter.Context) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) XComputedTypeReference(org.eclipse.xtext.xtype.XComputedTypeReference) ClassFinder(org.eclipse.xtext.common.types.access.impl.ClassFinder) XExpression(org.eclipse.xtext.xbase.XExpression) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject)

Example 2 with ClassFinder

use of org.eclipse.xtext.common.types.access.impl.ClassFinder 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)2 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)2 ClassFinder (org.eclipse.xtext.common.types.access.impl.ClassFinder)2 XExpression (org.eclipse.xtext.xbase.XExpression)2 Context (org.eclipse.xtext.xbase.interpreter.Context)2 EObject (org.eclipse.emf.ecore.EObject)1 InternalEObject (org.eclipse.emf.ecore.InternalEObject)1 TypeResource (org.eclipse.xtext.common.types.access.TypeResource)1 ConstantExpressionEvaluationException (org.eclipse.xtext.xbase.interpreter.ConstantExpressionEvaluationException)1 StackedConstantExpressionEvaluationException (org.eclipse.xtext.xbase.interpreter.StackedConstantExpressionEvaluationException)1 XComputedTypeReference (org.eclipse.xtext.xtype.XComputedTypeReference)1