/// <summary> /// Tries to construct a new plan that sets a field for a /// receiver of the type given. May fail if there are no /// applicable receivers. /// </summary> /// <param name="type"></param> /// <param name="plan"></param> /// <returns></returns> private void NewFieldSettingPlan(FieldInfo field, PlanManager planManager, bool forbidNull) { this.stats.Selected(FieldSettingTransformer.Get(field).ToString()); Type[] parameterTypes = new Type[2]; parameterTypes[0] = field.DeclaringType; parameterTypes[1] = field.FieldType; RandomPlansResult r; if (!RandomPlans(out r, parameterTypes, delegate(Plan p, int i) { if (i == 0 && p.transformer is PrimitiveValueTransformer) { return(false); } return(true); }, planManager.builderPlans, forbidNull, null)) { stats.CreatedNew(CreationResult.NoInputs); return; } Plan plan = new Plan(FieldSettingTransformer.Get(field), r.fplans, r.fparameterChoosers); planManager.AddMaybeExecutingIfNeeded(plan, this.stats); }
/// <summary> /// Tries to construct a new plan that calls a method on a /// receiver of the type given. May fail if there are no /// applicable methods or receivers available. /// </summary> /// <param name="type"></param> /// <param name="plan"></param> /// <returns></returns> private void NewMethodPlan(Type type, MethodInfo method, PlanManager planManager, bool forbidNull, Type[] methodArgumentTypes) { this.stats.Selected(MethodCall.Get(method).ToString()); PlanFilter f; if (forbidNull) { f = delegate(Plan p, int i) { if (!method.IsStatic && i == 0 && p.transformer is PrimitiveValueTransformer) { return(false); } // Non-null heuristic if (!methodArgumentTypes[i].IsValueType && (p.transformer is PrimitiveValueTransformer)) { return(false); } return(true); }; } else { f = delegate(Plan p, int i) { if (!method.IsStatic && i == 0 && p.transformer is PrimitiveValueTransformer) { return(false); } return(true); }; } RandomPlansResult r; if (!RandomPlans(out r, methodArgumentTypes, f, planManager.builderPlans, forbidNull, method)) { stats.CreatedNew(CreationResult.NoInputs); return; } //Console.WriteLine("\t\t A plan has been created"); Plan plan = new Plan(MethodCall.Get(method), r.fplans, r.fparameterChoosers); planManager.AddMaybeExecutingIfNeeded(plan, this.stats); }
/// <summary> /// Tries to construct a new plan that calls a method on a /// receiver of the type given. May fail if there are no /// applicable methods or receivers available. /// </summary> /// <param name="type"></param> /// <param name="plan"></param> /// <returns></returns> private void NewMethodPlan(Type type, MethodInfo method, PlanManager planManager, bool forbidNull, Type[] methodArgumentTypes) { stats.Selected(MethodCall.Get(method).ToString()); PlanFilter f; if (forbidNull) { f = delegate(Plan p, int i) { if (!method.IsStatic && i == 0 && p.transformer is PrimitiveValueTransformer) { return(false); } //// Non-null heuristic [email protected] //if (!methodArgumentTypes[i].IsValueType && (p.transformer is PrimitiveValueTransformer)) // return false; return(true); }; } else { f = delegate(Plan p, int i) { if (!method.IsStatic && i == 0 && p.transformer is PrimitiveValueTransformer) { return(false); } return(true); }; } if (!RandomPlans(out RandomPlansResult randomPlansResult, methodArgumentTypes, f, planManager.builderPlans, forbidNull, method)) { stats.CreatedNew(CreationResult.NoInputs); return; } //Logger.Debug("\t\t A plan has been created"); Plan plan = new Plan(MethodCall.Get(method), randomPlansResult.fplans, randomPlansResult.fparameterChoosers); plan.ClassName = method.DeclaringType.Name; planManager.AddMaybeExecutingIfNeeded(plan, stats); }
/// <summary> /// Tries to construct a new plan that calls a constructor /// of the type given. May fail if there are no /// applicable constructors. /// </summary> /// <param name="type"></param> /// <param name="plan"></param> /// <returns></returns> private void NewConstructorPlan(Type type, ConstructorInfo constructor, PlanManager planManager, bool forbidNull, Type[] constructorArgumentTypes) { this.stats.Selected(ConstructorCallTransformer.Get(constructor).ToString()); PlanFilter f; if (forbidNull) { f = delegate(Plan p, int i) { // Non-null heuristic if (!constructorArgumentTypes[i].IsValueType && (p.transformer is PrimitiveValueTransformer)) { return(false); } return(true); }; } else { f = delegate(Plan p, int i) { return(true); }; } RandomPlansResult r; if (!RandomPlans(out r, constructorArgumentTypes, f, planManager.builderPlans, forbidNull, null)) { stats.CreatedNew(CreationResult.NoInputs); return; } Plan plan = new Plan(ConstructorCallTransformer.Get(constructor), r.fplans, r.fparameterChoosers); plan.ClassName = constructor.DeclaringType.Name; planManager.AddMaybeExecutingIfNeeded(plan, this.stats); }
/// <summary> /// Tries to construct a new plan that sets a field for a /// receiver of the type given. May fail if there are no /// applicable receivers. /// </summary> /// <param name="type"></param> /// <param name="plan"></param> /// <returns></returns> private void NewFieldSettingPlan(FieldInfo field, PlanManager planManager, bool forbidNull) { this.stats.Selected(FieldSettingTransformer.Get(field).ToString()); Type[] parameterTypes = new Type[2]; parameterTypes[0] = field.DeclaringType; parameterTypes[1] = field.FieldType; RandomPlansResult r; if (!RandomPlans(out r, parameterTypes, delegate(Plan p, int i) { if (i == 0 && p.transformer is PrimitiveValueTransformer) return false; return true; }, planManager.builderPlans, forbidNull, null)) { stats.CreatedNew(CreationResult.NoInputs); return; } Plan plan = new Plan(FieldSettingTransformer.Get(field), r.fplans, r.fparameterChoosers); planManager.AddMaybeExecutingIfNeeded(plan, this.stats); }
/// <summary> /// Tries to construct a new plan that calls a constructor /// of the type given. May fail if there are no /// applicable constructors. /// </summary> /// <param name="type"></param> /// <param name="plan"></param> /// <returns></returns> private void NewConstructorPlan(Type type, ConstructorInfo constructor, PlanManager planManager, bool forbidNull, Type[] constructorArgumentTypes) { this.stats.Selected(ConstructorCallTransformer.Get(constructor).ToString()); PlanFilter f; if (forbidNull) { f = delegate(Plan p, int i) { // Non-null heuristic if (!constructorArgumentTypes[i].IsValueType && (p.transformer is PrimitiveValueTransformer)) return false; return true; }; } else { f = delegate(Plan p, int i) { return true; }; } RandomPlansResult r; if (!RandomPlans(out r, constructorArgumentTypes, f, planManager.builderPlans, forbidNull, null)) { stats.CreatedNew(CreationResult.NoInputs); return; } Plan plan = new Plan(ConstructorCallTransformer.Get(constructor), r.fplans, r.fparameterChoosers); planManager.AddMaybeExecutingIfNeeded(plan, this.stats); }
/// <summary> /// Tries to construct a new plan that calls a method on a /// receiver of the type given. May fail if there are no /// applicable methods or receivers available. /// </summary> /// <param name="type"></param> /// <param name="plan"></param> /// <returns></returns> private void NewMethodPlan(Type type, MethodInfo method, PlanManager planManager, bool forbidNull, Type[] methodArgumentTypes) { this.stats.Selected(MethodCall.Get(method).ToString()); PlanFilter f; if (forbidNull) { f = delegate(Plan p, int i) { if (!method.IsStatic && i == 0 && p.transformer is PrimitiveValueTransformer) return false; // Non-null heuristic if (!methodArgumentTypes[i].IsValueType && (p.transformer is PrimitiveValueTransformer)) return false; return true; }; } else { f = delegate(Plan p, int i) { if (!method.IsStatic && i == 0 && p.transformer is PrimitiveValueTransformer) return false; return true; }; } RandomPlansResult r; if (!RandomPlans(out r, methodArgumentTypes, f, planManager.builderPlans, forbidNull, method)) { stats.CreatedNew(CreationResult.NoInputs); return; } //Console.WriteLine("\t\t A plan has been created"); Plan plan = new Plan(MethodCall.Get(method), r.fplans, r.fparameterChoosers); planManager.AddMaybeExecutingIfNeeded(plan, this.stats); }