Search in sources :

Example 1 with Module

use of org.eclipse.xtext.example.arithmetics.arithmetics.Module in project xtext-eclipse by eclipse.

the class ArithmeticsScopeProvider method getScope.

@Override
public IScope getScope(EObject context, EReference reference) {
    if (reference == ArithmeticsPackage.Literals.IMPORT__MODULE) {
        return super.getGlobalScope(context.eResource(), reference);
    }
    Module module = EcoreUtil2.getContainerOfType(context, Module.class);
    IScope result = IScope.NULLSCOPE;
    for (Import i : module.getImports()) {
        if (!i.getModule().eIsProxy()) {
            result = getModuleScope(context, reference, i.getModule(), result);
        }
    }
    result = getModuleScope(context, reference, module, result);
    return getDefinitionScope(context, reference, result);
}
Also used : Import(org.eclipse.xtext.example.arithmetics.arithmetics.Import) IScope(org.eclipse.xtext.scoping.IScope) Module(org.eclipse.xtext.example.arithmetics.arithmetics.Module)

Example 2 with Module

use of org.eclipse.xtext.example.arithmetics.arithmetics.Module in project xtext-eclipse by eclipse.

the class CalculatorTest method evaluatesTo.

private void evaluatesTo(CharSequence content, double expected) throws Exception {
    Module module = parseHelper.parse("module test " + content);
    Statement firstStatement = module.getStatements().get(0);
    Iterable<Expression> expressions = Iterables.filter(firstStatement.eContents(), Expression.class);
    Expression expression = Iterables.getFirst(expressions, null);
    BigDecimal result = calculator.evaluate(expression);
    Assert.assertEquals(expected, result.doubleValue(), 0.0001);
}
Also used : Expression(org.eclipse.xtext.example.arithmetics.arithmetics.Expression) Statement(org.eclipse.xtext.example.arithmetics.arithmetics.Statement) Module(org.eclipse.xtext.example.arithmetics.arithmetics.Module) BigDecimal(java.math.BigDecimal)

Aggregations

Module (org.eclipse.xtext.example.arithmetics.arithmetics.Module)2 BigDecimal (java.math.BigDecimal)1 Expression (org.eclipse.xtext.example.arithmetics.arithmetics.Expression)1 Import (org.eclipse.xtext.example.arithmetics.arithmetics.Import)1 Statement (org.eclipse.xtext.example.arithmetics.arithmetics.Statement)1 IScope (org.eclipse.xtext.scoping.IScope)1