Ejemplo n.º 1
0
        internal override Snapshot CreateSnapshot()
        {
            var node          = LookupNode();
            var parentElement = !this.IsRootNamespace
                ? (AbstractCodeElement)this.Parent
                : null;

            var nodesBuilder = ArrayBuilder <SyntaxNode> .GetInstance();

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

            return(new NodeSnapshot(this.State, _fileCodeModel, node, parentElement,
                                    nodesBuilder.ToImmutableAndFree()));
        }
Ejemplo n.º 2
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.GetLogicalSupportedMemberNodes(node);
            var memberNodeCount = memberNodes.Count();

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

            element = null;
            return(false);
        }
Ejemplo n.º 3
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))
            {
                CodeModelService.GetOptionNameAndOrdinal(
                    node,
                    child,
                    out var childName,
                    out var ordinal
                    );
                if (childName == name)
                {
                    element = 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 = CodeImport.Create(State, FileCodeModel, parentElement, childName);
                    return(true);
                }
            }

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

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

            element = null;
            return(false);
        }