Exemplo n.º 1
0
        /// <summary>
        /// API to generate methods for an interface. Generated methods will not have
        /// a body generated. Such methods are used only for extracting signatures.
        /// </summary>
        /// <param name="maxNoOfParameters"> </param>
        /// <param name="classList"> </param>
        /// <param name="name">
        /// @return </param>
        public static Method generateMethodForInterface(int maxNoOfParameters, List <ClassGenerator> classList, string name)
        {
            int numberOfParams = ProgGenUtil.getRandomIntInRange(maxNoOfParameters);

            //		if(numberOfParams < 2)
            if (numberOfParams < ProgGenUtil.minNoOfParameters)
            {
                numberOfParams = ProgGenUtil.minNoOfParameters;
            }
            //TODO: So, interface methods will have at least 2 parameters, but why?
            return(new Method(false, numberOfParams, null, classList, name, 0, 0, 0, false));
        }
Exemplo n.º 2
0
        /// <summary>
        /// API to generate a method for a class.
        /// </summary>
        /// <param name="generator"> </param>
        /// <param name="maxNumberOfParams"> </param>
        /// <param name="classList"> </param>
        /// <param name="name"> </param>
        /// <param name="maxLocPerMethod"> </param>
        /// <param name="maxNestedIfs"> </param>
        /// <param name="maxAllowedMethodCalls"> </param>
        /// <param name="needMethodBody">
        /// @return </param>
        public static Method generateMethod(ClassGenerator generator, int maxNumberOfParams, List <ClassGenerator> classList, string name, int maxLocPerMethod, int maxNestedIfs, int maxAllowedMethodCalls, bool needMethodBody)
        {
            bool isStatic = ProgGenUtil.coinFlip();

            //we need minimum of two parameters
            int numberOfParams = ProgGenUtil.getRandomIntInRange(maxNumberOfParams);

            //if(numberOfParams<2)
            if (numberOfParams < ProgGenUtil.minNoOfParameters)
            {
                numberOfParams = ProgGenUtil.minNoOfParameters;
            }

            return(new Method(isStatic, numberOfParams, generator, classList, name, maxLocPerMethod, maxNestedIfs, maxAllowedMethodCalls, needMethodBody));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns field name.
        /// e.g.:
        /// Array type: a[5]
        /// Non array type: a
        /// </summary>
        public override string ToString()
        {
            this.literal = "";

            if (!isArray)
            {
                literal += name;
            }
            else
            {
                int arrayIndex = ProgGenUtil.getRandomIntInRange(arraySize);
                literal += name + "[" + arrayIndex + "]";
            }

            return(literal);
        }