Esempio n. 1
0
        private static void AnalyzeTypeDeclaration(
            SymbolAnalysisContext ctx,
            AnnotationsContext annotationsContext,
            ImmutabilityContext immutabilityContext,
            INamedTypeSymbol typeSymbol
            )
        {
            if (typeSymbol.IsImplicitlyDeclared)
            {
                return;
            }

            ImmutableAttributeConsistencyChecker consistencyChecker = new ImmutableAttributeConsistencyChecker(
                compilation: ctx.Compilation,
                diagnosticSink: ctx.ReportDiagnostic,
                context: immutabilityContext,
                annotationsContext: annotationsContext
                );

            consistencyChecker.CheckTypeDeclaration(typeSymbol);

            if (typeSymbol.TypeKind == TypeKind.Interface)
            {
                return;
            }

            if (!annotationsContext.Objects.Immutable.IsDefined(typeSymbol) &&
                !annotationsContext.Objects.ConditionallyImmutable.IsDefined(typeSymbol) &&
                !annotationsContext.Objects.ImmutableBaseClass.IsDefined(typeSymbol)
                )
            {
                return;
            }

            if (annotationsContext.Objects.ConditionallyImmutable.IsDefined(typeSymbol))
            {
                immutabilityContext = immutabilityContext.WithConditionalTypeParametersAsImmutable(typeSymbol);
            }

            ImmutableDefinitionChecker checker = new ImmutableDefinitionChecker(
                compilation: ctx.Compilation,
                diagnosticSink: ctx.ReportDiagnostic,
                context: immutabilityContext,
                annotationsContext: annotationsContext
                );

            checker.CheckDeclaration(typeSymbol);
        }
Esempio n. 2
0
        private static void AnalyzeMethodDeclarationConsistency(
            SymbolAnalysisContext ctx,
            AnnotationsContext annotationsContext,
            ImmutabilityContext immutabilityContext,
            IMethodSymbol methodSymbol
            )
        {
            // Static methods can't implement interface methods
            if (methodSymbol.IsStatic)
            {
                return;
            }

            ImmutableAttributeConsistencyChecker consistencyChecker = new ImmutableAttributeConsistencyChecker(
                compilation: ctx.Compilation,
                diagnosticSink: ctx.ReportDiagnostic,
                context: immutabilityContext,
                annotationsContext: annotationsContext
                );

            consistencyChecker.CheckMethodDeclaration(methodSymbol);
        }