private IOperationResult Mutate(IMutator[] mutators, MutationParameters parameters)
 {
     var compositeResult = new CompositeOperationResult();
       foreach (var mutator in mutators) {
     var result = mutator.Mutate(parameters);
     compositeResult.AddResult(result);
       }
       return compositeResult;
 }
 public OperationResult Morph(MutationParameters parameters)
 {
     parameters.Validate();
       if (parameters.SourceType == null) throw new ArgumentException("parameters must contain a SourceType", "parameters");
       var targetType = parameters.SourceType; // the source is also the target
       var visitor = new MorphIntoInterfaceVisitor(parameters);
       targetType.Accept(visitor);
       return visitor.Result;
 }
        /// <summary>
        /// Executes the given mutators.
        /// </summary>
        /// <param name="mutators">Mutators.</param>
        /// <returns>The composite result of all mutators' mutations.</returns>
        public IOperationResult Run(params IMutator[] mutators)
        {
            if (mutators == null || mutators.Length == 0) return null;

              var context = new MutationContext(_sourceAssembly.MainModule);
              var parameters = new MutationParameters {
            Context = context,
            SourceType = _sourceType
              };

              var result = Mutate(mutators, parameters);
              context.Finalize(result);

              return result;
        }
 public IOperationResult Mutate(MutationParameters parameters)
 {
     parameters.Validate();
       var assembly = parameters.Assembly;
       var result = new CompositeOperationResult();
       assembly.MainModule.GetAllTypes(). // TODO: what about other modules?
     Where(type => DoesRoles(type)).
     // TODO: do we need a special order here? like base classes first?
     ForEach(type => {
       var singleResult = new RoleComposerMutator().ComposeRoles(
     new MutationParameters {
       SourceType = type,
       Context = parameters.Context
     });
       result.AddResult(singleResult);
     });
       return result;
 }
        public IOperationResult Morph(MutationParameters parameters)
        {
            if (parameters.SourceType != null) return MorphType(parameters);

              parameters.Validate();
              var assembly = parameters.Assembly;
              var result = new CompositeOperationResult();
              assembly.MainModule.GetAllTypes().
            Where(type => type.IsRole() && !type.IsRoleView()).
            ForEach(role => {
              var singleResult = MorphType(
            new MutationParameters {
              SourceType = role,
              Context = parameters.Context
            }
              );
              result.AddResult(singleResult);
            });
              return result;
        }
        public RoleComposerResult ComposeRoles(MutationParameters parameters)
        {
            parameters.Validate();
              _targetType = parameters.SourceType;
              if (_targetType == null) throw new ArgumentException("parameters must contain a SourceType", "parameters");

              Tracer.TraceVerbose("Compose class: {0}", _targetType.ToString());

              var result = new RoleComposerResult();

              CheckComposition(result);
              if (!result.Success) { return result; }

              var roles = RetrieveRoles();

              var conflictDetector = new ConflictDetector(_targetType);
              {
            var memberProcessResult = conflictDetector.Process(roles);
            result.AddResult(memberProcessResult);
            if (!memberProcessResult.Success) {
              return result;
            }
              }

              if (_targetType.IsRole()) {
            // roles are not composed
            return result;
              }

              {
            _container = conflictDetector.Container;
            var composeResult = ComposeRoles(roles);
            result.AddResult(composeResult);
            if (!composeResult.Success) {
              return result;
            }
              }

              return result;
        }
        public MorphIntoRoleResult MorphType(MutationParameters parameters)
        {
            parameters.Validate();
              var roleType = parameters.SourceType;
              if (roleType == null) throw new ArgumentException("parameters must include a SourceType", "parameters");

              _parameters = parameters;

              if (!roleType.IsRole()) {
            throw new InvalidOperationException("Cannot morph class into role");
              }

              Tracer.TraceVerbose("Morph role: {0}", roleType);

              var result = new MorphIntoRoleResult();

              CheckRole(roleType, result);
              if (!result.Success) { return result; }

              PreProcessRole(roleType); // TODO: result?
              if (!result.Success) { return result; }

              var roleStateClass = ExtractRoleStateClass(roleType, result);
              if (!result.Success) { return result; }

              // TODO: Cecil bug! We need to touch the SemanticsAttributes in order for it to remain on the method!
              roleType.Methods.Select(m => m.SemanticsAttributes).ToList();

              var roleCodeClass = ExtractRoleCodeClass(roleType, result);
              if (!result.Success) { return result; }

              MorphRoleIntoInterface(roleType, result);
              if (!result.Success) { return result; }

              result.CodeType = roleCodeClass;
              result.StateType = roleStateClass;

              return result;
        }
 public IOperationResult Mutate(MutationParameters parameters)
 {
     parameters.Validate();
       return Check(parameters);
 }
 public IOperationResult Check(MutationParameters parameters)
 {
     _roleType = parameters.SourceType;
       return Check(parameters.Context);
 }
 IOperationResult IMutator.Mutate(MutationParameters parameters)
 {
     return Morph(parameters);
 }
 public IOperationResult Check(MutationParameters parameters)
 {
     return Check(parameters.Context);
 }
 IOperationResult IMutator.Mutate(MutationParameters parameters)
 {
     return ComposeRoles(parameters);
 }
 public MorphIntoInterfaceVisitor(MutationParameters parameters)
 {
     if (parameters == null) throw new ArgumentNullException("parameters");
     if (parameters.SourceType == null) throw new ArgumentException("parameters must contain a SourceType", "parameters");
     _parameters = parameters;
 }