public static async Task <Document> RefactorAsync(
     Document document,
     AttributeArgumentListSyntax attributeArgumentList,
     CancellationToken cancellationToken)
 {
     return(await document.RemoveNodeAsync(attributeArgumentList, SyntaxRemoveOptions.KeepNoTrivia, cancellationToken).ConfigureAwait(false));
 }
示例#2
0
        private static async Task AddOrRemoveParameterNameAsync(
            RefactoringContext context,
            AttributeArgumentListSyntax argumentList,
            AttributeArgumentSyntax[] arguments)
        {
            if (context.IsRefactoringEnabled(RefactoringIdentifiers.AddParameterNameToArgument) &&
                await CanAddParameterNameAsync(context, arguments).ConfigureAwait(false))
            {
                context.RegisterRefactoring(
                    "Add parameter name",
                    cancellationToken =>
                {
                    return(AddParameterNameToArgumentsAsync(
                               context.Document,
                               argumentList,
                               arguments,
                               cancellationToken));
                });
            }

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.RemoveParameterNameFromArgument) &&
                arguments.Any(f => f.NameColon != null))
            {
                context.RegisterRefactoring(
                    "Remove parameter name",
                    cancellationToken =>
                {
                    return(RemoveParameterNameFromArgumentsAsync(
                               context.Document,
                               argumentList,
                               arguments,
                               cancellationToken));
                });
            }
        }
示例#3
0
        private AttributeArgumentListSyntax ParseUnityShaderPropertyAttributeArgumentList()
        {
            AttributeArgumentListSyntax result = null;

            if (Current.Kind == SyntaxKind.OpenParenToken)
            {
                var openParen = Match(SyntaxKind.OpenParenToken);

                var argumentsList = new List <SyntaxNodeBase>();
                argumentsList.Add(ParseUnityExpression());

                while (Current.Kind == SyntaxKind.CommaToken)
                {
                    argumentsList.Add(Match(SyntaxKind.CommaToken));
                    argumentsList.Add(ParseUnityExpression());
                }

                var closeParen = Match(SyntaxKind.CloseParenToken);

                result = new AttributeArgumentListSyntax(
                    openParen,
                    new SeparatedSyntaxList <LiteralExpressionSyntax>(argumentsList),
                    closeParen);
            }

            return(result);
        }
示例#4
0
 public static AttributeArgumentListSyntax VisitNode(
     AttributeArgumentListSyntax argumentList,
     AttributeArgumentSyntax[] arguments,
     SemanticModel semanticModel)
 {
     return((AttributeArgumentListSyntax) new AddParameterNameSyntaxRewriter(arguments, semanticModel).Visit(argumentList));
 }
            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);
            }
        public IEnumerable <DiagnosticInfo> GetDiagnosticInfo(SyntaxNodeAnalysisContext context)
        {
            var result = new List <DiagnosticInfo>();
            var method = context.Node as MethodDeclarationSyntax;

            foreach (AttributeListSyntax attributeList in method.AttributeLists)
            {
                foreach (AttributeSyntax attribute in attributeList.Attributes)
                {
                    if (string.Compare(attribute.Name?.ToString(), "ValidateInput") != 0)
                    {
                        continue;
                    }

                    //Verify the namespace before proceeding
                    var symbol = context.SemanticModel.GetSymbolInfo(attribute).Symbol as ISymbol;
                    if (string.Compare(symbol?.ContainingNamespace.ToString(), "System.Web.Mvc", StringComparison.Ordinal) != 0)
                    {
                        continue;
                    }

                    AttributeArgumentListSyntax argumentList = attribute.ArgumentList;
                    AttributeArgumentSyntax     argument     = argumentList.Arguments.First();
                    var value = context.SemanticModel.GetConstantValue(argument?.Expression);

                    if (value.HasValue && (bool)value.Value == false)
                    {
                        result.Add(new DiagnosticInfo(attribute.GetLocation()));
                    }
                }
            }

            return(result);
        }
        private async Task <Document> AddTestCategory(Document document, MethodDeclarationSyntax method, CancellationToken cancellationToken)
        {
            SyntaxList <AttributeListSyntax> attributeLists = method.AttributeLists;

            foreach (AttributeListSyntax attributes in attributeLists)
            {
                foreach (AttributeSyntax attributesyntax in attributes.Attributes)
                {
                    if (attributesyntax.Name.ToString().Contains(@"TestCategory"))
                    {
                        return(document);
                    }
                }
            }

            SyntaxNode rootNode = await document.GetSyntaxRootAsync(cancellationToken);

            NameSyntax name = SyntaxFactory.ParseName("TestCategory");
            AttributeArgumentListSyntax arguments = SyntaxFactory.ParseAttributeArgumentList("(TestDefinitions.UnitTests)");
            AttributeSyntax             attribute = SyntaxFactory.Attribute(name, arguments);

            AttributeListSyntax attributeList = SyntaxFactory.AttributeList(
                SyntaxFactory.SingletonSeparatedList <AttributeSyntax>(attribute));

            MethodDeclarationSyntax newMethod = method.WithAttributeLists(method.AttributeLists.Add(attributeList));

            SyntaxNode newRoot     = rootNode.ReplaceNode(method, newMethod);
            Document   newDocument = document.WithSyntaxRoot(newRoot);

            return(newDocument);
        }
示例#8
0
        private static void AnalyzeArgumentList(SyntaxNodeAnalysisContext context, AttributeArgumentListSyntax argumentListSyntax)
        {
            if (argumentListSyntax == null ||
                argumentListSyntax.OpenParenToken.IsMissing ||
                argumentListSyntax.IsMissing ||
                !argumentListSyntax.Arguments.Any())
            {
                return;
            }

            var firstArgument = argumentListSyntax.Arguments[0];

            var firstArgumentLineSpan = firstArgument.GetLocation().GetLineSpan();

            if (!firstArgumentLineSpan.IsValid)
            {
                return;
            }

            var openParenLineSpan = argumentListSyntax.OpenParenToken.GetLocation().GetLineSpan();

            if (!openParenLineSpan.IsValid)
            {
                return;
            }

            if (openParenLineSpan.EndLinePosition.Line != firstArgumentLineSpan.StartLinePosition.Line &&
                openParenLineSpan.EndLinePosition.Line != (firstArgumentLineSpan.StartLinePosition.Line - 1))
            {
                context.ReportDiagnostic(Diagnostic.Create(Descriptor, firstArgument.GetLocation()));
            }
        }
示例#9
0
        private static AttributeArgumentListSyntax ToMultiLine(AttributeArgumentListSyntax argumentList, CancellationToken cancellationToken = default(CancellationToken))
        {
            string indent = GetIncreasedLineIndent(argumentList.Parent, cancellationToken);

            SyntaxTriviaList leadingTrivia = ParseLeadingTrivia(indent);

            var nodesAndTokens = new List <SyntaxNodeOrToken>();

            SeparatedSyntaxList <AttributeArgumentSyntax> .Enumerator en = argumentList.Arguments.GetEnumerator();

            if (en.MoveNext())
            {
                nodesAndTokens.Add(en.Current
                                   .TrimTrailingTrivia()
                                   .WithLeadingTrivia(leadingTrivia));

                while (en.MoveNext())
                {
                    nodesAndTokens.Add(CommaToken().WithTrailingTrivia(NewLine()));

                    nodesAndTokens.Add(en.Current
                                       .TrimTrailingTrivia()
                                       .WithLeadingTrivia(leadingTrivia));
                }
            }

            return(AttributeArgumentList(
                       OpenParenToken().WithTrailingTrivia(NewLine()),
                       SeparatedList <AttributeArgumentSyntax>(nodesAndTokens),
                       argumentList.CloseParenToken.WithoutLeadingTrivia()));
        }
 public static AttributeSyntax Update(this AttributeSyntax originalAttribute,
                                      NameSyntax name = null,
                                      AttributeArgumentListSyntax argumentList = null)
 {
     return(originalAttribute.Update(
                name ?? originalAttribute.Name,
                argumentList ?? originalAttribute.ArgumentList));
 }
 public override void AddChildren()
 {
     Kind                   = Node.Kind();
     _name                  = ((AttributeSyntax)Node).Name;
     _nameIsChanged         = false;
     _argumentList          = ((AttributeSyntax)Node).ArgumentList;
     _argumentListIsChanged = false;
 }
示例#12
0
 public static ImmutableArray <ParameterName> GenerateParameterNames(
     this SemanticModel semanticModel,
     AttributeArgumentListSyntax argumentList,
     CancellationToken cancellationToken)
 {
     return(semanticModel.GenerateParameterNames(
                argumentList.Arguments, reservedNames: null, cancellationToken: cancellationToken));
 }
示例#13
0
 public MacroExpander(AttributeArgumentListSyntax attrs)
 {
     prefix = postfix = null;
     text   = "";
     foreach (var argument in attrs.ToArguments())
     {
         switch (argument.Name, argument.Value)
         {
示例#14
0
 internal static SignatureHelpState GetSignatureHelpState(AttributeArgumentListSyntax argumentList, int position)
 {
     return(CommonSignatureHelpUtilities.GetSignatureHelpState(
                argumentList, position,
                s_getAttributeArgumentListOpenToken,
                s_getAttributeArgumentListCloseToken,
                s_getAttributeArgumentListArgumentsWithSeparators,
                s_getAttributeArgumentListNames));
 }
示例#15
0
        public static Task <Document> ToMultiLineAsync(
            Document document,
            AttributeArgumentListSyntax argumentList,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            AttributeArgumentListSyntax newNode = ToMultiLine(argumentList, cancellationToken);

            return(document.ReplaceNodeAsync(argumentList, newNode, cancellationToken));
        }
示例#16
0
        public override void VisitAttributeArgumentList(AttributeArgumentListSyntax node)
        {
            foreach (AttributeArgumentSyntax argument in node.Arguments)
            {
                argument.Accept(this);
            }

            base.VisitAttributeArgumentList(node);
        }
 internal static SignatureHelpState GetSignatureHelpState(AttributeArgumentListSyntax argumentList, int position)
 {
     return CommonSignatureHelpUtilities.GetSignatureHelpState(
         argumentList, position,
         s_getAttributeArgumentListOpenToken,
         s_getAttributeArgumentListCloseToken,
         s_getAttributeArgumentListArgumentsWithSeparators,
         s_getAttributeArgumentListNames);
 }
示例#18
0
        private static AttributeArgumentSyntax FindByPosition(AttributeArgumentListSyntax arguments, int position)
        {
            if (arguments?.Arguments.Count > position)
            {
                return(arguments.Arguments[0]);
            }

            return(null);
        }
        private async Task <Document> AddDateMemberAttributesAndFixOrder(Document document, PropertyDeclarationSyntax[] publicProperties, PropertyDeclarationSyntax[] propertiesWithDataMemberAttributeWithoutOrder, PropertyDeclarationSyntax[] propertiesWithDataMemberAttributeWithOrder, CancellationToken cancellationToken)
        {
            var root = await document.GetSyntaxRootAsync(cancellationToken);

            int max = 0;

            if (propertiesWithDataMemberAttributeWithOrder.Any())
            {
                max = propertiesWithDataMemberAttributeWithOrder.Max(p => GetOrder(GetDataMemberAttribute(p)) ?? 0);
            }

            var updateNodes = new Dictionary <SyntaxNode, SyntaxNode>();

            foreach (var property in propertiesWithDataMemberAttributeWithoutOrder)
            {
                var attribute = GetDataMemberAttribute(property); //DataMember
                AttributeArgumentListSyntax arguments = CreateOrderArgument(++max);
                var args = attribute.ArgumentList?.Arguments.ToArray();
                AttributeArgumentListSyntax allArgs = arguments;
                if (args != null)
                {
                    allArgs = arguments.AddArguments(args);
                }
                var newAttribute = attribute.WithArgumentList(allArgs); //DataMember(Order = #)
                updateNodes.Add(attribute, newAttribute);
            }
            foreach (var property in publicProperties.Except(propertiesWithDataMemberAttributeWithoutOrder.Union(propertiesWithDataMemberAttributeWithOrder)))
            {
                var name = SyntaxFactory.ParseName(DataMember);
                AttributeArgumentListSyntax arguments = CreateOrderArgument(++max);
                var attribute = SyntaxFactory.Attribute(name, arguments); //DataMember(Order = #)

                var attributeList = new SeparatedSyntaxList <AttributeSyntax>();
                attributeList = attributeList.Add(attribute);
                var list     = SyntaxFactory.AttributeList(attributeList); //[DataMember(Order = #)]
                var modifier = property.Modifiers.FirstOrDefault();

                if (modifier != null)
                {
                    var commentsT = modifier.LeadingTrivia;

                    list = list.WithLeadingTrivia(commentsT);
                }


                var newModifiers = SyntaxFactory.TokenList(property.Modifiers.Skip(1).Concat(new[] { SyntaxFactory.Token(SyntaxKind.PublicKeyword) }));;
                var newProperty  = property.AddAttributeLists(list).WithModifiers(newModifiers);

                updateNodes.Add(property, newProperty);
            }
            root = root.ReplaceNodes(updateNodes.Keys, (n1, n2) =>
            {
                return(updateNodes[n1]);
            });
            return(document.WithSyntaxRoot(root));
        }
        private void AnalyzeAttributeSyntax(
            SyntaxNodeAnalysisContext context,
            AttributeSyntax attributeSyntax,
            INamedTypeSymbol serializerAttributeType,
            ImmutableArray <INamedTypeSymbol> serializerInterfaceTypes
            )
        {
            SemanticModel model = context.SemanticModel;

            if (!model.IsAttributeOfType(attributeSyntax, serializerAttributeType))
            {
                return;
            }

            AttributeArgumentListSyntax argumentList = attributeSyntax.ArgumentList;

            if (argumentList == null)
            {
                return;
            }

            SeparatedSyntaxList <AttributeArgumentSyntax> arguments = argumentList.Arguments;

            if (arguments.Count == 0)
            {
                return;
            }

            AttributeArgumentSyntax typeArgumentSyntax = arguments[0];

            if (!(typeArgumentSyntax.Expression is TypeOfExpressionSyntax typeofSyntax))
            {
                ReportInvalidSerializerType(
                    context,
                    typeArgumentSyntax,
                    messageArg: typeArgumentSyntax.Expression.ToString()
                    );
                return;
            }

            ITypeSymbol serializerType = model.GetTypeInfo(typeofSyntax.Type).Type;

            if (DoesImplementOneOfSerializerInterfaces(
                    serializerType,
                    serializerInterfaceTypes
                    ))
            {
                return;
            }

            ReportInvalidSerializerType(
                context,
                typeArgumentSyntax,
                messageArg: serializerType.ToDisplayString(TypeDisplayFormat)
                );
        }
        private List <Image> GetImages(AttributeArgumentListSyntax argumentList)
        {
            var list = new List <Image>();

            list.Add(GetImage(argumentList, 1));
            list.Add(GetImage(argumentList, 2));
            list.Add(GetImage(argumentList, 3));
            list.Add(GetImage(argumentList, 4));
            return(list.Where(x => x.ImageAttributes != "" && x.ImageAttributes != null).ToList());
        }
示例#22
0
        public override Evaluation VisitAttributeArgumentList(AttributeArgumentListSyntax node)
        {
            EvaluationList list = new EvaluationList();

            foreach (AttributeArgumentSyntax argument in node.Arguments)
            {
                list.Add(argument.Accept <Evaluation>(this));
            }

            return(list);
        }
示例#23
0
        public override void VisitAttributeArgumentList(AttributeArgumentListSyntax node)
        {
            var index = 0;

            foreach (var attrArg in node.Arguments)
            {
                var visitor = new AttributeArgumentWalker(this.ShowAst);
                visitor.Visit(attrArg);
                AddParameter(visitor.Name, visitor.Value, index++);
            }
        }
        private SeparatedSyntaxList <AttributeSyntax> CreateAttribute(SeparatedSyntaxList <AttributeArgumentSyntax> arguments)
        {
            AttributeArgumentListSyntax newArguments = SyntaxFactory.AttributeArgumentList(SyntaxFactory.Token(SyntaxKind.OpenParenToken),
                                                                                           arguments, SyntaxFactory.Token(SyntaxKind.CloseParenToken));
            SeparatedSyntaxList <AttributeSyntax> attributeWhole = new SeparatedSyntaxList <AttributeSyntax>();

            attributeWhole = attributeWhole.Add(
                SyntaxFactory.Attribute(SyntaxFactory.ParseName(AttributeName), newArguments));

            return(attributeWhole);
        }
示例#25
0
        private static Task <Document> RemoveParameterNameFromArgumentsAsync(
            Document document,
            AttributeArgumentListSyntax argumentList,
            AttributeArgumentSyntax[] arguments,
            CancellationToken cancellationToken = default)
        {
            AttributeArgumentListSyntax newArgumentList = RemoveParameterNameSyntaxRewriter.VisitNode(argumentList, arguments)
                                                          .WithFormatterAnnotation();

            return(document.ReplaceNodeAsync(argumentList, newArgumentList, cancellationToken));
        }
示例#26
0
        private static AttributeArgumentListSyntax CreateMultilineList(AttributeArgumentListSyntax argumentList)
        {
            SeparatedSyntaxList <AttributeArgumentSyntax> arguments = SeparatedList <AttributeArgumentSyntax>(CreateMultilineNodesAndTokens(argumentList));

            SyntaxToken openParen = Token(SyntaxKind.OpenParenToken)
                                    .WithTrailingNewLine();

            return(AttributeArgumentList(arguments)
                   .WithOpenParenToken(openParen)
                   .WithCloseParenToken(argumentList.CloseParenToken.WithoutLeadingTrivia()));
        }
        public static void ComputeRefactoring(RefactoringContext context, AttributeArgumentListSyntax argumentList)
        {
            AttributeArgumentSyntax argument = GetArgument(context, argumentList);

            if (argument != null)
            {
                context.RegisterRefactoring(
                    "Duplicate argument",
                    cancellationToken => RefactorAsync(context.Document, argument, cancellationToken));
            }
        }
        private Image GetImage(AttributeArgumentListSyntax argumentList, int index)
        {
            var argumentImageType       = argumentList.Arguments.ToList().FirstOrDefault(x => x?.NameEquals?.Name?.Identifier.ValueText == $"Image{index}Type");
            var argumentImageAttributes = argumentList.Arguments.ToList().FirstOrDefault(x => x?.NameEquals?.Name?.Identifier.ValueText == $"Image{index}Attributes");

            return(new Image
            {
                ImageAttributes = AnalyzerHelper.RemoveQuote(argumentImageAttributes?.Expression?.NormalizeWhitespace()?.ToFullString()),
                ImageType = argumentImageType?.Expression?.NormalizeWhitespace()?.ToFullString(),
                Location = argumentImageType?.GetLocation()
            });
        }
示例#29
0
        public static AttributeListSyntax Create(string attributeName, AttributeArgumentListSyntax attributeArgumentList)
        {
            if (attributeName == null)
            {
                throw new ArgumentNullException(nameof(attributeName));
            }

            return(SyntaxFactory.AttributeList(
                       SyntaxFactory.SingletonSeparatedList(
                           SyntaxAttributeFactory.Create(attributeName)
                           .WithArgumentList(attributeArgumentList))));
        }
示例#30
0
 public static AttributeArgumentListSyntax VisitNode(AttributeArgumentListSyntax argumentList, AttributeArgumentSyntax[] arguments = null)
 {
     if (arguments == null)
     {
         return((AttributeArgumentListSyntax)_instance.Visit(argumentList));
     }
     else
     {
         var instance = new RemoveParameterNameSyntaxRewriter(arguments);
         return((AttributeArgumentListSyntax)instance.Visit(argumentList));
     }
 }
示例#31
0
        private static void HandleAttributeArgumentList(SyntaxNodeAnalysisContext context)
        {
            AttributeArgumentListSyntax syntax = (AttributeArgumentListSyntax)context.Node;

            if (syntax.Arguments.Count != 0)
            {
                return;
            }

            // Attribute constructor should not use unnecessary parenthesis
            context.ReportDiagnostic(Diagnostic.Create(Descriptor, syntax.GetLocation()));
        }
		public static IList<string> GenerateParameterNames(
			this SemanticModel semanticModel,
			AttributeArgumentListSyntax argumentList)
		{
			return semanticModel.GenerateParameterNames(argumentList.Arguments);
		}
示例#33
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="node"></param>
 public override sealed void VisitAttributeArgumentList(AttributeArgumentListSyntax node)
 {
     this.OnNodeVisited(node);
     if (!this.traverseRootOnly) base.VisitAttributeArgumentList(node);
 }
示例#34
0
        private AnalyzedAttributeArguments BindAttributeArguments(AttributeArgumentListSyntax attributeArgumentList, NamedTypeSymbol attributeType, DiagnosticBag diagnostics)
        {
            var boundConstructorArguments = AnalyzedArguments.GetInstance();
            var boundNamedArguments = ImmutableArray<BoundExpression>.Empty;
            if (attributeArgumentList != null)
            {
                ArrayBuilder<BoundExpression> boundNamedArgumentsBuilder = null;
                HashSet<string> boundNamedArgumentsSet = null;

                // Avoid "cascading" errors for constructor arguments.
                // We will still generate errors for each duplicate named attribute argument,
                // matching Dev10 compiler behavior.
                bool hadError = false;

                foreach (var argument in attributeArgumentList.Arguments)
                {
                    if (argument.NameEquals == null)
                    {
                        // Constructor argument
                        hadError |= this.BindArgumentAndName(
                            boundConstructorArguments,
                            diagnostics,
                            hadError,
                            argument,
                            argument.Expression,
                            argument.NameColon,
                            refKind: RefKind.None,
                            allowArglist: false);

                        if (boundNamedArgumentsBuilder != null)
                        {
                            // Error CS1016: Named attribute argument expected
                            // This has been reported by the parser.
                            hadError = true;
                        }
                    }
                    else
                    {
                        // Named argument
                        // TODO: use fully qualified identifier name for boundNamedArgumentsSet
                        string argumentName = argument.NameEquals.Name.Identifier.ValueText;
                        if (boundNamedArgumentsBuilder == null)
                        {
                            boundNamedArgumentsBuilder = ArrayBuilder<BoundExpression>.GetInstance();
                            boundNamedArgumentsSet = new HashSet<string>();
                        }
                        else if (boundNamedArgumentsSet.Contains(argumentName))
                        {
                            // Duplicate named argument
                            Error(diagnostics, ErrorCode.ERR_DuplicateNamedAttributeArgument, argument, argumentName);
                            hadError = true;
                        }

                        BoundExpression boundNamedArgument = BindNamedAttributeArgument(argument, attributeType, diagnostics);
                        boundNamedArgumentsBuilder.Add(boundNamedArgument);
                        boundNamedArgumentsSet.Add(argumentName);
                    }
                }

                if (boundNamedArgumentsBuilder != null)
                {
                    boundNamedArguments = boundNamedArgumentsBuilder.ToImmutableAndFree();
                }
            }

            return new AnalyzedAttributeArguments(boundConstructorArguments, boundNamedArguments);
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="node"></param>
 public override sealed void VisitAttributeArgumentList(AttributeArgumentListSyntax node)
 {
     this.OnNodeVisited(node, this.type.IsInstanceOfType(node));
     base.VisitAttributeArgumentList(node);
 }
            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 (int 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;
            }
示例#37
0
        public void VisitAttributeArgumentList(AttributeArgumentListSyntax node)
        {
            if (node == null)
                throw new ArgumentNullException("node");

            node.Validate();

            _writer.WriteSyntax(Syntax.OpenParen);

            bool hadOne = false;

            foreach (var argument in node.Arguments)
            {
                if (hadOne)
                    _writer.WriteListSeparator();
                else
                    hadOne = true;

                argument.Accept(this);
            }

            _writer.WriteSyntax(Syntax.CloseParen);
        }
 internal static TextSpan GetSignatureHelpSpan(AttributeArgumentListSyntax argumentList)
 {
     return CommonSignatureHelpUtilities.GetSignatureHelpSpan(argumentList, s_getAttributeArgumentListCloseToken);
 }
示例#39
0
 public static string AttributeArgumentList(AttributeArgumentListSyntax list)
 {
     return "(" + string.Join(", ", list.Arguments.Select(SyntaxNode)) + ")";
 }
示例#40
0
        private AttributeArgumentListSyntax ParseUnityShaderPropertyAttributeArgumentList()
        {
            AttributeArgumentListSyntax result = null;

            if (Current.Kind == SyntaxKind.OpenParenToken)
            {
                var openParen = Match(SyntaxKind.OpenParenToken);

                var argumentsList = new List<SyntaxNode>();
                argumentsList.Add(ParseUnityExpression());

                while (Current.Kind == SyntaxKind.CommaToken)
                {
                    argumentsList.Add(Match(SyntaxKind.CommaToken));
                    argumentsList.Add(ParseUnityExpression());
                }

                var closeParen = Match(SyntaxKind.CloseParenToken);

                result = new AttributeArgumentListSyntax(
                    openParen,
                    new SeparatedSyntaxList<LiteralExpressionSyntax>(argumentsList),
                    closeParen);
            }

            return result;
        }
        private ISet<string> GetExistingNamedParameters(AttributeArgumentListSyntax argumentList, int position)
        {
            var existingArguments1 =
                argumentList.Arguments.Where(a => a.Span.End <= position)
                                      .Where(a => a.NameColon != null)
                                      .Select(a => a.NameColon.Name.Identifier.ValueText);
            var existingArguments2 =
                argumentList.Arguments.Where(a => a.Span.End <= position)
                                      .Where(a => a.NameEquals != null)
                                      .Select(a => a.NameEquals.Name.Identifier.ValueText);

            return existingArguments1.Concat(existingArguments2).ToSet();
        }
        private static void AnalyzeArgumentList(SyntaxNodeAnalysisContext context, AttributeArgumentListSyntax argumentListSyntax)
        {
            if (argumentListSyntax == null ||
                argumentListSyntax.OpenParenToken.IsMissing ||
                argumentListSyntax.IsMissing ||
                !argumentListSyntax.Arguments.Any())
            {
                return;
            }

            var firstArgument = argumentListSyntax.Arguments[0];
            if (firstArgument.GetLeadingTrivia().Any(SyntaxKind.PragmaWarningDirectiveTrivia))
            {
                return;
            }

            var firstArgumentLineSpan = firstArgument.GetLineSpan();
            if (!firstArgumentLineSpan.IsValid)
            {
                return;
            }

            var openParenLineSpan = argumentListSyntax.OpenParenToken.GetLineSpan();
            if (!openParenLineSpan.IsValid)
            {
                return;
            }

            if (openParenLineSpan.EndLinePosition.Line != firstArgumentLineSpan.StartLinePosition.Line &&
                openParenLineSpan.EndLinePosition.Line != (firstArgumentLineSpan.StartLinePosition.Line - 1))
            {
                context.ReportDiagnostic(Diagnostic.Create(Descriptor, firstArgument.GetLocation()));
            }
        }
示例#43
0
 public virtual void VisitAttributeArgumentList(AttributeArgumentListSyntax node)
 {
     DefaultVisit(node);
 }
            private IEnumerable<ITypeSymbol> InferTypeInAttributeArgumentList(AttributeArgumentListSyntax attributeArgumentList, SyntaxToken previousToken)
            {
                // Has to follow the ( or a ,
                if (previousToken != attributeArgumentList.OpenParenToken && previousToken.CSharpKind() != SyntaxKind.CommaToken)
                {
                    return SpecializedCollections.EmptyEnumerable<ITypeSymbol>();
                }

                var attribute = attributeArgumentList.Parent as AttributeSyntax;
                if (attribute != null)
                {
                    var index = this.GetArgumentListIndex(attributeArgumentList, previousToken);
                    return InferTypeInAttribute(attribute, index);
                }

                return SpecializedCollections.EmptyEnumerable<ITypeSymbol>();
            }
            private int GetArgumentListIndex(AttributeArgumentListSyntax attributeArgumentList, SyntaxToken previousToken)
            {
                if (previousToken == attributeArgumentList.OpenParenToken)
                {
                    return 0;
                }

                ////    ( node0 , node1 , node2 , node3 ,
                //
                // Tokidx   0   1   2   3   4   5   6   7
                //
                // index        1       2       3
                //
                // index = (Tokidx + 1) / 2

                var tokenIndex = attributeArgumentList.Arguments.GetWithSeparators().IndexOf(previousToken);
                return (tokenIndex + 1) / 2;
            }