public override void Fix(IInspectionResult result, IRewriteSession rewriteSession)
        {
            if (!(result is IWithInspectionResultProperties <(IParseTreeAnnotation Annotation, string AttributeName, IReadOnlyList <string> AttributeValues)> resultProperties))
            {
                return;
            }

            var declaration = result.Target;

            var(oldParseTreeAnnotation, attributeBaseName, attributeValues) = resultProperties.Properties;

            if (declaration.DeclarationType.HasFlag(DeclarationType.Module))
            {
                var componentType = declaration.QualifiedModuleName.ComponentType;
                if (IsDefaultAttribute(componentType, attributeBaseName, attributeValues))
                {
                    _annotationUpdater.RemoveAnnotation(rewriteSession, oldParseTreeAnnotation);
                }
                else
                {
                    var(newAnnotation, newAnnotationValues) = _attributeAnnotationProvider.ModuleAttributeAnnotation(attributeBaseName, attributeValues);
                    _annotationUpdater.UpdateAnnotation(rewriteSession, oldParseTreeAnnotation, newAnnotation, newAnnotationValues);
                }
            }
            else
            {
                var(newAnnotation, newAnnotationValues) = _attributeAnnotationProvider.MemberAttributeAnnotation(attributeBaseName, attributeValues);
                _annotationUpdater.UpdateAnnotation(rewriteSession, oldParseTreeAnnotation, newAnnotation, newAnnotationValues);
            }
        }
Exemple #2
0
        public override void Fix(IInspectionResult result, IRewriteSession rewriteSession)
        {
            IParseTreeAnnotation oldAnnotation = result.Properties.Annotation;
            string attributeName = result.Properties.AttributeName;
            IReadOnlyList <string> attributeValues = result.Properties.AttributeValues;

            var declaration = result.Target;

            if (declaration.DeclarationType.HasFlag(DeclarationType.Module))
            {
                var componentType = declaration.QualifiedModuleName.ComponentType;
                if (IsDefaultAttribute(componentType, attributeName, attributeValues))
                {
                    _annotationUpdater.RemoveAnnotation(rewriteSession, oldAnnotation);
                }
                else
                {
                    var(newAnnotation, newAnnotationValues) = _attributeAnnotationProvider.ModuleAttributeAnnotation(attributeName, attributeValues);
                    _annotationUpdater.UpdateAnnotation(rewriteSession, oldAnnotation, newAnnotation, newAnnotationValues);
                }
            }
            else
            {
                var attributeBaseName = AttributeBaseName(attributeName, declaration);
                var(newAnnotation, newAnnotationValues) = _attributeAnnotationProvider.MemberAttributeAnnotation(attributeBaseName, attributeValues);
                _annotationUpdater.UpdateAnnotation(rewriteSession, oldAnnotation, newAnnotation, newAnnotationValues);
            }
        }
Exemple #3
0
        private void UpdateFolderAnnotation(MoveToFolderModel model, IParseTreeAnnotation oldPta, IRewriteSession rewriteSession)
        {
            var oldFolderName = oldPta.AnnotationArguments.FirstOrDefault();

            if (oldFolderName == null || oldFolderName.Equals(model.TargetFolder))
            {
                return;
            }

            var(annotation, annotationValues) = NewAnnotation(model.TargetFolder);

            _annotationUpdater.UpdateAnnotation(rewriteSession, oldPta, annotation, annotationValues);
        }
Exemple #4
0
        private void FixNonModule(IInspectionResult result, IRewriteSession rewriteSession)
        {
            var module                   = result.QualifiedSelection.QualifiedName;
            var lineToAnnotate           = result.QualifiedSelection.Selection.StartLine;
            var existingIgnoreAnnotation = _state.DeclarationFinder.FindAnnotations(module, lineToAnnotate)
                                           .OfType <IgnoreAnnotation>()
                                           .FirstOrDefault();

            var annotationType = AnnotationType.Ignore;

            if (existingIgnoreAnnotation != null)
            {
                var annotationValues = existingIgnoreAnnotation.InspectionNames.ToList();
                annotationValues.Insert(0, result.Inspection.AnnotationName);
                _annotationUpdater.UpdateAnnotation(rewriteSession, existingIgnoreAnnotation, annotationType, annotationValues);
            }
            else
            {
                var annotationValues = new List <string> {
                    result.Inspection.AnnotationName
                };
                _annotationUpdater.AddAnnotation(rewriteSession, new QualifiedContext(module, result.Context), annotationType, annotationValues);
            }
        }
        public override void Fix(IInspectionResult result, IRewriteSession rewriteSession)
        {
            var module            = result.QualifiedSelection.QualifiedName;
            var moduleDeclaration = _state.DeclarationFinder.Members(module, DeclarationType.Module)
                                    .FirstOrDefault();

            if (moduleDeclaration == null)
            {
                return;
            }

            var existingIgnoreModuleAnnotation = moduleDeclaration.Annotations
                                                 .FirstOrDefault(pta => pta.Annotation is IgnoreModuleAnnotation);

            var annotationType = new IgnoreModuleAnnotation();

            if (existingIgnoreModuleAnnotation != null)
            {
                var annotationValues = existingIgnoreModuleAnnotation.AnnotationArguments.ToList();

                if (annotationValues.Contains(result.Inspection.AnnotationName))
                {
                    return;
                }

                annotationValues.Insert(0, result.Inspection.AnnotationName);
                _annotationUpdater.UpdateAnnotation(rewriteSession, existingIgnoreModuleAnnotation, annotationType, annotationValues);
            }
            else
            {
                var newModuleText    = rewriteSession.CheckOutModuleRewriter(module).GetText();
                var ignoreModuleText = $"'{ParseTreeAnnotation.ANNOTATION_MARKER}{annotationType.Name}";
                if (newModuleText.Contains(ignoreModuleText))
                {
                    //Most probably, we have added this already in another invocation on the same rewrite session.
                    return;
                }

                var annotationValues = new List <string> {
                    result.Inspection.AnnotationName
                };
                _annotationUpdater.AddAnnotation(rewriteSession, moduleDeclaration, annotationType, annotationValues);
            }
        }