Пример #1
0
 private MemoizedMethodMemberArgument(IParameterSymbol parameterSymbol, bool partitionsCache)
 {
     PartitionsCache = partitionsCache;
     Name            = parameterSymbol.Name;
     ArgType         = parameterSymbol.ToDisplayString();
     IsNullable      = parameterSymbol.NullableAnnotation == NullableAnnotation.Annotated;
 }
Пример #2
0
        public static bool TryCreate
        (
            GeneratorContext context,
            Location errorLocation,
            IParameterSymbol parameterSymbol,
            [NotNullWhen(true)] out MemoizedMethodMemberArgument?arg
        )
        {
            var type = parameterSymbol.Type;

            if (!parameterSymbol.DeclaringSyntaxReferences.IsEmpty)
            {
                var syntaxReference = parameterSymbol.DeclaringSyntaxReferences.First();
                errorLocation = syntaxReference.SyntaxTree.GetLocation(syntaxReference.Span);
            }

            var attributes = parameterSymbol.GetAttributes();

            var partitionsCache = attributes.Any(x => SymbolEqualityComparer.Default.Equals(x.AttributeClass, context.PartitionCacheAttribute));

            if (TypeRequiresEquatable(type))
            {
                if (!type.AllInterfaces.Any(x => x.MetadataName == "IEquatable`1"))
                {
                    context.CreateError("Must implement IEquatable<>", $"Type {parameterSymbol.ToDisplayString()} must implement IEquatable<>", errorLocation);
                    arg = null;
                    return(false);
                }
            }

            arg = new MemoizedMethodMemberArgument(parameterSymbol, partitionsCache);
            return(true);
        }
        private static ArgumentSyntax AddParameterName(
            ArgumentSyntax argument,
            SemanticModel semanticModel,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (argument.NameColon == null || argument.NameColon.IsMissing)
            {
                IParameterSymbol parameterSymbol = CSharpAnalysis.DetermineParameter(
                    argument,
                    semanticModel,
                    allowParams: false,
                    cancellationToken: cancellationToken);

                if (parameterSymbol != null)
                {
                    return(argument
                           .WithNameColon(
                               NameColon(parameterSymbol.ToDisplayString(_symbolDisplayFormat))
                               .WithTrailingSpace())
                           .WithTriviaFrom(argument));
                }
            }

            return(argument);
        }
        private static async Task <Document> AddParameterNameAsync(
            Document document,
            ArgumentSyntax argument,
            IParameterSymbol parameterSymbol,
            CancellationToken cancellationToken)
        {
            SyntaxNode oldRoot = await document.GetSyntaxRootAsync(cancellationToken);

            ArgumentSyntax newNode = argument
                                     .WithNameColon(NameColon(parameterSymbol.ToDisplayString(_symbolDisplayFormat)))
                                     .WithTriviaFrom(argument)
                                     .WithAdditionalAnnotations(Formatter.Annotation);

            SyntaxNode newRoot = oldRoot.ReplaceNode(argument, newNode);

            return(document.WithSyntaxRoot(newRoot));
        }
Пример #5
0
        public static void ReportSignalParameterTypeNotSupported(
            GeneratorExecutionContext context,
            IParameterSymbol parameterSymbol)
        {
            var locations = parameterSymbol.Locations;
            var location  = locations.FirstOrDefault(l => l.SourceTree != null) ?? locations.FirstOrDefault();

            string message = "The parameter of the delegate signature of the signal " +
                             $"is not supported: '{parameterSymbol.ToDisplayString()}'";

            string description = $"{message}. Use supported types only or remove the '[Signal]' attribute.";

            context.ReportDiagnostic(Diagnostic.Create(
                                         new DiagnosticDescriptor(id: "GD0202",
                                                                  title: message,
                                                                  messageFormat: message,
                                                                  category: "Usage",
                                                                  DiagnosticSeverity.Error,
                                                                  isEnabledByDefault: true,
                                                                  description),
                                         location,
                                         location?.SourceTree?.FilePath));
        }
Пример #6
0
        private static ArgumentSyntax AddParameterName(
            ArgumentSyntax argument,
            SemanticModel semanticModel,
            CancellationToken cancellationToken = default)
        {
            if (argument.NameColon?.IsMissing != false)
            {
                IParameterSymbol parameterSymbol = semanticModel.DetermineParameter(
                    argument,
                    allowParams: false,
                    cancellationToken: cancellationToken);

                if (parameterSymbol != null)
                {
                    return(argument
                           .WithNameColon(
                               NameColon(parameterSymbol.ToDisplayString(_symbolDisplayFormat))
                               .WithTrailingTrivia(Space))
                           .WithTriviaFrom(argument));
                }
            }

            return(argument);
        }
        public static ArgumentSyntax AddParameterName(
            ArgumentSyntax argument,
            SemanticModel semanticModel,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (argument == null)
            {
                throw new ArgumentNullException(nameof(argument));
            }

            if (semanticModel == null)
            {
                throw new ArgumentNullException(nameof(semanticModel));
            }

            if (argument.NameColon != null && !argument.NameColon.IsMissing)
            {
                return(argument);
            }

            IParameterSymbol parameterSymbol = argument.DetermineParameter(
                semanticModel,
                allowParams: false,
                cancellationToken: cancellationToken);

            if (parameterSymbol == null)
            {
                return(argument);
            }

            return(argument
                   .WithNameColon(
                       NameColon(parameterSymbol.ToDisplayString(_symbolDisplayFormat))
                       .WithTrailingTrivia(Space))
                   .WithTriviaFrom(argument));
        }
Пример #8
0
        }                                    // Optional; unused for now

        public ParameterViewModel(IParameterSymbol parameter, string documentation = null)
        {
            Documentation = documentation;

            Label = parameter.ToDisplayString(Constants.SymbolDisplayFormat);
        }