Search in sources :

Example 6 with NegativeExpression

use of edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.NegativeExpression in project AGREE by loonwerks.

the class InputConstraintSemanticSequencer 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 == InputConstraintPackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case InputConstraintPackage.BINARY_EXPRESSION:
                sequence_AddSub_MultDiv(context, (BinaryExpression) semanticObject);
                return;
            case InputConstraintPackage.BOOLEAN_LITERAL:
                sequence_BooleanLiteral(context, (BooleanLiteral) semanticObject);
                return;
            case InputConstraintPackage.CONST_REF_EXPRESSION:
                sequence_ConstRef(context, (ConstRefExpression) semanticObject);
                return;
            case InputConstraintPackage.ELEMENT_REF_EXPRESSION:
                sequence_ElementRef(context, (ElementRefExpression) semanticObject);
                return;
            case InputConstraintPackage.INTEGER_LITERAL:
                sequence_IntegerLiteral(context, (IntegerLiteral) semanticObject);
                return;
            case InputConstraintPackage.INTERVAL_EXPRESSION:
                sequence_Interval(context, (IntervalExpression) semanticObject);
                return;
            case InputConstraintPackage.NEGATIVE_EXPRESSION:
                sequence_Negative(context, (NegativeExpression) semanticObject);
                return;
            case InputConstraintPackage.PRE_EXPRESSION:
                sequence_Pre(context, (PreExpression) semanticObject);
                return;
            case InputConstraintPackage.RANDOM_ELEMENT_EXPRESSION:
                sequence_RandomElement(context, (RandomElementExpression) semanticObject);
                return;
            case InputConstraintPackage.RANDOM_INTEGER_EXPRESSION:
                sequence_RandomInteger(context, (RandomIntegerExpression) semanticObject);
                return;
            case InputConstraintPackage.RANDOM_REAL_EXPRESSION:
                sequence_RandomReal(context, (RandomRealExpression) semanticObject);
                return;
            case InputConstraintPackage.REAL_LITERAL:
                sequence_RealLiteral(context, (RealLiteral) semanticObject);
                return;
            case InputConstraintPackage.SET_EXPRESSION:
                sequence_Set(context, (SetExpression) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) ConstRefExpression(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.ConstRefExpression) SetExpression(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.SetExpression) BooleanLiteral(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.BooleanLiteral) RandomIntegerExpression(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.RandomIntegerExpression) PreExpression(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.PreExpression) EPackage(org.eclipse.emf.ecore.EPackage) RealLiteral(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.RealLiteral) BinaryExpression(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.BinaryExpression) RandomElementExpression(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.RandomElementExpression) RandomRealExpression(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.RandomRealExpression) Parameter(org.eclipse.xtext.Parameter) IntervalExpression(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.IntervalExpression) IntegerLiteral(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.IntegerLiteral) ElementRefExpression(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.ElementRefExpression) NegativeExpression(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.NegativeExpression)

Example 7 with NegativeExpression

use of edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.NegativeExpression in project AGREE by loonwerks.

the class ExpressionFactory method createReal.

public static ScalarExpression createReal(final BigInteger value) {
    final boolean isNegative = value.signum() < 0;
    BigDecimal decValue = new BigDecimal(value);
    // Negative values arnen't allowed
    if (isNegative) {
        decValue = decValue.negate();
    }
    // Adjust scale. Decimal values with a scale less than 1 do not serialize properly.
    if (decValue.scale() < 1) {
        decValue = decValue.setScale(1);
    }
    final RealLiteral realLiteral = InputConstraintFactory.eINSTANCE.createRealLiteral();
    realLiteral.setValue(decValue);
    final ScalarExpression scalarExpression;
    if (isNegative) {
        final NegativeExpression negExpr = InputConstraintFactory.eINSTANCE.createNegativeExpression();
        negExpr.setValue(realLiteral);
        scalarExpression = negExpr;
    } else {
        scalarExpression = realLiteral;
    }
    return scalarExpression;
}
Also used : RealLiteral(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.RealLiteral) ScalarExpression(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.ScalarExpression) BigDecimal(java.math.BigDecimal) NegativeExpression(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.NegativeExpression)

Aggregations

NegativeExpression (edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.NegativeExpression)7 BooleanLiteral (edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.BooleanLiteral)4 RealLiteral (edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.RealLiteral)4 BinaryExpression (edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.BinaryExpression)3 ConstRefExpression (edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.ConstRefExpression)3 ElementRefExpression (edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.ElementRefExpression)3 IntegerLiteral (edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.IntegerLiteral)3 IntervalExpression (edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.IntervalExpression)3 PreExpression (edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.PreExpression)3 RandomElementExpression (edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.RandomElementExpression)3 RandomIntegerExpression (edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.RandomIntegerExpression)3 RandomRealExpression (edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.RandomRealExpression)3 ScalarExpression (edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.ScalarExpression)3 SetExpression (edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.SetExpression)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 EClassifier (org.eclipse.emf.ecore.EClassifier)2 EObject (org.eclipse.emf.ecore.EObject)2 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)2 MenuItem (org.eclipse.swt.widgets.MenuItem)2