public static async Task <Document> RefactorAsync( Document document, AttributeArgumentListSyntax attributeArgumentList, CancellationToken cancellationToken) { return(await document.RemoveNodeAsync(attributeArgumentList, SyntaxRemoveOptions.KeepNoTrivia, cancellationToken).ConfigureAwait(false)); }
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)); }); } }
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); }
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); }
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())); } }
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; }
public static ImmutableArray <ParameterName> GenerateParameterNames( this SemanticModel semanticModel, AttributeArgumentListSyntax argumentList, CancellationToken cancellationToken) { return(semanticModel.GenerateParameterNames( argumentList.Arguments, reservedNames: null, cancellationToken: cancellationToken)); }
public MacroExpander(AttributeArgumentListSyntax attrs) { prefix = postfix = null; text = ""; foreach (var argument in attrs.ToArguments()) { switch (argument.Name, argument.Value) {
internal static SignatureHelpState GetSignatureHelpState(AttributeArgumentListSyntax argumentList, int position) { return(CommonSignatureHelpUtilities.GetSignatureHelpState( argumentList, position, s_getAttributeArgumentListOpenToken, s_getAttributeArgumentListCloseToken, s_getAttributeArgumentListArgumentsWithSeparators, s_getAttributeArgumentListNames)); }
public static Task <Document> ToMultiLineAsync( Document document, AttributeArgumentListSyntax argumentList, CancellationToken cancellationToken = default(CancellationToken)) { AttributeArgumentListSyntax newNode = ToMultiLine(argumentList, cancellationToken); return(document.ReplaceNodeAsync(argumentList, newNode, cancellationToken)); }
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); }
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()); }
public override Evaluation VisitAttributeArgumentList(AttributeArgumentListSyntax node) { EvaluationList list = new EvaluationList(); foreach (AttributeArgumentSyntax argument in node.Arguments) { list.Add(argument.Accept <Evaluation>(this)); } return(list); }
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); }
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)); }
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() }); }
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)))); }
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)); } }
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); }
/// <summary> /// /// </summary> /// <param name="node"></param> public override sealed void VisitAttributeArgumentList(AttributeArgumentListSyntax node) { this.OnNodeVisited(node); if (!this.traverseRootOnly) base.VisitAttributeArgumentList(node); }
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; }
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); }
public static string AttributeArgumentList(AttributeArgumentListSyntax list) { return "(" + string.Join(", ", list.Arguments.Select(SyntaxNode)) + ")"; }
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())); } }
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; }