Search in sources :

Example 1 with FunctionCall

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

the class ArithmeticsSemanticSequencer method sequence.

@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
    EPackage epackage = semanticObject.eClass().getEPackage();
    ParserRule rule = context.getParserRule();
    Action action = context.getAssignedAction();
    Set<Parameter> parameters = context.getEnabledBooleanParameters();
    if (epackage == ArithmeticsPackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case ArithmeticsPackage.DECLARED_PARAMETER:
                sequence_DeclaredParameter(context, (DeclaredParameter) semanticObject);
                return;
            case ArithmeticsPackage.DEFINITION:
                sequence_Definition(context, (Definition) semanticObject);
                return;
            case ArithmeticsPackage.DIV:
                sequence_Multiplication(context, (Div) semanticObject);
                return;
            case ArithmeticsPackage.EVALUATION:
                sequence_Evaluation(context, (Evaluation) semanticObject);
                return;
            case ArithmeticsPackage.FUNCTION_CALL:
                sequence_PrimaryExpression(context, (FunctionCall) semanticObject);
                return;
            case ArithmeticsPackage.IMPORT:
                sequence_Import(context, (Import) semanticObject);
                return;
            case ArithmeticsPackage.MINUS:
                sequence_Addition(context, (Minus) semanticObject);
                return;
            case ArithmeticsPackage.MODULE:
                sequence_Module(context, (org.eclipse.xtext.example.arithmetics.arithmetics.Module) semanticObject);
                return;
            case ArithmeticsPackage.MULTI:
                sequence_Multiplication(context, (Multi) semanticObject);
                return;
            case ArithmeticsPackage.NUMBER_LITERAL:
                sequence_PrimaryExpression(context, (NumberLiteral) semanticObject);
                return;
            case ArithmeticsPackage.PLUS:
                sequence_Addition(context, (Plus) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Evaluation(org.eclipse.xtext.example.arithmetics.arithmetics.Evaluation) Action(org.eclipse.xtext.Action) Import(org.eclipse.xtext.example.arithmetics.arithmetics.Import) Definition(org.eclipse.xtext.example.arithmetics.arithmetics.Definition) Multi(org.eclipse.xtext.example.arithmetics.arithmetics.Multi) EPackage(org.eclipse.emf.ecore.EPackage) Div(org.eclipse.xtext.example.arithmetics.arithmetics.Div) DeclaredParameter(org.eclipse.xtext.example.arithmetics.arithmetics.DeclaredParameter) Parameter(org.eclipse.xtext.Parameter) FunctionCall(org.eclipse.xtext.example.arithmetics.arithmetics.FunctionCall) DeclaredParameter(org.eclipse.xtext.example.arithmetics.arithmetics.DeclaredParameter) Plus(org.eclipse.xtext.example.arithmetics.arithmetics.Plus) Minus(org.eclipse.xtext.example.arithmetics.arithmetics.Minus) NumberLiteral(org.eclipse.xtext.example.arithmetics.arithmetics.NumberLiteral)

Example 2 with FunctionCall

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

the class ArithmeticsValidator method checkNormalizable.

@Check
public void checkNormalizable(Expression expr) {
    if (expr instanceof NumberLiteral || expr instanceof FunctionCall) {
        return;
    }
    Evaluation eval = EcoreUtil2.getContainerOfType(expr, Evaluation.class);
    if (eval != null) {
        return;
    }
    TreeIterator<EObject> contents = expr.eAllContents();
    while (contents.hasNext()) {
        EObject next = contents.next();
        if ((next instanceof FunctionCall)) {
            return;
        }
    }
    BigDecimal decimal = calculator.evaluate(expr);
    if (decimal.toString().length() <= 8) {
        warning("Expression could be normalized to constant \'" + decimal + "\'", null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, ArithmeticsValidator.NORMALIZABLE, decimal.toString());
    }
}
Also used : Evaluation(org.eclipse.xtext.example.arithmetics.arithmetics.Evaluation) EObject(org.eclipse.emf.ecore.EObject) FunctionCall(org.eclipse.xtext.example.arithmetics.arithmetics.FunctionCall) NumberLiteral(org.eclipse.xtext.example.arithmetics.arithmetics.NumberLiteral) BigDecimal(java.math.BigDecimal) Check(org.eclipse.xtext.validation.Check)

Aggregations

Evaluation (org.eclipse.xtext.example.arithmetics.arithmetics.Evaluation)2 FunctionCall (org.eclipse.xtext.example.arithmetics.arithmetics.FunctionCall)2 NumberLiteral (org.eclipse.xtext.example.arithmetics.arithmetics.NumberLiteral)2 BigDecimal (java.math.BigDecimal)1 EObject (org.eclipse.emf.ecore.EObject)1 EPackage (org.eclipse.emf.ecore.EPackage)1 Action (org.eclipse.xtext.Action)1 Parameter (org.eclipse.xtext.Parameter)1 ParserRule (org.eclipse.xtext.ParserRule)1 DeclaredParameter (org.eclipse.xtext.example.arithmetics.arithmetics.DeclaredParameter)1 Definition (org.eclipse.xtext.example.arithmetics.arithmetics.Definition)1 Div (org.eclipse.xtext.example.arithmetics.arithmetics.Div)1 Import (org.eclipse.xtext.example.arithmetics.arithmetics.Import)1 Minus (org.eclipse.xtext.example.arithmetics.arithmetics.Minus)1 Multi (org.eclipse.xtext.example.arithmetics.arithmetics.Multi)1 Plus (org.eclipse.xtext.example.arithmetics.arithmetics.Plus)1 Check (org.eclipse.xtext.validation.Check)1