Esempio n. 1
0
        protected override bool TryGetItemByName(string name, out EnvDTE.CodeElement element)
        {
            var node          = LookupNode();
            var parentElement = !IsRootNamespace
                ? (AbstractCodeElement)Parent
                : null;

            // Option statements
            foreach (var child in CodeModelService.GetOptionNodes(node))
            {
                string childName;
                int    ordinal;
                CodeModelService.GetOptionNameAndOrdinal(node, child, out childName, out ordinal);
                if (childName == name)
                {
                    element = (EnvDTE.CodeElement)CodeOptionsStatement.Create(State, FileCodeModel, childName, ordinal);
                    return(true);
                }
            }

            // Imports/using statements
            foreach (var child in CodeModelService.GetImportNodes(node))
            {
                var childName = CodeModelService.GetImportNamespaceOrType(child);
                if (childName == name)
                {
                    element = (EnvDTE.CodeElement)CodeImport.Create(State, FileCodeModel, parentElement, childName);
                    return(true);
                }
            }

            // Attributes
            foreach (var child in CodeModelService.GetAttributeNodes(node))
            {
                string childName;
                int    ordinal;
                CodeModelService.GetAttributeNameAndOrdinal(node, child, out childName, out ordinal);
                if (childName == name)
                {
                    element = (EnvDTE.CodeElement)CodeAttribute.Create(State, FileCodeModel, parentElement, childName, ordinal);
                    return(true);
                }
            }

            // Members
            foreach (var child in CodeModelService.GetFlattenedMemberNodes(node))
            {
                var childName = CodeModelService.GetName(child);
                if (childName == name)
                {
                    element = FileCodeModel.CreateCodeElement <EnvDTE.CodeElement>(child);
                    return(true);
                }
            }

            element = null;
            return(false);
        }
Esempio n. 2
0
        internal override Snapshot CreateSnapshot()
        {
            var node          = LookupNode();
            var parentElement = (AbstractCodeElement)this.Parent;

            var nodesBuilder = ImmutableArray.CreateBuilder <SyntaxNode>();

            nodesBuilder.AddRange(CodeModelService.GetFlattenedMemberNodes(node));

            return(new NodeSnapshot(this.State, _fileCodeModel, node, parentElement, nodesBuilder.ToImmutable()));
        }
Esempio n. 3
0
        protected override bool TryGetItemByIndex(int index, out EnvDTE.CodeElement element)
        {
            var node = LookupNode();

            var memberNodes = CodeModelService.GetFlattenedMemberNodes(node);

            if (index >= 0 && index < memberNodes.Count())
            {
                var child = memberNodes.ElementAt(index);
                element = FileCodeModel.CreateCodeElement <EnvDTE.CodeElement>(child);
                return(true);
            }

            element = null;
            return(false);
        }
Esempio n. 4
0
        internal override Snapshot CreateSnapshot()
        {
            var node          = LookupNode();
            var parentElement = !this.IsRootNamespace
                ? (AbstractCodeElement)this.Parent
                : null;

            var nodesBuilder = ImmutableArray.CreateBuilder <SyntaxNode>();

            nodesBuilder.AddRange(CodeModelService.GetOptionNodes(node));
            nodesBuilder.AddRange(CodeModelService.GetImportNodes(node));
            nodesBuilder.AddRange(CodeModelService.GetAttributeNodes(node));
            nodesBuilder.AddRange(CodeModelService.GetFlattenedMemberNodes(node));

            return(new NodeSnapshot(this.State, _fileCodeModel, node, parentElement, nodesBuilder.ToImmutable()));
        }
Esempio n. 5
0
        protected override bool TryGetItemByName(string name, out EnvDTE.CodeElement element)
        {
            var node = LookupNode();

            foreach (var child in CodeModelService.GetFlattenedMemberNodes(node))
            {
                var childName = CodeModelService.GetName(child);
                if (childName == name)
                {
                    element = FileCodeModel.CreateCodeElement <EnvDTE.CodeElement>(child);
                    return(true);
                }
            }

            element = null;
            return(false);
        }
Esempio n. 6
0
        protected override bool TryGetItemByIndex(int index, out EnvDTE.CodeElement element)
        {
            var node          = LookupNode();
            var parentElement = !this.IsRootNamespace
                ? (AbstractCodeElement)this.Parent
                : null;

            int currentIndex = 0;

            // Option statements
            var optionNodes     = CodeModelService.GetOptionNodes(node);
            var optionNodeCount = optionNodes.Count();

            if (index < currentIndex + optionNodeCount)
            {
                var child = optionNodes.ElementAt(index - currentIndex);
                element = CreateCodeOptionsStatement(child, node);
                return(true);
            }

            currentIndex += optionNodeCount;

            // Imports/using statements
            var importNodes     = CodeModelService.GetImportNodes(node);
            var importNodeCount = importNodes.Count();

            if (index < currentIndex + importNodeCount)
            {
                var child = importNodes.ElementAt(index - currentIndex);
                element = CreateCodeImport(child, parentElement);
                return(true);
            }

            currentIndex += importNodeCount;

            // Attributes
            var attributeNodes     = CodeModelService.GetAttributeNodes(node);
            var attributeNodeCount = attributeNodes.Count();

            if (index < currentIndex + attributeNodeCount)
            {
                var child = attributeNodes.ElementAt(index - currentIndex);
                element = CreateCodeAttribute(child, node, parentElement);
                return(true);
            }

            currentIndex += attributeNodeCount;

            // Members
            var memberNodes     = CodeModelService.GetFlattenedMemberNodes(node);
            var memberNodeCount = memberNodes.Count();

            if (index < currentIndex + memberNodeCount)
            {
                var child = memberNodes.ElementAt(index - currentIndex);
                element = FileCodeModel.CreateCodeElement <EnvDTE.CodeElement>(child);
                return(true);
            }

            element = null;
            return(false);
        }