Пример #1
0
        public static void ReportHiddenDisposable(this CustomAnalysisContext ctx, string actualTypeName, string returnTypeName, string methodOrFuncName)
        {
            var location   = ctx.OriginalNode.GetLocation();
            var descriptor = Hidden.Disposable;

            ctx.Context.ReportDiagnostic(Diagnostic.Create(descriptor, location, actualTypeName, returnTypeName, methodOrFuncName));
        }
Пример #2
0
        private static void ReportNotDisposedNoneStaticPropertyFactory(this CustomAnalysisContext ctx, string propertyName)
        {
            var location   = ctx.OriginalNode.GetLocation();
            var properties = ImmutableDictionary.CreateBuilder <string, string>();

            properties.Add(Constants.Variablename, propertyName);
            var descriptor = NotDisposed.FactoryProperty.Descriptor;

            ctx.Context.ReportDiagnostic(Diagnostic.Create(descriptor, location, properties.ToImmutable(), propertyName));
        }
Пример #3
0
 public static void ReportNotDisposedField(this CustomAnalysisContext ctx, string fieldName, bool isStatic)
 {
     if (isStatic)
     {
         ReportNotDisposedStaticField(ctx, fieldName);
     }
     else
     {
         ReportNotDisposedNoneStaticField(ctx, fieldName);
     }
 }
Пример #4
0
 public static void ReportNotDisposedProperty(this CustomAnalysisContext ctx, string propertyName, bool isStatic)
 {
     if (isStatic)
     {
         ReportNotDisposedStaticProperty(ctx, propertyName);
     }
     else
     {
         ReportNotDisposedNoneStaticProperty(ctx, propertyName);
     }
 }
Пример #5
0
        public static void ReportNotDisposedLocalVariable(this CustomAnalysisContext ctx, string variableName)
        {
            var location   = ctx.OriginalNode.GetLocation();
            var descriptor = NotDisposed.LocalVariable.Descriptor;

            if (GetCustomSeverity(ctx, out var severity))
            {
                descriptor = ReplaceSeverity(descriptor, severity);
            }

            ctx.Context.ReportDiagnostic(Diagnostic.Create(descriptor, location, variableName));
        }
Пример #6
0
        public static void ReportNotDisposedAnonymousObject(this CustomAnalysisContext ctx)
        {
            var location   = ctx.OriginalNode.GetLocation();
            var descriptor = ctx.Source == DisposableSource.InvocationExpression
                ? NotDisposed.AnonymousObject.FromMethodInvocationDescriptor
                : NotDisposed.AnonymousObject.FromObjectCreationDescriptor;

            if (GetCustomSeverity(ctx, out var severity))
            {
                descriptor = ReplaceSeverity(descriptor, severity);
            }

            ctx.Context.ReportDiagnostic(Diagnostic.Create(descriptor, location));
        }
Пример #7
0
        private static void ReportNotDisposedStaticField(this CustomAnalysisContext ctx, string fieldName)
        {
            var location   = ctx.OriginalNode.GetLocation();
            var properties = ImmutableDictionary.CreateBuilder <string, string>();

            properties.Add(Constants.Variablename, fieldName);
            var descriptor = ctx.Source == DisposableSource.InvocationExpression
                ? NotDisposed.Assignment.FromMethodInvocation.ToStaticField.OfSameTypeDescriptor
                : NotDisposed.Assignment.FromObjectCreation.ToStaticField.OfSameTypeDescriptor;

            if (GetCustomSeverity(ctx, out var severity))
            {
                descriptor = ReplaceSeverity(descriptor, severity);
            }

            ctx.Context.ReportDiagnostic(Diagnostic.Create(descriptor, location, properties.ToImmutable(), fieldName));
        }
Пример #8
0
        public static void ReportNotDisposedPropertyOfAnotherType(this CustomAnalysisContext ctx,
                                                                  string propertyName, string typeOrInstanceName = null, bool isStatic = false)
        {
            var location   = ctx.OriginalNode.GetLocation();
            var properties = ImmutableDictionary.CreateBuilder <string, string>();

            properties.Add(Constants.Variablename, propertyName);
            var descriptor = ctx.Source == DisposableSource.InvocationExpression
                ? isStatic
                    ? NotDisposed.Assignment.FromMethodInvocation.ToStaticProperty.OfAnotherTypeDescriptor
                    : NotDisposed.Assignment.FromMethodInvocation.ToProperty.OfAnotherTypeDescriptor
                : isStatic
                    ? NotDisposed.Assignment.FromObjectCreation.ToStaticProperty.OfAnotherTypeDescriptor
                    : NotDisposed.Assignment.FromObjectCreation.ToProperty.OfAnotherTypeDescriptor;

            if (GetCustomSeverity(ctx, out var severity))
            {
                descriptor = ReplaceSeverity(descriptor, severity);
            }
            var propertyPath = typeOrInstanceName != null ? $"{typeOrInstanceName}.{propertyName}" : propertyName;

            ctx.Context.ReportDiagnostic(Diagnostic.Create(descriptor, location, properties.ToImmutable(), propertyPath));
        }
Пример #9
0
        private static bool GetCustomSeverity(CustomAnalysisContext context, out DiagnosticSeverity severity)
        {
            var fullName = context.Type.GetFullNamespace();

            return(context.Configuration.TypeWithCustomSeverity.TryGetValue(fullName, out severity));
        }
Пример #10
0
 public static CustomAnalysisContext NewWith(this CustomAnalysisContext ctx, SyntaxNode newNode)
 {
     return(CustomAnalysisContext.WithOtherNode(ctx.Context, newNode, ctx.Source, ctx.Type, ctx.Detector,
                                                ctx.Configuration));
 }
Пример #11
0
 public static bool IsTypeIgnoredOrImplementsIgnoredInterface(this CustomAnalysisContext ctx)
 {
     return(ctx.Detector.IsIgnoredTypeOrImplementsIgnoredInterface(ctx.Type));
 }
Пример #12
0
 public static bool IsDisposableOrImplementsDisposable(this CustomAnalysisContext ctx)
 {
     return(ctx.Type.IsDisposableOrImplementsDisposable());
 }
Пример #13
0
 public static bool CouldDetectType(this CustomAnalysisContext ctx)
 {
     return(ctx.Type != null);
 }