示例#1
0
 protected override object GetExtenderNames()
 => CodeModelService.GetPropertyExtenderNames();
            private bool CompareAttributeArguments(AttributeArgumentListSyntax oldAttributeArguments, AttributeArgumentListSyntax newAttributeArguments)
            {
                if (oldAttributeArguments == null || newAttributeArguments == null)
                {
                    return(oldAttributeArguments == newAttributeArguments);
                }

                var oldArguments = oldAttributeArguments.Arguments;
                var newArguments = newAttributeArguments.Arguments;

                if (oldArguments.Count != newArguments.Count)
                {
                    return(false);
                }

                for (var i = 0; i < oldArguments.Count; i++)
                {
                    var oldArgument = oldArguments[i];
                    var newArgument = newArguments[i];

                    if (!StringComparer.Ordinal.Equals(CodeModelService.GetName(oldArgument), CodeModelService.GetName(newArgument)))
                    {
                        return(false);
                    }

                    if (!CompareExpressions(oldArgument.Expression, newArgument.Expression))
                    {
                        return(false);
                    }
                }

                return(true);
            }
示例#3
0
        internal EnvDTE.CodeStruct AddStruct(SyntaxNode containerNode, string name, object position, object bases, object implementedInterfaces, EnvDTE.vsCMAccess access)
        {
            // TODO(DustinCa): Old C# code base doesn't even check bases for validity -- does VB?

            var containerNodePosition = containerNode.SpanStart;
            var semanticModel         = GetSemanticModel();

            var implementedInterfaceArray = GetValidArray(bases, allowMultipleElements: true);

            var implementedInterfaceSymbols = Array.ConvertAll(implementedInterfaceArray,
                                                               i => (INamedTypeSymbol)CodeModelService.GetTypeSymbol(i, semanticModel, containerNodePosition));

            var newType = CreateTypeDeclaration(
                containerNode,
                TypeKind.Struct,
                CodeModelService.GetUnescapedName(name),
                access,
                implementedInterfaces: implementedInterfaceSymbols);

            var insertionIndex = CodeModelService.PositionVariantToMemberInsertionIndex(position, containerNode, fileCodeModel: this);

            newType = InsertMember(containerNode, newType, insertionIndex);

            return((EnvDTE.CodeStruct)CreateInternalCodeMember(this.State, fileCodeModel: this, node: newType));
        }
            private bool CompareEnumMemberDeclarations(
                EnumMemberDeclarationSyntax oldEnumMember,
                EnumMemberDeclarationSyntax newEnumMember,
                SyntaxNode newNodeParent,
                CodeModelEventQueue eventQueue)
            {
                Debug.Assert(oldEnumMember != null && newEnumMember != null);

                var same = true;

                if (!StringComparer.Ordinal.Equals(CodeModelService.GetName(oldEnumMember), CodeModelService.GetName(newEnumMember)))
                {
                    EnqueueChangeEvent(newEnumMember, newNodeParent, CodeModelEventType.Rename, eventQueue);
                    same = false;
                }

                same &= CompareChildren(
                    CompareAttributeLists,
                    oldEnumMember.AttributeLists.AsReadOnlyList(),
                    newEnumMember.AttributeLists.AsReadOnlyList(),
                    newEnumMember,
                    CodeModelEventType.Unknown,
                    eventQueue);

                return(same);
            }
            private bool CompareVariableDeclarators(
                VariableDeclaratorSyntax oldVariableDeclarator,
                VariableDeclaratorSyntax newVariableDeclarator,
                SyntaxNode newNodeParent,
                CodeModelEventQueue eventQueue)
            {
                Debug.Assert(oldVariableDeclarator != null && newVariableDeclarator != null);

                if (!StringComparer.Ordinal.Equals(CodeModelService.GetName(oldVariableDeclarator), CodeModelService.GetName(newVariableDeclarator)))
                {
                    EnqueueChangeEvent(newVariableDeclarator, newNodeParent, CodeModelEventType.Rename, eventQueue);
                    return(false);
                }

                return(true);
            }
        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.CreateCodeElement <EnvDTE.CodeElement>(child);
                return(true);
            }

            element = null;
            return(false);
        }
示例#7
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);
        }
示例#8
0
 protected virtual string GetFullName()
 => CodeModelService.GetExternalSymbolFullName(LookupSymbol());
示例#9
0
 internal override ImmutableArray <SyntaxNode> GetParameters()
 {
     return(ImmutableArray.CreateRange(CodeModelService.GetParameterNodes(LookupNode())));
 }
示例#10
0
 private bool HasAccessorNode(MethodKind methodKind)
 {
     return(CodeModelService.TryGetAccessorNode(LookupNode(), methodKind, out var accessorNode));
 }
示例#11
0
        protected virtual string GetName()
        {
            var node = LookupNode();

            return(CodeModelService.GetName(node));
        }
示例#12
0
 public EnvDTE.CodeTypeRef CreateCodeTypeRef(object type)
 {
     return(CodeModelService.CreateCodeTypeRef(this.State, _projectId, type));
 }
示例#13
0
 private bool IsExpressionBodiedProperty()
 => CodeModelService.IsExpressionBodiedProperty(LookupNode());
示例#14
0
 protected override object GetExtender(string name)
 => CodeModelService.GetPropertyExtender(name, LookupNode(), LookupSymbol());
示例#15
0
 protected override object GetExtenderNames()
 {
     return(CodeModelService.GetTypeExtenderNames());
 }
示例#16
0
 protected override object GetExtender(string name)
 {
     return(CodeModelService.GetFunctionExtender(name, LookupNode(), LookupSymbol()));
 }
示例#17
0
 protected override object GetExtender(string name)
 {
     return(CodeModelService.GetTypeExtender(name, this));
 }
示例#18
0
        protected SyntaxNode CreateConstructorDeclaration(SyntaxNode containerNode, string typeName, EnvDTE.vsCMAccess access)
        {
            var destination = CodeModelService.GetDestination(containerNode);

            var newMethodSymbol = CodeGenerationSymbolFactory.CreateConstructorSymbol(
                attributes: default,
        private EnvDTE.CodeElement CreateCodeImport(SyntaxNode node, AbstractCodeElement parentElement)
        {
            var name = CodeModelService.GetImportNamespaceOrType(node);

            return(CodeImport.Create(this.State, this.FileCodeModel, parentElement, name));
        }
示例#20
0
        protected override bool TryGetItemByIndex(int index, out EnvDTE.CodeElement element)
        {
            var parameters = this.ParentElement.GetParameters();

            if (index < parameters.Length)
            {
                var parameter = parameters[index];
                element = (EnvDTE.CodeElement)CodeParameter.Create(this.State, this.ParentElement, CodeModelService.GetParameterName(parameter));
                return(true);
            }

            element = null;
            return(false);
        }
            private bool CompareParameters(ParameterSyntax oldParameter, ParameterSyntax newParameter, SyntaxNode newNodeParent, CodeModelEventQueue eventQueue)
            {
                Debug.Assert(oldParameter != null && newParameter != null);

                var same = true;

                if (!StringComparer.Ordinal.Equals(CodeModelService.GetName(oldParameter), CodeModelService.GetName(newParameter)))
                {
                    EnqueueChangeEvent(newParameter, newNodeParent, CodeModelEventType.Rename, eventQueue);
                    same = false;
                }

                // If modifiers or the type have changed enqueue a element changed (unknown change) node
                if (!CompareModifiers(oldParameter, newParameter) ||
                    !CompareTypes(oldParameter.Type, newParameter.Type))
                {
                    EnqueueChangeEvent(newParameter, newNodeParent, CodeModelEventType.Unknown, eventQueue);
                    same = false;
                }

                return(same);
            }
 protected virtual string GetName()
 {
     return(CodeModelService.GetExternalSymbolName(LookupSymbol()));
 }
            private bool ComparePropertyDeclarations(
                BasePropertyDeclarationSyntax oldProperty,
                BasePropertyDeclarationSyntax newProperty,
                SyntaxNode newNodeParent,
                CodeModelEventQueue eventQueue)
            {
                Debug.Assert(oldProperty != null && newProperty != null);

                var same = true;

                if (!StringComparer.Ordinal.Equals(CodeModelService.GetName(oldProperty), CodeModelService.GetName(newProperty)))
                {
                    EnqueueChangeEvent(newProperty, newNodeParent, CodeModelEventType.Rename, eventQueue);
                    same = false;
                }

                // If modifiers have changed enqueue a element changed (unknown change) node
                if (!CompareModifiers(oldProperty, newProperty))
                {
                    EnqueueChangeEvent(newProperty, newNodeParent, CodeModelEventType.Unknown, eventQueue);
                    same = false;
                }

                // If return type had changed enqueue a element changed (typeref changed) node
                if (!CompareTypes(oldProperty.Type, newProperty.Type))
                {
                    EnqueueChangeEvent(newProperty, newNodeParent, CodeModelEventType.TypeRefChange, eventQueue);
                    same = false;
                }

                same &= CompareChildren(
                    CompareAttributeLists,
                    oldProperty.AttributeLists.AsReadOnlyList(),
                    newProperty.AttributeLists.AsReadOnlyList(),
                    newProperty,
                    CodeModelEventType.Unknown,
                    eventQueue);

                if (oldProperty is IndexerDeclarationSyntax oldIndexer)
                {
                    var newIndexer = (IndexerDeclarationSyntax)newProperty;
                    same &= CompareChildren(
                        CompareParameters,
                        oldIndexer.ParameterList.Parameters.AsReadOnlyList(),
                        newIndexer.ParameterList.Parameters.AsReadOnlyList(),
                        newIndexer,
                        CodeModelEventType.SigChange,
                        eventQueue);
                }

                return(same);
            }
 public string get_Prototype(int flags = 0)
 {
     return(CodeModelService.GetPrototype(null, LookupSymbol(), (PrototypeFlags)flags));
 }
            private bool CompareMethodDeclarations(
                BaseMethodDeclarationSyntax oldMethod,
                BaseMethodDeclarationSyntax newMethod,
                SyntaxNode newNodeParent,
                CodeModelEventQueue eventQueue)
            {
                Debug.Assert(oldMethod != null && newMethod != null);

                if (!StringComparer.Ordinal.Equals(CodeModelService.GetName(oldMethod), CodeModelService.GetName(newMethod)))
                {
                    var change = CompareRenamedDeclarations(
                        CompareParameters,
                        oldMethod.ParameterList.Parameters.AsReadOnlyList(),
                        newMethod.ParameterList.Parameters.AsReadOnlyList(),
                        oldMethod,
                        newMethod,
                        newNodeParent,
                        eventQueue);

                    if (change == DeclarationChange.NameOnly)
                    {
                        EnqueueChangeEvent(newMethod, newNodeParent, CodeModelEventType.Rename, eventQueue);
                    }

                    return(false);
                }
                else
                {
                    var same = true;

                    if (!CompareModifiers(oldMethod, newMethod))
                    {
                        same = false;
                        EnqueueChangeEvent(newMethod, newNodeParent, CodeModelEventType.Unknown, eventQueue);
                    }

                    if (!CompareTypes(GetReturnType(oldMethod), GetReturnType(newMethod)))
                    {
                        same = false;
                        EnqueueChangeEvent(newMethod, newNodeParent, CodeModelEventType.TypeRefChange, eventQueue);
                    }

                    same &= CompareChildren(
                        CompareAttributeLists,
                        oldMethod.AttributeLists.AsReadOnlyList(),
                        newMethod.AttributeLists.AsReadOnlyList(),
                        newMethod,
                        CodeModelEventType.Unknown,
                        eventQueue);

                    same &= CompareChildren(
                        CompareParameters,
                        oldMethod.ParameterList.Parameters.AsReadOnlyList(),
                        newMethod.ParameterList.Parameters.AsReadOnlyList(),
                        newMethod,
                        CodeModelEventType.SigChange,
                        eventQueue);

                    return(same);
                }
            }
 protected virtual EnvDTE.vsCMAccess GetAccess()
 {
     return(CodeModelService.GetAccess(LookupSymbol()));
 }
示例#27
0
        internal EnvDTE.CodeClass AddClass(SyntaxNode containerNode, string name, object position, object bases, object implementedInterfaces, EnvDTE.vsCMAccess access)
        {
            var containerNodePosition = containerNode.SpanStart;
            var semanticModel         = GetSemanticModel();

            var baseArray = GetValidArray(bases, allowMultipleElements: false);

            Debug.Assert(baseArray.Length == 0 || baseArray.Length == 1);

            var baseTypeSymbol = baseArray.Length == 1
                ? (INamedTypeSymbol)CodeModelService.GetTypeSymbol(baseArray[0], semanticModel, containerNodePosition)
                : null;

            var implementedInterfaceArray = GetValidArray(implementedInterfaces, allowMultipleElements: true);

            var implementedInterfaceSymbols = Array.ConvertAll(implementedInterfaceArray,
                                                               i => (INamedTypeSymbol)CodeModelService.GetTypeSymbol(i, semanticModel, containerNodePosition));

            var newType = CreateTypeDeclaration(
                containerNode,
                TypeKind.Class,
                CodeModelService.GetUnescapedName(name),
                access,
                baseType: baseTypeSymbol,
                implementedInterfaces: implementedInterfaceSymbols);

            var insertionIndex = CodeModelService.PositionVariantToMemberInsertionIndex(position, containerNode, fileCodeModel: this);

            newType = InsertMember(containerNode, newType, insertionIndex);

            return((EnvDTE.CodeClass)CreateInternalCodeMember(this.State, fileCodeModel: this, node: newType));
        }
示例#28
0
 private SyntaxNode GetNamespaceNode()
 {
     return(LookupNode().Ancestors()
            .Where(n => CodeModelService.IsNamespace(n))
            .FirstOrDefault());
 }
示例#29
0
 protected override string GetName()
 {
     return(CodeModelService.GetName(LookupNode()));
 }
示例#30
0
 private bool HasAccessorNode(MethodKind methodKind)
 => CodeModelService.TryGetAccessorNode(LookupNode(), methodKind, out _);