Ejemplo n.º 1
0
        public static BaseListSyntax GetBaseList(IHasImplementedInterfaces item)
        {
            var list    = new List <BaseTypeSyntax>();
            var asClass = item as IClass;

            if (asClass != null)
            {
                if (asClass.BaseType != null)
                {
                    var baseTypeSyntax = (TypeSyntax)RDom.CSharp.GetSyntaxNode(asClass.BaseType);
                    var baseSyntax     = SyntaxFactory.SimpleBaseType(baseTypeSyntax);
                    list.Add(baseSyntax);
                }
            }
            foreach (var interf in item.ImplementedInterfaces)
            {
                var interfTypeSyntax = (TypeSyntax)RDom.CSharp.GetSyntaxNode(interf);
                var baseSyntax       = SyntaxFactory.SimpleBaseType(interfTypeSyntax);
                list.Add(baseSyntax);
            }

            var colonToken = SyntaxFactory.Token(SyntaxKind.ColonToken);

            colonToken = BuildSyntaxHelpers.AttachWhitespaceToToken(colonToken, item.Whitespace2Set[LanguageElement.BaseListPrefix]);

            return(list.Any()
                  ? SyntaxFactory.BaseList(colonToken, SyntaxFactory.SeparatedList <BaseTypeSyntax>(list))
                  : null);
        }
Ejemplo n.º 2
0
 internal static void AddImplementedInterfacesSteps <TInterfaceReference>(
     this List <ISourceCodeBuilderStep> steps,
     IHasImplementedInterfaces <TInterfaceReference> implementedInterfaces)
     where TInterfaceReference : IVisitable <IGenericVisitor>
 {
     if (implementedInterfaces.ImplementedInterfaces.Count != 0)
     {
         steps.Add(new WriteWhitespace());
         steps.Add(new WriteColon());
         steps.AddPlaceholder(SourceCodePlaceholder.BeginBaseTypeList);
         steps.Add(new WriteWhitespace());
         steps.AddCommaSeparatedChildNodeSteps(implementedInterfaces.ImplementedInterfaces);
         steps.AddPlaceholder(SourceCodePlaceholder.EndBaseTypeList);
     }
 }
Ejemplo n.º 3
0
        internal static void AddBaseClassAndImplementedInterfacesSteps <TClassReference, TInterfaceReference>(
            this List <ISourceCodeBuilderStep> steps,
            IHasBaseClass <TClassReference> baseClassContainer,
            IHasImplementedInterfaces <TInterfaceReference> implementedInterfaces)
            where TClassReference : IVisitable <IGenericVisitor>
            where TInterfaceReference : IVisitable <IGenericVisitor>
        {
            if (baseClassContainer.BaseClass != null)
            {
                steps.Add(new WriteWhitespace());
                steps.Add(new WriteColon());
                steps.AddPlaceholder(SourceCodePlaceholder.BeginBaseTypeList);
                steps.Add(new WriteWhitespace());
                steps.Add(new WriteChildNode <TClassReference>(baseClassContainer.BaseClass));
            }

            if (implementedInterfaces.ImplementedInterfaces.Count != 0)
            {
                if (baseClassContainer.BaseClass == null)
                {
                    steps.Add(new WriteWhitespace());
                    steps.Add(new WriteColon());
                    steps.AddPlaceholder(SourceCodePlaceholder.BeginBaseTypeList);
                    steps.Add(new WriteWhitespace());
                }
                else
                {
                    steps.Add(new WriteComma());
                    steps.Add(new WriteWhitespace());
                }

                steps.AddCommaSeparatedChildNodeSteps(implementedInterfaces.ImplementedInterfaces);
            }

            if (baseClassContainer.BaseClass != null || implementedInterfaces.ImplementedInterfaces.Count != 0)
            {
                steps.AddPlaceholder(SourceCodePlaceholder.EndBaseTypeList);
            }
        }
Ejemplo n.º 4
0
        private void InitializeBaseList(IHasImplementedInterfaces itemAsT,
                                        SyntaxNode node, IDom parent, SemanticModel model)
        {
            if (itemAsT == null)
            {
                return;
            }

            var symbol     = ((IRoslynHasSymbol)itemAsT).Symbol as INamedTypeSymbol;
            var interfaces = symbol.Interfaces;
            var baseType   = symbol.BaseType;
            var baseList   = node.ChildNodes().OfType <BaseListSyntax>().SingleOrDefault();

            if (baseList != null)
            {
                IEnumerable <BaseTypeSyntax> types = baseList.Types.ToList();
                StoreWhitespaceForToken(itemAsT, baseList.ColonToken, LanguagePart.Current, LanguageElement.BaseListPrefix);
                if (baseType != null)
                {
                    var baseName = baseType.ToString();
                    baseName = baseName.Contains(".")
                              ? baseName.SubstringAfterLast(".")
                              : baseName;
                    if (node is ClassDeclarationSyntax && baseName == types.First().ToString())
                    {
                        var itemAsClass = itemAsT as RDomClass;
                        var syntax      = types.First();
                        if (itemAsClass == null)
                        {
                            throw new InvalidOperationException();
                        }
                        var newBaseType = Corporation.Create(syntax, itemAsT, model).Single()
                                          as IReferencedType;
                        itemAsClass.BaseType = newBaseType;
                        //StoreWhitespace(newBaseType, syntax,
                        //              LanguagePart.Current, whitespaceLookupForImplementedInterfaces);
                        types = types.Skip(1);
                    }
                }
                foreach (var implementedInterfaceSyntax in types)
                {
                    var newInterface = Corporation.Create(implementedInterfaceSyntax, itemAsT, model).Single()
                                       as IReferencedType;
                    //StoreWhitespace(newInterface, implementedInterfaceSyntax,
                    //              LanguagePart.Current, whitespaceLookupForImplementedInterfaces);

                    var whitespace2 = newInterface.Whitespace2Set[LanguageElement.Identifier];
                    if (string.IsNullOrEmpty(whitespace2.LeadingWhitespace))
                    {
                        var prevNodeOrToken = implementedInterfaceSyntax.Parent
                                              .ChildNodesAndTokens()
                                              .PreviousSiblings(implementedInterfaceSyntax)
                                              .LastOrDefault();
                        var sepKind = whitespaceLookupForImplementedInterfaces.Lookup(LanguageElement.Separator);
                        if (prevNodeOrToken.Kind() == sepKind)
                        {
                            var commaToken = prevNodeOrToken.AsToken();
                            whitespace2.LeadingWhitespace = commaToken.TrailingTrivia.ToString();
                        }
                    }

                    itemAsT.ImplementedInterfaces.AddOrMove(newInterface);
                }
            }
        }