@Override protected void internalToConvertedExpression(XExpression obj, ITreeAppendable appendable) { if (obj instanceof XStringLiteral) { _toJavaExpression((XStringLiteral) obj, appendable); } else if (obj instanceof XNumberLiteral) { _toJavaExpression((XNumberLiteral) obj, appendable); } else if (obj instanceof XNullLiteral) { _toJavaExpression((XNullLiteral) obj, appendable); } else if (obj instanceof XBooleanLiteral) { _toJavaExpression((XBooleanLiteral) obj, appendable); } else if (obj instanceof XTypeLiteral) { _toJavaExpression((XTypeLiteral) obj, appendable); } else { super.internalToConvertedExpression(obj, appendable); } }
@Override protected void doInternalToJavaStatement(XExpression obj, ITreeAppendable appendable, boolean isReferenced) { if (obj instanceof XStringLiteral) { _toJavaStatement((XStringLiteral) obj, appendable, isReferenced); } else if (obj instanceof XNumberLiteral) { _toJavaStatement((XNumberLiteral) obj, appendable, isReferenced); } else if (obj instanceof XNullLiteral) { _toJavaStatement((XNullLiteral) obj, appendable, isReferenced); } else if (obj instanceof XBooleanLiteral) { _toJavaStatement((XBooleanLiteral) obj, appendable, isReferenced); } else if (obj instanceof XTypeLiteral) { _toJavaStatement((XTypeLiteral) obj, appendable, isReferenced); } else { super.doInternalToJavaStatement(obj, appendable, isReferenced); } }
public boolean isConstant(final XExpression expression) { if (expression instanceof XAbstractFeatureCall) { return _isConstant((XAbstractFeatureCall)expression); } else if (expression instanceof XBooleanLiteral) { return _isConstant((XBooleanLiteral)expression); } else if (expression instanceof XCastedExpression) { return _isConstant((XCastedExpression)expression); } else if (expression instanceof XNumberLiteral) { return _isConstant((XNumberLiteral)expression); } else if (expression instanceof XStringLiteral) { return _isConstant((XStringLiteral)expression); } else if (expression instanceof XTypeLiteral) { return _isConstant((XTypeLiteral)expression); } else if (expression != null) { return _isConstant(expression); } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(expression).toString()); } }
public Object internalEvaluate(final XExpression it, final Context ctx) { if (it instanceof XBinaryOperation) { return _internalEvaluate((XBinaryOperation)it, ctx); } else if (it instanceof XUnaryOperation) { return _internalEvaluate((XUnaryOperation)it, ctx); } else if (it instanceof XBooleanLiteral) { return _internalEvaluate((XBooleanLiteral)it, ctx); } else if (it instanceof XCastedExpression) { return _internalEvaluate((XCastedExpression)it, ctx); } else if (it instanceof XStringLiteral) { return _internalEvaluate((XStringLiteral)it, ctx); } else if (it instanceof XTypeLiteral) { return _internalEvaluate((XTypeLiteral)it, ctx); } else if (it instanceof XAnnotation) { return _internalEvaluate((XAnnotation)it, ctx); } else if (it != null) { return _internalEvaluate(it, ctx); } else if (it == null) { return _internalEvaluate((Void)null, ctx); } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(it, ctx).toString()); } }
/** * @return whether the expression itself (not its children) possibly causes a side-effect */ public boolean hasSideEffects(XExpression expr) { if (expr instanceof XClosure || expr instanceof XStringLiteral || expr instanceof XTypeLiteral || expr instanceof XBooleanLiteral || expr instanceof XNumberLiteral || expr instanceof XNullLiteral || expr instanceof XAnnotation ) return false; if(expr instanceof XCollectionLiteral) { for(XExpression element: ((XCollectionLiteral)expr).getElements()) { if(hasSideEffects(element)) return true; } return false; } if (expr instanceof XAbstractFeatureCall) { XAbstractFeatureCall featureCall = (XAbstractFeatureCall) expr; return hasSideEffects(featureCall, true); } if (expr instanceof XConstructorCall) { XConstructorCall constrCall = (XConstructorCall) expr; return findPureAnnotation(constrCall.getConstructor()) == null; } return true; }
@Override protected boolean isVariableDeclarationRequired(XExpression expr, ITreeAppendable b, boolean recursive) { if (expr instanceof XBooleanLiteral || expr instanceof XStringLiteral || expr instanceof XNumberLiteral || expr instanceof XTypeLiteral || expr instanceof XClosure || expr instanceof XNullLiteral) return false; return super.isVariableDeclarationRequired(expr,b, recursive); }
public EvaluationResult internalEvaluate(final XExpression it, final EvaluationContext context) { if (it instanceof XBinaryOperation) { return _internalEvaluate((XBinaryOperation)it, context); } else if (it instanceof XUnaryOperation) { return _internalEvaluate((XUnaryOperation)it, context); } else if (it instanceof XAbstractFeatureCall) { return _internalEvaluate((XAbstractFeatureCall)it, context); } else if (it instanceof XBooleanLiteral) { return _internalEvaluate((XBooleanLiteral)it, context); } else if (it instanceof XCastedExpression) { return _internalEvaluate((XCastedExpression)it, context); } else if (it instanceof XNullLiteral) { return _internalEvaluate((XNullLiteral)it, context); } else if (it instanceof XNumberLiteral) { return _internalEvaluate((XNumberLiteral)it, context); } else if (it instanceof XStringLiteral) { return _internalEvaluate((XStringLiteral)it, context); } else if (it instanceof XTypeLiteral) { return _internalEvaluate((XTypeLiteral)it, context); } else if (it != null) { return _internalEvaluate(it, context); } else if (it == null) { return _internalEvaluate((Void)null, context); } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(it, context).toString()); } }
public Object internalEvaluate(final XExpression it, final Context ctx) { if (it instanceof XBinaryOperation) { return _internalEvaluate((XBinaryOperation)it, ctx); } else if (it instanceof XUnaryOperation) { return _internalEvaluate((XUnaryOperation)it, ctx); } else if (it instanceof XAbstractFeatureCall) { return _internalEvaluate((XAbstractFeatureCall)it, ctx); } else if (it instanceof XBooleanLiteral) { return _internalEvaluate((XBooleanLiteral)it, ctx); } else if (it instanceof XCastedExpression) { return _internalEvaluate((XCastedExpression)it, ctx); } else if (it instanceof XNumberLiteral) { return _internalEvaluate((XNumberLiteral)it, ctx); } else if (it instanceof XStringLiteral) { return _internalEvaluate((XStringLiteral)it, ctx); } else if (it instanceof XTypeLiteral) { return _internalEvaluate((XTypeLiteral)it, ctx); } else if (it instanceof XAnnotation) { return _internalEvaluate((XAnnotation)it, ctx); } else if (it != null) { return _internalEvaluate(it, ctx); } else if (it == null) { return _internalEvaluate((Void)null, ctx); } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(it, ctx).toString()); } }
@Deprecated protected void sequence_XBooleanLiteral(EObject context, XBooleanLiteral semanticObject) { sequence_XBooleanLiteral(createContext(context, semanticObject), semanticObject); }
@Override public void computeTypes(XExpression expression, ITypeComputationState state) { if (expression instanceof XAssignment) { _computeTypes((XAssignment)expression, state); } else if (expression instanceof XAbstractFeatureCall) { _computeTypes((XAbstractFeatureCall)expression, state); } else if (expression instanceof XDoWhileExpression) { _computeTypes((XDoWhileExpression)expression, state); } else if (expression instanceof XWhileExpression) { _computeTypes((XWhileExpression)expression, state); } else if (expression instanceof XBlockExpression) { _computeTypes((XBlockExpression)expression, state); } else if (expression instanceof XBooleanLiteral) { _computeTypes((XBooleanLiteral)expression, state); } else if (expression instanceof XCastedExpression) { _computeTypes((XCastedExpression)expression, state); } else if (expression instanceof XClosure) { _computeTypes((XClosure)expression, state); } else if (expression instanceof XConstructorCall) { _computeTypes((XConstructorCall)expression, state); } else if (expression instanceof XForLoopExpression) { _computeTypes((XForLoopExpression)expression, state); } else if (expression instanceof XBasicForLoopExpression) { _computeTypes((XBasicForLoopExpression)expression, state); } else if (expression instanceof XIfExpression) { _computeTypes((XIfExpression)expression, state); } else if (expression instanceof XInstanceOfExpression) { _computeTypes((XInstanceOfExpression)expression, state); } else if (expression instanceof XNumberLiteral) { _computeTypes((XNumberLiteral)expression, state); } else if (expression instanceof XNullLiteral) { _computeTypes((XNullLiteral)expression, state); } else if (expression instanceof XReturnExpression) { _computeTypes((XReturnExpression)expression, state); } else if (expression instanceof XStringLiteral) { _computeTypes((XStringLiteral)expression, state); } else if (expression instanceof XSwitchExpression) { _computeTypes((XSwitchExpression)expression, state); } else if (expression instanceof XThrowExpression) { _computeTypes((XThrowExpression)expression, state); } else if (expression instanceof XTryCatchFinallyExpression) { _computeTypes((XTryCatchFinallyExpression)expression, state); } else if (expression instanceof XTypeLiteral) { _computeTypes((XTypeLiteral)expression, state); } else if (expression instanceof XVariableDeclaration) { _computeTypes((XVariableDeclaration)expression, state); } else if (expression instanceof XListLiteral) { _computeTypes((XListLiteral)expression, state); } else if (expression instanceof XSetLiteral) { _computeTypes((XSetLiteral)expression, state); } else if (expression instanceof XSynchronizedExpression) { _computeTypes((XSynchronizedExpression)expression, state); } else { throw new UnsupportedOperationException("Missing type computation for expression type: " + expression.eClass().getName() + " / " + state); } }
/** * @param object used for dispatching */ protected void _computeTypes(XBooleanLiteral object, ITypeComputationState state) { LightweightTypeReference bool = getRawTypeForName(Boolean.TYPE, state); state.acceptActualType(bool); }
public void _toJavaExpression(XBooleanLiteral expr, ITreeAppendable b) { b.append(Boolean.toString(expr.isIsTrue())); }
public void _toJavaStatement(XBooleanLiteral expr, ITreeAppendable b, boolean isReferenced) { generateComment(expr, b, isReferenced); }
/** * don't call this directly. Always call evaluate() internalEvaluate() */ protected Object doEvaluate(XExpression expression, IEvaluationContext context, CancelIndicator indicator) { if (expression instanceof XAssignment) { return _doEvaluate((XAssignment)expression, context, indicator); } else if (expression instanceof XDoWhileExpression) { return _doEvaluate((XDoWhileExpression)expression, context, indicator); } else if (expression instanceof XMemberFeatureCall) { return _doEvaluate((XMemberFeatureCall)expression, context, indicator); } else if (expression instanceof XWhileExpression) { return _doEvaluate((XWhileExpression)expression, context, indicator); } else if (expression instanceof XFeatureCall) { return _doEvaluate((XFeatureCall)expression, context, indicator); } else if (expression instanceof XAbstractFeatureCall) { return _doEvaluate((XAbstractFeatureCall)expression, context, indicator); } else if (expression instanceof XBlockExpression) { return _doEvaluate((XBlockExpression)expression, context, indicator); } else if (expression instanceof XSynchronizedExpression) { return _doEvaluate((XSynchronizedExpression)expression, context, indicator); } else if (expression instanceof XBooleanLiteral) { return _doEvaluate((XBooleanLiteral)expression, context, indicator); } else if (expression instanceof XCastedExpression) { return _doEvaluate((XCastedExpression)expression, context, indicator); } else if (expression instanceof XClosure) { return _doEvaluate((XClosure)expression, context, indicator); } else if (expression instanceof XConstructorCall) { return _doEvaluate((XConstructorCall)expression, context, indicator); } else if (expression instanceof XForLoopExpression) { return _doEvaluate((XForLoopExpression)expression, context, indicator); } else if (expression instanceof XBasicForLoopExpression) { return _doEvaluate((XBasicForLoopExpression)expression, context, indicator); } else if (expression instanceof XIfExpression) { return _doEvaluate((XIfExpression)expression, context, indicator); } else if (expression instanceof XInstanceOfExpression) { return _doEvaluate((XInstanceOfExpression)expression, context, indicator); } else if (expression instanceof XNullLiteral) { return _doEvaluate((XNullLiteral)expression, context, indicator); } else if (expression instanceof XNumberLiteral) { return _doEvaluate((XNumberLiteral)expression, context, indicator); } else if (expression instanceof XReturnExpression) { return _doEvaluate((XReturnExpression)expression, context, indicator); } else if (expression instanceof XStringLiteral) { return _doEvaluate((XStringLiteral)expression, context, indicator); } else if (expression instanceof XSwitchExpression) { return _doEvaluate((XSwitchExpression)expression, context, indicator); } else if (expression instanceof XThrowExpression) { return _doEvaluate((XThrowExpression)expression, context, indicator); } else if (expression instanceof XTryCatchFinallyExpression) { return _doEvaluate((XTryCatchFinallyExpression)expression, context, indicator); } else if (expression instanceof XTypeLiteral) { return _doEvaluate((XTypeLiteral)expression, context, indicator); } else if (expression instanceof XVariableDeclaration) { return _doEvaluate((XVariableDeclaration)expression, context, indicator); } else if (expression instanceof XListLiteral) { return _doEvaluate((XListLiteral)expression, context, indicator); } else if (expression instanceof XSetLiteral) { return _doEvaluate((XSetLiteral)expression, context, indicator); } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(expression, context, indicator).toString()); } }
protected boolean _isConstant(final XBooleanLiteral expression) { return true; }
protected void _findImplicitReturns(final XBooleanLiteral expression, final ImplicitReturnFinder.Acceptor acceptor) { acceptor.accept(expression); }
public void findImplicitReturns(final XExpression expression, final ImplicitReturnFinder.Acceptor acceptor) { if (expression instanceof XAbstractFeatureCall) { _findImplicitReturns((XAbstractFeatureCall)expression, acceptor); return; } else if (expression instanceof XBlockExpression) { _findImplicitReturns((XBlockExpression)expression, acceptor); return; } else if (expression instanceof XBooleanLiteral) { _findImplicitReturns((XBooleanLiteral)expression, acceptor); return; } else if (expression instanceof XCastedExpression) { _findImplicitReturns((XCastedExpression)expression, acceptor); return; } else if (expression instanceof XClosure) { _findImplicitReturns((XClosure)expression, acceptor); return; } else if (expression instanceof XCollectionLiteral) { _findImplicitReturns((XCollectionLiteral)expression, acceptor); return; } else if (expression instanceof XConstructorCall) { _findImplicitReturns((XConstructorCall)expression, acceptor); return; } else if (expression instanceof XIfExpression) { _findImplicitReturns((XIfExpression)expression, acceptor); return; } else if (expression instanceof XInstanceOfExpression) { _findImplicitReturns((XInstanceOfExpression)expression, acceptor); return; } else if (expression instanceof XNullLiteral) { _findImplicitReturns((XNullLiteral)expression, acceptor); return; } else if (expression instanceof XNumberLiteral) { _findImplicitReturns((XNumberLiteral)expression, acceptor); return; } else if (expression instanceof XStringLiteral) { _findImplicitReturns((XStringLiteral)expression, acceptor); return; } else if (expression instanceof XSwitchExpression) { _findImplicitReturns((XSwitchExpression)expression, acceptor); return; } else if (expression instanceof XSynchronizedExpression) { _findImplicitReturns((XSynchronizedExpression)expression, acceptor); return; } else if (expression instanceof XTryCatchFinallyExpression) { _findImplicitReturns((XTryCatchFinallyExpression)expression, acceptor); return; } else if (expression instanceof XTypeLiteral) { _findImplicitReturns((XTypeLiteral)expression, acceptor); return; } else if (expression != null) { _findImplicitReturns(expression, acceptor); return; } else if (expression == null) { _findImplicitReturns((Void)null, acceptor); return; } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(expression, acceptor).toString()); } }
protected EvaluationResult _internalEvaluate(final XBooleanLiteral it, final EvaluationContext context) { boolean _isIsTrue = it.isIsTrue(); return new EvaluationResult(Boolean.valueOf(_isIsTrue), true); }
protected Object _internalEvaluate(final XBooleanLiteral it, final Context ctx) { return Boolean.valueOf(it.isIsTrue()); }
@Test public void testBooleanLiteral_1() throws Exception { XBooleanLiteral literal = (XBooleanLiteral) expression("true"); assertTrue(literal.isIsTrue()); }
@Test public void testBooleanLiteral_2() throws Exception { XBooleanLiteral literal = (XBooleanLiteral) expression("false"); assertFalse(literal.isIsTrue()); }
@Test public void testIf_0() throws Exception { XIfExpression ie = (XIfExpression) expression("if (true) false"); assertTrue(((XBooleanLiteral) ie.getIf()).isIsTrue()); assertFalse(((XBooleanLiteral) ie.getThen()).isIsTrue()); assertNull(ie.getElse()); }
@Test public void testIf_1() throws Exception { XIfExpression ie = (XIfExpression) expression("if (true) false else bar"); assertTrue(((XBooleanLiteral) ie.getIf()).isIsTrue()); assertFalse(((XBooleanLiteral) ie.getThen()).isIsTrue()); assertTrue(ie.getElse() instanceof XFeatureCall); }
@Test public void testWhileExpression() throws Exception { XWhileExpression expression = (XWhileExpression) expression("while (true) 'foo'"); assertTrue(expression.getPredicate() instanceof XBooleanLiteral); assertTrue(expression.getBody() instanceof XStringLiteral); }
@Test public void testDoWhileExpression() throws Exception { XDoWhileExpression expression = (XDoWhileExpression) expression("do foo while (true)"); assertTrue(expression.getPredicate() instanceof XBooleanLiteral); assertFeatureCall("foo",expression.getBody()); }
protected void doTestInstanceOf(XInstanceOfExpression expression) { assertEquals("java.lang.Boolean",expression.getType().getIdentifier()); assertTrue(expression.getExpression() instanceof XBooleanLiteral); }
/** * Contexts: * XExpression returns XBooleanLiteral * XAssignment returns XBooleanLiteral * XAssignment.XBinaryOperation_1_1_0_0_0 returns XBooleanLiteral * XOrExpression returns XBooleanLiteral * XOrExpression.XBinaryOperation_1_0_0_0 returns XBooleanLiteral * XAndExpression returns XBooleanLiteral * XAndExpression.XBinaryOperation_1_0_0_0 returns XBooleanLiteral * XEqualityExpression returns XBooleanLiteral * XEqualityExpression.XBinaryOperation_1_0_0_0 returns XBooleanLiteral * XRelationalExpression returns XBooleanLiteral * XRelationalExpression.XInstanceOfExpression_1_0_0_0_0 returns XBooleanLiteral * XRelationalExpression.XBinaryOperation_1_1_0_0_0 returns XBooleanLiteral * XOtherOperatorExpression returns XBooleanLiteral * XOtherOperatorExpression.XBinaryOperation_1_0_0_0 returns XBooleanLiteral * XAdditiveExpression returns XBooleanLiteral * XAdditiveExpression.XBinaryOperation_1_0_0_0 returns XBooleanLiteral * XMultiplicativeExpression returns XBooleanLiteral * XMultiplicativeExpression.XBinaryOperation_1_0_0_0 returns XBooleanLiteral * XUnaryOperation returns XBooleanLiteral * XCastedExpression returns XBooleanLiteral * XCastedExpression.XCastedExpression_1_0_0_0 returns XBooleanLiteral * XPostfixOperation returns XBooleanLiteral * XPostfixOperation.XPostfixOperation_1_0_0 returns XBooleanLiteral * XMemberFeatureCall returns XBooleanLiteral * XMemberFeatureCall.XAssignment_1_0_0_0_0 returns XBooleanLiteral * XMemberFeatureCall.XMemberFeatureCall_1_1_0_0_0 returns XBooleanLiteral * XPrimaryExpression returns XBooleanLiteral * XLiteral returns XBooleanLiteral * XParenthesizedExpression returns XBooleanLiteral * XExpressionOrVarDeclaration returns XBooleanLiteral * XBooleanLiteral returns XBooleanLiteral * * Constraint: * isTrue?='true'? */ protected void sequence_XBooleanLiteral(ISerializationContext context, XBooleanLiteral semanticObject) { genericSequencer.createSequence(context, semanticObject); }
/** * @param context unused in this context but required for dispatching * @param indicator unused in this context but required for dispatching */ protected Object _doEvaluate(XBooleanLiteral literal, IEvaluationContext context, CancelIndicator indicator) { return literal.isIsTrue(); }
/** * Constraint: * (isTrue?='true'?) */ protected void sequence_XBooleanLiteral(EObject context, XBooleanLiteral semanticObject) { genericSequencer.createSequence(context, semanticObject); }