/// <summary> /// Method to fetch fields which are of OBJECT primitive type. /// </summary> /// <param name="variableList"> /// @return </param> //JAVA TO C# CONVERTER TODO TASK: Java wildcard generics are not converted to .NET: //ORIGINAL LINE: private static java.util.ArrayList<? extends edu.uta.cse.proggen.classLevelElements.Field> getObjects(java.util.ArrayList<? extends edu.uta.cse.proggen.classLevelElements.Field> variableList) //JAVA TO C# CONVERTER TODO TASK: Java wildcard generics are not converted to .NET: //ORIGINAL LINE: private static java.util.ArrayList<? extends edu.uta.cse.proggen.classLevelElements.Field> getObjects(java.util.ArrayList<? extends edu.uta.cse.proggen.classLevelElements.Field> variableList) //static void Cat<T> (IList<T> sources) //Veena : Again unreachable Code. // THis is if Objects are being created. Since we are not doing inheritence/Objects, it's Unreacheble. //So dont waste time converting it. Get a Life :P //private static List<T> getObjects(List<T> variableList) where ? : edu.uta.cse.proggen.classLevelElements.Field where T1 : edu.uta.cse.proggen.classLevelElements.Field //{ // List<Field> objList = new List<Field>(); // foreach (Field @var in variableList) // { // if (@var.Type.Type == Type.Primitives.OBJECT) // { // objList.Add(@var); // } // } // return objList; //} private static string getParametersForList(List <Variable> parameterList, Method method) { string parameters = ""; foreach (Variable @var in parameterList) { if (@var.Name.Equals("recursionCounter")) { parameters += "recursionCounter,"; continue; } Operand operand; Type.Primitives primitive = @var.Type.getType();//.Type.Type; int optionVariableOrField = (new Random()).Next(1); if (optionVariableOrField == 0) { operand = VariableGenerator.getRandomizedVariable(method, primitive); } else { operand = FieldGenerator.getRandomField(method.AssociatedClass, primitive, method.Static); } parameters += operand + ","; } parameters = parameters.Substring(0, parameters.Length - 1); return(parameters); }
/// <summary> /// Generates an appropriate return statement for the Method. /// </summary> private void generateReturnStatement() { StringBuilder builder = new StringBuilder("return "); builder.Append("("); builder.Append(this.returnType); builder.Append(")"); int choiceVarOrLiteral = (new Random()).Next(1); Operand operand; if (choiceVarOrLiteral == 0) { operand = VariableGenerator.getRandomizedVariable(this, this.returnType); } else { operand = new Literal(this.returnType); } builder.Append(operand); builder.Append(";\n"); this.returnStatement = builder.ToString(); }
public static Statement getRandomizedStatement(Method method, List <ClassGenerator> classList) { Statement stmt = new Statement(); Random rand = new Random(); int option = 0; option = rand.Next(100) % 3; switch (option) { case 0: // Assignment statement stmt.stmt = (new AssignmentExpression(method)).ToString(); //FIXME: if there is no local variable available to assign, it will simply use print statement. // following line will add an extra line to the LOC method.Loc = method.Loc + 1; break; case 1: // Print statements: Max. 5 lines in a block stmt.stmt = (new PrintStatement(method)).ToString(); break; case 2: // method calls: restrict it to MAX_ALLOWED_METH_CALL int methCalledCounterValue = method.MethodCallCounter + 1; method.MethodCallCounter = methCalledCounterValue; if (methCalledCounterValue < method.MaxAllowedMethodCalls) { if (ProgGenUtil.coinFlip()) { stmt.stmt += ProgGenUtil.getMethodCall(method, classList); } else { //wire it to variables in scope Operand lhs; Random random = new Random(); HashSet <Type.Primitives> validPrimitivesInScope = ProgGenUtil.getValidPrimitivesInScope(method); //Pick a type object[] primitivesArray = validPrimitivesInScope.ToArray(); if (primitivesArray.Length == 0) { stmt.stmt += ProgGenUtil.getMethodCall(method, classList); break; } Type.Primitives selectedPrimitive = (Type.Primitives)primitivesArray[random.Next(primitivesArray.Length)]; // Introducing any variable lhs = VariableGenerator.getRandomizedVariable(method, selectedPrimitive); string methodCall = ProgGenUtil.getMethodCallForReturnType(method, classList, new Type(selectedPrimitive, ""), lhs); stmt.stmt += methodCall + "\n"; } } else { stmt.stmt = (new PrintStatement(method)).ToString(); } break; default: stmt.stmt = (new IfStmtIfStmt(method, classList)).ToString(); break; } return(stmt); }