public static void CreateAndRegisterActions(
                CompilationStartAnalysisContext context,
                AbstractRemoveUnusedParametersAndValuesDiagnosticAnalyzer analyzer)
            {
                var attributeSetForMethodsToIgnore = ImmutableHashSet.CreateRange(GetAttributesForMethodsToIgnore(context.Compilation).WhereNotNull());
                var eventsArgType = context.Compilation.EventArgsType();
                var deserializationConstructorCheck = new DeserializationConstructorCheck(context.Compilation);
                var iCustomMarshaler = context.Compilation.GetTypeByMetadataName(typeof(ICustomMarshaler).FullName !);

                context.RegisterSymbolStartAction(symbolStartContext =>
                {
                    if (HasSyntaxErrors((INamedTypeSymbol)symbolStartContext.Symbol, symbolStartContext.CancellationToken))
                    {
                        // Bail out on syntax errors.
                        return;
                    }

                    // Create a new SymbolStartAnalyzer instance for every named type symbol
                    // to ensure there is no shared state (such as identified unused parameters within the type),
                    // as that would lead to duplicate diagnostics being reported from symbol end action callbacks
                    // for unrelated named types.
                    var symbolAnalyzer = new SymbolStartAnalyzer(analyzer, eventsArgType, attributeSetForMethodsToIgnore, deserializationConstructorCheck, iCustomMarshaler);
                    symbolAnalyzer.OnSymbolStart(symbolStartContext);
                }, SymbolKind.NamedType);

                return;
            private static async Task <bool> IsApplicableConstructorAsync(
                IMethodSymbol constructor,
                Document document,
                ImmutableArray <string> parameterNamesForSelectedMembers,
                CancellationToken cancellationToken
                )
            {
                var constructorParams = constructor.Parameters;

                if (constructorParams.Length == 2)
                {
                    var compilation = await document.Project
                                      .GetCompilationAsync(cancellationToken)
                                      .ConfigureAwait(false);

                    var deserializationConstructorCheck = new DeserializationConstructorCheck(
                        compilation
                        );
                    if (deserializationConstructorCheck.IsDeserializationConstructor(constructor))
                    {
                        return(false);
                    }
                }

                return(constructorParams.All(parameter => parameter.RefKind == RefKind.None) &&
                       !constructor.IsImplicitlyDeclared &&
                       !constructorParams.Any(p => p.IsParams) &&
                       !SelectedMembersAlreadyExistAsParameters(
                           parameterNamesForSelectedMembers,
                           constructorParams
                           ));
            }
            public SymbolStartAnalyzer(
                AbstractRemoveUnusedParametersAndValuesDiagnosticAnalyzer compilationAnalyzer,
                INamedTypeSymbol eventArgsTypeOpt,
                ImmutableHashSet <INamedTypeSymbol> attributeSetForMethodsToIgnore,
                DeserializationConstructorCheck deserializationConstructorCheck)
            {
                _compilationAnalyzer = compilationAnalyzer;

                _eventArgsTypeOpt = eventArgsTypeOpt;
                _attributeSetForMethodsToIgnore  = attributeSetForMethodsToIgnore;
                _deserializationConstructorCheck = deserializationConstructorCheck;
                _unusedParameters       = new ConcurrentDictionary <IParameterSymbol, bool>();
                _methodsUsedAsDelegates = new ConcurrentDictionary <IMethodSymbol, bool>();
            }
            public static void CreateAndRegisterActions(
                CompilationStartAnalysisContext context,
                AbstractRemoveUnusedParametersAndValuesDiagnosticAnalyzer analyzer)
            {
                var attributeSetForMethodsToIgnore = ImmutableHashSet.CreateRange(GetAttributesForMethodsToIgnore(context.Compilation).WhereNotNull());
                var eventsArgType = context.Compilation.EventArgsType();
                var deserializationConstructorCheck = new DeserializationConstructorCheck(context.Compilation);

                context.RegisterSymbolStartAction(symbolStartContext =>
                {
                    // Create a new SymbolStartAnalyzer instance for every named type symbol
                    // to ensure there is no shared state (such as identified unused parameters within the type),
                    // as that would lead to duplicate diagnostics being reported from symbol end action callbacks
                    // for unrelated named types.
                    var symbolAnalyzer = new SymbolStartAnalyzer(analyzer, eventsArgType, attributeSetForMethodsToIgnore, deserializationConstructorCheck);
                    symbolAnalyzer.OnSymbolStart(symbolStartContext);
                }, SymbolKind.NamedType);
            }
Exemplo n.º 5
0
            private CompilationAnalyzer(
                Compilation compilation,
                AbstractRemoveUnusedMembersDiagnosticAnalyzer <TDocumentationCommentTriviaSyntax, TIdentifierNameSyntax> analyzer)
            {
                _gate     = new object();
                _analyzer = analyzer;

                // State map for candidate member symbols, with the value indicating how each symbol is used in executable code.
                _symbolValueUsageStateMap = new Dictionary <ISymbol, ValueUsageInfo>();

                _taskType        = compilation.TaskType();
                _genericTaskType = compilation.TaskOfTType();
                _debuggerDisplayAttributeType = compilation.DebuggerDisplayAttributeType();
                _structLayoutAttributeType    = compilation.StructLayoutAttributeType();
                _eventArgsType = compilation.EventArgsType();
                _deserializationConstructorCheck = new DeserializationConstructorCheck(compilation);
                _attributeSetForMethodsToIgnore  = ImmutableHashSet.CreateRange(GetAttributesForMethodsToIgnore(compilation));
            }