예제 #1
0
        protected override IDom CreateItemFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model)
        {
            var syntax = syntaxNode as NamespaceDeclarationSyntax;
            // TODO: I think there is a better way to do this, but I can't find it right now
            var names = syntax.Name.ToString().Split(new char[] { '.' });
            var group = Guid.Empty;

            if (names.Count() > 1)
            {
                group = Guid.NewGuid();
            }
            RDomNamespace item           = null;
            RDomNamespace outerNamespace = null;

            foreach (var name in names)
            {
                var newItem = new RDomNamespace(syntaxNode, parent, model, name, group);
                CreateFromWorker.StandardInitialize(newItem, syntaxNode, parent, model, OutputContext);
                CreateFromWorker.StoreWhitespace(newItem, syntax, LanguagePart.Current, WhitespaceLookup);

                // At this point, item is the last newItem
                if (item != null)
                {
                    item.StemMembersAll.AddOrMove(newItem);
                }
                item = newItem;
                if (outerNamespace == null)
                {
                    outerNamespace = item;
                }
                if (name != names.Last())
                {
                    parent = item;
                }
            }

            // Qualified name unbundles namespaces, and if it's defined together, we want it together here.
            // Thus, this replaces hte base Initialize name with the correct one
            if (item.Name.StartsWith("@"))
            {
                item.Name = item.Name.Substring(1);
            }
            CreateFromWorker.LoadStemMembers(item, syntax.Members, syntax.Usings, model);

            HandleTrailingTrivia(syntax, model, item);

            // This will return the outer namespace, which in the form N is the only one.
            // In the form N1.N2.. there is a nested level for each part (N1, N2).
            // The inner holds the children, the outer is returned.
            return(outerNamespace);
        }
예제 #2
0
        protected override IDom CreateItemFrom(SyntaxNode syntaxNode, IDom parent, SemanticModel model)
        {
            var syntax  = syntaxNode as CompilationUnitSyntax;
            var newItem = new RDomRoot(OutputContext.Corporation.FactoryAccess, syntaxNode, parent, model);

            // Root does not call StandardInitialize because the info is attched to the first item
            // and particularly, whitespace would be doubled.
            //CreateFromWorker.InitializePublicAnnotations(newItem,  syntaxNode,  parent,  model);

            newItem.FilePath = syntax.SyntaxTree.FilePath;
            newItem.Name     = Path.GetFileNameWithoutExtension(newItem.FilePath);
            CreateFromWorker.LoadStemMembers(newItem, syntax.Members, syntax.Usings, model);

            return(newItem);
        }