Examples of IfThenElseStatement


Examples of org.allspice.structured.statement.IfThenElseStatement

public class TestIfThenElse extends MyTestCase {
  public static interface IfTest {
    public int meth(boolean arg0) ;
  }
  public void test1() throws Exception {
    IfTest obj = makeObject(IfTest.class,new IfThenElseStatement(
        ARG0,
        new FIFO<Statement>(new ReturnStatement(new ConstExpr(Integer.valueOf(3),null),null)),
        new FIFO<Statement>(new ReturnStatement(new ConstExpr(Integer.valueOf(2),null),null)),
        null)) ;
    assertEquals(obj.meth(true),3) ;
View Full Code Here

Examples of org.openquark.cal.internal.javamodel.JavaStatement.IfThenElseStatement

        }
        JavaStatement.ThrowStatement throwAssertError =
            new ThrowStatement(createAssertionError);
       
        // if (!conditionExpr) {throw new AssertionError();}
        IfThenElseStatement ifThen =
            new IfThenElseStatement(new OperatorExpression.Unary(JavaOperator.LOGICAL_NEGATE, assertStatement.getConditionExpr()), throwAssertError);
       
        // if (!$assertionsDisabled) {if (!conditionExpr) {throw new AssertionError;}}
        JavaExpression assertionsDisabledField = new JavaExpression.JavaField.Static(context.classTypeName, "$assertionsDisabled", JavaTypeName.BOOLEAN);
        JavaExpression checkAssertionEnabled = new JavaExpression.OperatorExpression.Unary(JavaOperator.LOGICAL_NEGATE, assertionsDisabledField);
        ifThen = new IfThenElseStatement (checkAssertionEnabled, ifThen);
       
        return encodeIfThenElseStatement(ifThen, context);
    }
View Full Code Here

Examples of org.openquark.cal.internal.javamodel.JavaStatement.IfThenElseStatement

       
        if (ifThenElse.getElseStatement() != null) {
            JavaStatement elsePart =
                (JavaStatement)ifThenElse.getElseStatement().accept(this, arg);
           
            return new IfThenElseStatement(condition, thenPart, elsePart);
        }
       
        return new IfThenElseStatement(condition, thenPart);
    }
View Full Code Here

Examples of org.openquark.cal.internal.javamodel.JavaStatement.IfThenElseStatement

                emitLine(sb, indent, "return;");
            } else {
                emitLine(sb, indent, "return " + getSource(returnStatement.getReturnExpression(),indent, 7, context) ";");
            }
        } else if (statement instanceof IfThenElseStatement) {
            IfThenElseStatement iteStatement = (IfThenElseStatement)statement;

            emitLine(sb, indent, "if (" + getSource(iteStatement.getCondition(), indent, 4, context) + ") {");

            sb.append(getSource(iteStatement.getThenStatement(), context, indent + 1));

            // Emit the else clause only if there is one.
            StringBuilder elseClause = getSource(iteStatement.getElseStatement(), context, indent + 1);

            if (elseClause.length() > 0) {
                emitLine(sb, indent, "} else {");
                sb.append(elseClause);
            }
View Full Code Here

Examples of org.openquark.cal.internal.javamodel.JavaStatement.IfThenElseStatement

                        hashCodeField,
                        LiteralWrapper.make(new Integer(0)));
           
            JavaStatement.Block thenBlock = new JavaStatement.Block();
           
            IfThenElseStatement ifThen =
                new IfThenElseStatement (condition, thenBlock);
           
            hashCode.addStatement (ifThen);
           
            // build up the hashcode value.
            JavaExpression.LocalVariable result =
View Full Code Here

Examples of org.openquark.cal.internal.javamodel.JavaStatement.IfThenElseStatement

                new JavaExpression.OperatorExpression.Binary(
                        JavaOperator.EQUALS_OBJECT,
                        thisField,
                        objectArg);
            JavaStatement.IfThenElseStatement ifThen =
                new IfThenElseStatement(
                        condition,
                        new ReturnStatement(LiteralWrapper.TRUE));
           
            equals.addStatement(ifThen);

            // if (object == null) {
            //     return false;
            // }
            condition =
                new JavaExpression.OperatorExpression.Binary(JavaOperator.EQUALS_OBJECT, objectArg, LiteralWrapper.NULL);
            ifThen =
                new IfThenElseStatement (condition, new ReturnStatement(LiteralWrapper.FALSE));
            equals.addStatement(ifThen);
           
            // if (!(object instanceOf ThisType)) {
            //     return false;
            // }
            condition =
                new JavaExpression.InstanceOf(objectArg, typeName);
            condition =
                new OperatorExpression.Unary(JavaOperator.LOGICAL_NEGATE, condition);
            ifThen =
                new IfThenElseStatement (
                        condition,
                        new ReturnStatement(LiteralWrapper.FALSE));
            equals.addStatement(ifThen);
           
            // ThisType castObject = (ThisType)object;
            LocalVariable localVar =
                new LocalVariable ("cast" + argName, typeName);
           
            JavaStatement localVarDecl =
                new JavaStatement.LocalVariableDeclaration (
                        localVar,
                        new JavaExpression.CastExpression(typeName, objectArg));
            equals.addStatement (localVarDecl);
           

            // Check DC name
            // if (!getDCName().equals(castObject.getDCName())) {
            //     return false;
            // }
            JavaExpression thisGetDCName =
                new MethodInvocation.Instance(null, GET_DC_NAME_METHOD_NAME, JavaTypeName.STRING, MethodInvocation.InvocationType.VIRTUAL);
            JavaExpression otherGetDCName =
                new MethodInvocation.Instance(localVar, GET_DC_NAME_METHOD_NAME, JavaTypeName.STRING, MethodInvocation.InvocationType.VIRTUAL);
            JavaExpression compareDCNames =
                new MethodInvocation.Instance(thisGetDCName, "equals", otherGetDCName, JavaTypeName.OBJECT, JavaTypeName.BOOLEAN, MethodInvocation.InvocationType.VIRTUAL);
            compareDCNames = new OperatorExpression.Unary(JavaOperator.LOGICAL_NEGATE, compareDCNames);

            ifThen = new IfThenElseStatement(compareDCNames, new ReturnStatement(LiteralWrapper.FALSE));
            equals.addStatement(ifThen);
           
            if (fieldNames != null && fieldNames.size() > 0) {
                // Now we need to compare equality for the various fields.
                Iterator<FieldName> fields = fieldNames.iterator();
View Full Code Here

Examples of org.openquark.cal.internal.javamodel.JavaStatement.IfThenElseStatement

            Block elseBlock = variableContext.popJavaScope();
            elseBlock.addStatement(elsePart);

            JavaExpression conditionExpression = pair.getJavaExpression();

            JavaStatement ite = new IfThenElseStatement(conditionExpression, thenBlock, elseBlock);

            Block contextBlock = pair.getContextBlock();
            contextBlock.addStatement(ite);

            // We don't need to call generateReturn() at this point.  Any return statements
View Full Code Here

Examples of org.openquark.cal.internal.javamodel.JavaStatement.IfThenElseStatement

            elseBlock = variableContext.popJavaScope();
            elseBlock.addStatement(elsePart);
        }

        JavaStatement ite = new IfThenElseStatement(pair.getJavaExpression(), thenBlock, elseBlock);

        Block contextBlock = pair.getContextBlock();
        contextBlock.addStatement(ite);
        return contextBlock;
    }
View Full Code Here

Examples of org.openquark.cal.internal.javamodel.JavaStatement.IfThenElseStatement

            JavaExpression condition =
                (JavaExpression)ifThenElse.getCondition().accept (this, arg);

            if (newElse != null) {
                return new IfThenElseStatement(condition, newThen, newElse);
            }

            return new IfThenElseStatement(condition, newThen);
        }
View Full Code Here

Examples of org.openquark.cal.internal.javamodel.JavaStatement.IfThenElseStatement

                        Assignment localAssignment = new Assignment(localVariable, field);
                        InstanceOf checkType = new InstanceOf(localAssignment, JavaTypeNames.RTRESULT_FUNCTION);
                        MethodInvocation getValue = new MethodInvocation.Instance(localVariable, "getValue", JavaTypeNames.RTVALUE, MethodInvocation.InvocationType.VIRTUAL);
                        Assignment fieldAssignment = new Assignment(field, getValue);
                        ReturnStatement returnNewVal = new ReturnStatement(fieldAssignment);
                        IfThenElseStatement ifThen = new IfThenElseStatement(checkType, returnNewVal);
                        javaMethod.addStatement(ifThen);
                        javaMethod.addStatement(new ReturnStatement (localVariable));
                    } else {
                        javaMethod.addStatement(new ReturnStatement (field));
                    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.