Example #1
0
            /// <inheritdoc cref="DefaultParamDelegateAnalyzer.WithDiagnostics.Analyze(IDiagnosticReceiver, INamedTypeSymbol, DefaultParamCompilationData, CancellationToken)"/>
            public static bool Analyze(
                IDiagnosticReceiver diagnosticReceiver,
                INamedTypeSymbol symbol,
                DefaultParamCompilationData compilation,
                CancellationToken cancellationToken = default
                )
            {
                TypeParameterContainer typeParameters = TypeParameterContainer.CreateFrom(symbol, compilation, cancellationToken);

                if (!typeParameters.HasDefaultParams)
                {
                    return(false);
                }

                ImmutableArray <AttributeData> attributes = symbol.GetAttributes();

                INamedTypeSymbol[] containingTypes = symbol.GetContainingTypeSymbols().ToArray();

                bool isValid = AnalyzeAgainstProhibitedAttributes(diagnosticReceiver, symbol, compilation, attributes);

                isValid &= AnalyzeContainingTypes(diagnosticReceiver, symbol, compilation, containingTypes, cancellationToken);
                isValid &= AnalyzeAgainstPartial(diagnosticReceiver, symbol, cancellationToken);
                isValid &= AnalyzeTypeParameters(diagnosticReceiver, symbol, in typeParameters);

                if (isValid)
                {
                    string targetNamespace = GetTargetNamespace(symbol, compilation, attributes, containingTypes);

                    isValid &= AnalyzeCollidingMembers(diagnosticReceiver, symbol, in typeParameters, compilation, targetNamespace, out _, attributes, containingTypes, cancellationToken);
                }

                ShouldInheritInsteadOfCopying(diagnosticReceiver, symbol, compilation, attributes, containingTypes);

                return(isValid);
            }
            /// <summary>
            /// Fully analyzes the specified <paramref name="symbol"/>.
            /// </summary>
            /// <param name="diagnosticReceiver">
            /// <see cref="IDiagnosticReceiver"/> that is used to report <see cref="Diagnostic"/> s.
            /// </param>
            /// <param name="symbol"><see cref="INamedTypeSymbol"/> to analyze.</param>
            /// <param name="compilation">Current <see cref="DefaultParamCompilationData"/>.</param>
            /// <param name="cancellationToken">
            /// <see cref="CancellationToken"/> that specifies if the operation should be canceled.
            /// </param>
            /// <returns>
            /// <see langword="true"/> if the <paramref name="symbol"/> is valid, otherwise <see langword="false"/>.
            /// </returns>
            public static bool Analyze(
                IDiagnosticReceiver diagnosticReceiver,
                INamedTypeSymbol symbol,
                DefaultParamCompilationData compilation,
                CancellationToken cancellationToken = default
                )
            {
                TypeParameterContainer typeParameters = TypeParameterContainer.CreateFrom(symbol, compilation, cancellationToken);

                if (!typeParameters.HasDefaultParams)
                {
                    return(false);
                }

                bool isValid = AnalyzeAgainstProhibitedAttributes(diagnosticReceiver, symbol, compilation, out AttributeData[]? attributes);

                isValid &= AnalyzeContainingTypes(diagnosticReceiver, symbol, compilation, out INamedTypeSymbol[]? containingTypes, cancellationToken);
                isValid &= AnalyzeTypeParameters(diagnosticReceiver, symbol, in typeParameters);

                if (isValid)
                {
                    string targetNamespace = GetTargetNamespace(symbol, compilation, attributes !, containingTypes !);

                    return(AnalyzeCollidingMembers(diagnosticReceiver, symbol, in typeParameters, compilation, targetNamespace, out _, attributes !, containingTypes !, cancellationToken));
                }

                return(false);
            }
Example #3
0
        /// <summary>
        /// Fully analyzes the specified <paramref name="symbol"/>.
        /// </summary>
        /// <param name="symbol"><see cref="INamedTypeSymbol"/> to analyze.</param>
        /// <param name="compilation">Current <see cref="DefaultParamCompilationData"/>.</param>
        /// <param name="cancellationToken"><see cref="CancellationToken"/> that specifies if the operation should be canceled.</param>
        /// <returns><see langword="true"/> if the <paramref name="symbol"/> is valid, otherwise <see langword="false"/>.</returns>
        public static bool Analyze(
            INamedTypeSymbol symbol,
            DefaultParamCompilationData compilation,
            CancellationToken cancellationToken = default
            )
        {
            TypeParameterContainer typeParameters = TypeParameterContainer.CreateFrom(symbol, compilation, cancellationToken);

            if (!typeParameters.HasDefaultParams)
            {
                return(false);
            }

            if (AnalyzeAgainstProhibitedAttributes(symbol, compilation, out AttributeData[]? attributes) &&
        /// <summary>
        /// Fully analyzes the specified <paramref name="symbol"/>.
        /// </summary>
        /// <param name="symbol"><see cref="IMethodSymbol"/> to analyze.</param>
        /// <param name="compilation">Current <see cref="DefaultParamCompilationData"/>.</param>
        /// <param name="cancellationToken"><see cref="CancellationToken"/> that specifies if the operation should be canceled.</param>
        /// <returns><see langword="true"/> if the <paramref name="symbol"/> is valid, otherwise <see langword="false"/>.</returns>
        public static bool Analyze(
            IMethodSymbol symbol,
            DefaultParamCompilationData compilation,
            CancellationToken cancellationToken = default
            )
        {
            TypeParameterContainer typeParameters = TypeParameterContainer.CreateFrom(symbol, compilation, cancellationToken);

            if (!typeParameters.HasDefaultParams && !symbol.IsOverride)
            {
                return(false);
            }

            return(AnalyzeCore(symbol, compilation, ref typeParameters, cancellationToken));
        }
        /// <summary>
        /// Specifies, if the <see cref="SemanticModel"/>, <see cref="INamedTypeSymbol"/> and <see cref="TypeParameterContainer"/> can be created from the given <paramref name="declaration"/>.
        /// If so, returns them.
        /// </summary>
        /// <param name="compilation">Current <see cref="DefaultParamCompilationData"/>.</param>
        /// <param name="declaration"><see cref="TypeDeclarationSyntax"/> to validate.</param>
        /// <param name="semanticModel"><see cref="SemanticModel"/> of the <paramref name="declaration"/>.</param>
        /// <param name="symbol"><see cref="INamedTypeSymbol"/> created from the <paramref name="declaration"/>.</param>
        /// <param name="typeParameters"><see cref="TypeParameterContainer"/> that contains the <paramref name="declaration"/>'s type parameters.</param>
        /// <param name="cancellationToken"><see cref="CancellationToken"/> that specifies if the operation should be canceled.</param>
        public static bool GetValidationData(
            DefaultParamCompilationData compilation,
            TypeDeclarationSyntax declaration,
            [NotNullWhen(true)] out SemanticModel?semanticModel,
            [NotNullWhen(true)] out INamedTypeSymbol?symbol,
            out TypeParameterContainer typeParameters,
            CancellationToken cancellationToken = default
            )
        {
            semanticModel  = compilation.Compilation.GetSemanticModel(declaration.SyntaxTree);
            typeParameters = GetTypeParameters(declaration, semanticModel, compilation, cancellationToken);

            if (!typeParameters.HasDefaultParams)
            {
                symbol = null !;
                return(false);
            }

            symbol = semanticModel.GetDeclaredSymbol(declaration, cancellationToken) !;

            return(symbol is not null);
        }
 /// <inheritdoc cref="WithDiagnostics.AnalyzeBaseMethodAndTypeParameters(IDiagnosticReceiver, IMethodSymbol, ref TypeParameterContainer, in TypeParameterContainer)"/>
 public static bool AnalyzeBaseMethodAndTypeParameters(
     IMethodSymbol symbol,
     ref TypeParameterContainer typeParameters,
     in TypeParameterContainer combinedTypeParameters
Example #7
0
 /// <summary>
 /// Analyzes if the <paramref name="symbol"/> has valid <paramref name="typeParameters"/> when compared to the <paramref name="symbol"/>'s base method.
 /// </summary>
 /// <param name="diagnosticReceiver"><see cref="IDiagnosticReceiver"/> that is used to report <see cref="Diagnostic"/>s.</param>
 /// <param name="symbol"><see cref="IMethodSymbol"/> to analyze.</param>
 /// <param name="typeParameters"><see cref="TypeParameterContainer"/> that contains type parameters to be analyzed.</param>
 /// <param name="combinedTypeParameters">Combined <see cref="TypeParameterContainer"/>s of the <paramref name="symbol"/>'s base methods.</param>
 /// <returns><see langword="true"/> if the <paramref name="symbol"/> is valid, otherwise <see langword="false"/>.</returns>
 public static bool AnalyzeBaseMethodAndTypeParameters(
     IDiagnosticReceiver diagnosticReceiver,
     IMethodSymbol symbol,
     ref TypeParameterContainer typeParameters,
     in TypeParameterContainer combinedTypeParameters