class that represents the reference to a mixin with a mixin child
 public ConstructorInjectionSyntaxWriter(
     MixinReference mixin,
     SemanticModel semanticModel)
 {
     _mixin = mixin;
     _semantic = semanticModel;
 }
예제 #2
0
파일: Mixer.cs 프로젝트: pgenfer/mixinSharp
 public void IncludeMixinInChild(MixinReference mixin, ClassWithSourceCode child)
 {
     var childMembers = child.MembersFromThisAndBase;
     var mixinMembers = mixin.Class.MembersFromThisAndBase;
     foreach(var mixinMember in mixinMembers)
     {
         var membersWithSameSignatureInChild = childMembers
             .Where(x => _memberCompare.IsSameAs(x, mixinMember))
             .ToList();
         // 1. case: method does not exist in child => implement it
         if (!membersWithSameSignatureInChild.Any())
             _membersToImplement.Add(mixinMember.Clone());
         else // 2. case: method does exist in child, but is abstract and not overridden => override it
         {
             // member is declared as abstract in a base class of child
             // but not in child itself
             var abstractMembers = membersWithSameSignatureInChild
                 .Where(x => 
                     x.IsAbstract && 
                     x.Class != child && 
                     !child.HasOverride(x));
             _membersToImplement.AddRange(abstractMembers.Select(x => x.Clone(true)));
         }
     }
 }
        public void Setup()
        {
            _child = Substitute.For<ClassWithSourceCode>();
            _mixin = Substitute.For<MixinReference>();
            _mixin.Name.Returns(x => "_mixin");

            _command = new InjectMixinsIntoChildCommand(_mixin);
        }
 public InjectConstructorImplementationStrategy(
     MixinReference mixin,
     SemanticModel semanticModel,
     int positionInSourceFile)
 {
     _mixin = mixin;
     _semantic = semanticModel;
     _classPositionInSourceCode = positionInSourceFile;
 }
 protected override IMixinCommand[] CreateCommands(MixinReference mixin)
 {
     return new IMixinCommand[]
     {
         new IncludeMixinCommand(mixin),
         new AddMixinToBaseListCommand(mixin),
         new InjectMixinsIntoChildCommand(mixin),
     };
 }
 public IncludeMixinSyntaxWriter(
     IEnumerable<Member> membersToImplement, 
     MixinReference mixin, 
     SemanticModel semanticModel, 
     Settings settings = null)
 {
     _members = membersToImplement;
     _mixin = mixin;
     _semantic = semanticModel;
     _settings = settings ?? new Settings();
 }
 /// <summary>
 /// method is virtual, so derived classes can override it to create
 /// different strategies (e.g. for testing)
 /// </summary>
 /// <param name="mixin"></param>
 /// <param name="semantic"></param>
 /// <param name="settings"></param>
 /// <returns></returns>
 protected virtual Dictionary<Type, IImplementMemberForwarding> CreateStrategies(
     MixinReference mixin, SemanticModel semantic, Settings settings)
 {
     var implementationStrategies = new Dictionary<Type, IImplementMemberForwarding>
     {
         [typeof(Method)] = new ImplementMethodForwarding(mixin, _semantic, _settings),
         [typeof(IndexerProperty)] = new ImplementIndexerForwarding(mixin, _semantic, _settings),
         [typeof(Property)] = new ImplementPropertyForwarding(mixin, _semantic, _settings),
         [typeof(Event)] = new ImplementEventForwarding(mixin,_semantic,_settings)
     };
     return implementationStrategies;
 }
 public AddInterfacesToChildSyntaxWriter(
     MixinReference mixin,
     SemanticModel model,
     // needed to reduce type names depending on namespaces
     int positionOfChildClassInCode)
 {
     _mixinInterfaces = new InterfaceList();
     if (mixin.Class.IsInterface)
         _mixinInterfaces.AddInterface(mixin.Class.AsInterface());
     else
         foreach (var @interface in mixin.Class.Interfaces)
             _mixinInterfaces.AddInterface(@interface);
     _semantic = model;
     _positionOfChildClassInCode = positionOfChildClassInCode;
 }
예제 #9
0
        public override void VisitVariableDeclarator(VariableDeclaratorSyntax node)
        {
            // we take only the first declaration we found
            // so if this field definition has more than one variable declaration,
            // skip after the first one
            if (MixinReference != null)
                return;
            var fieldSymbol = (IFieldSymbol)_semantic.GetDeclaredSymbol(node);
            var typeOfField = fieldSymbol.Type;
            // type could not be resolved => return here
            if (typeOfField.TypeKind == TypeKind.Error)
                return;
            
            // also ignore native types (like int, string, double etc...)
            // we identify them by checking if the types are declared in the runtime itself
            // if yes, they are system types and we will skip them
            var module = typeOfField.ContainingModule;
            if (module != null && module.Name == CommonLanguageRuntimeLibrary)
                return;          

            var classFactory = new ClassFactory(_semantic);
            // create the mixin reference, that is the name of the field and the type the field references
            MixinReference = new MixinReference(fieldSymbol.Name, classFactory.Create(typeOfField));
        }
 /// <summary>
 /// constructor that takes a mixin directly. Can be used for testing
 /// </summary>
 /// <param name="mixin"></param>
 public CreateMixinFromFieldDeclarationCommand(MixinReference mixin):base(mixin)
 { }
 public InjectMixinsIntoChildCommand(MixinReference mixin) : base(mixin)
 {
 }
예제 #12
0
 /// <summary>
 /// initializes the base fields of the command object
 /// </summary>
 /// <param name="mixinChild">child class where the mixin should be added</param>
 /// <param name="mixin">mixin that should be added to the child class</param>
 protected MixinCommandBase(MixinReference mixin)
 {
     _mixin = mixin;
 }
예제 #13
0
 /// <summary>
 /// must be implemented by derived classes. Should
 /// return all commands that are part of this composition.
 /// </summary>
 /// <returns>List of commands that are part of this composition in their correct order.</returns>
 protected abstract IMixinCommand[] CreateCommands(MixinReference mixin);
예제 #14
0
 protected CompositeCommand(MixinReference mixin)
 {            
     _commands = CreateCommands(mixin);
     Mixin = mixin;
 }
 public AddFieldDeclarationForMixinCommand(MixinReference mixin) : base(mixin)
 {
 }
 /// <summary>
 /// constructor that takes a mixin directly. Can be used for testing.
 /// </summary>
 /// <param name="mixin">reference to the mixin</param>
 public CreateMixinFromInterfaceCommand(MixinReference mixin):base(mixin)
 { }
예제 #17
0
 public IncludeMixinCommand(MixinReference mixin):base(mixin)
 {            
 }
 public AddMixinToBaseListCommand(MixinReference mixin) : base(mixin)
 {
 }