Esempio n. 1
0
        protected override IEnumerable <IInspectionResult> DoGetInspectionResults()
        {
            var issues = new List <DeclarationInspectionResult>();

            foreach (var declaration in State.AllUserDeclarations)
            {
                var duplicateAnnotations = declaration.Annotations
                                           .GroupBy(annotation => annotation.AnnotationType)
                                           .Where(group => !group.First().AllowMultiple&& group.Count() > 1);

                issues.AddRange(duplicateAnnotations.Select(duplicate =>
                {
                    var result = new DeclarationInspectionResult(
                        this,
                        string.Format(InspectionResults.DuplicatedAnnotationInspection, duplicate.Key.ToString()),
                        declaration);

                    result.Properties.AnnotationType = duplicate.Key;

                    return(result);
                }));
            }

            return(issues);
        }
Esempio n. 2
0
        protected override IEnumerable <IInspectionResult> DoGetInspectionResults()
        {
            var declarationsWithAttributeAnnotations = State.DeclarationFinder.AllUserDeclarations
                                                       .Where(declaration => declaration.Annotations.Any(annotation => annotation.AnnotationType.HasFlag(AnnotationType.Attribute)));
            var results = new List <DeclarationInspectionResult>();

            foreach (var declaration in declarationsWithAttributeAnnotations.Where(decl => decl.QualifiedModuleName.ComponentType != ComponentType.Document))
            {
                foreach (var annotation in declaration.Annotations.OfType <IAttributeAnnotation>())
                {
                    if (HasDifferingAttributeValues(declaration, annotation, out var attributeValues))
                    {
                        var description = string.Format(InspectionResults.AttributeValueOutOfSyncInspection,
                                                        annotation.Attribute,
                                                        string.Join(", ", attributeValues),
                                                        annotation.AnnotationType);

                        var result = new DeclarationInspectionResult(this, description, declaration,
                                                                     new QualifiedContext(declaration.QualifiedModuleName, annotation.Context));
                        result.Properties.Annotation      = annotation;
                        result.Properties.AttributeName   = annotation.Attribute;
                        result.Properties.AttributeValues = attributeValues;

                        results.Add(result);
                    }
                }
            }

            return(results);
        }
Esempio n. 3
0
        protected override IEnumerable <IInspectionResult> DoGetInspectionResults()
        {
            var declarationsWithAttributeAnnotations = State.DeclarationFinder.AllUserDeclarations
                                                       .Where(declaration => declaration.Annotations.Any(pta => pta.Annotation is IAttributeAnnotation));
            var results = new List <DeclarationInspectionResult>();

            foreach (var declaration in declarationsWithAttributeAnnotations.Where(decl => decl.QualifiedModuleName.ComponentType != ComponentType.Document))
            {
                foreach (var annotationInstance in declaration.Annotations.Where(pta => pta.Annotation is IAttributeAnnotation))
                {
                    // cast is safe given the predicate in the foreach
                    var annotation = (IAttributeAnnotation)annotationInstance.Annotation;
                    if (HasDifferingAttributeValues(declaration, annotationInstance, out var attributeValues))
                    {
                        var attributeName = annotation.Attribute(annotationInstance);

                        var description = string.Format(InspectionResults.AttributeValueOutOfSyncInspection,
                                                        attributeName,
                                                        string.Join(", ", attributeValues),
                                                        annotation.Name);

                        var result = new DeclarationInspectionResult(this, description, declaration,
                                                                     new QualifiedContext(declaration.QualifiedModuleName, annotationInstance.Context));
                        result.Properties.Annotation      = annotationInstance;
                        result.Properties.AttributeName   = attributeName;
                        result.Properties.AttributeValues = attributeValues;

                        results.Add(result);
                    }
                }
            }

            return(results);
        }
Esempio n. 4
0
        protected override IEnumerable <IInspectionResult> DoGetInspectionResults()
        {
            var declarationsWithAttributeAnnotations = State.DeclarationFinder.AllUserDeclarations
                                                       .Where(declaration => declaration.Annotations.Any(annotation => annotation.AnnotationType.HasFlag(AnnotationType.Attribute)));
            var results = new List <DeclarationInspectionResult>();

            foreach (var declaration in declarationsWithAttributeAnnotations.Where(decl => decl.QualifiedModuleName.ComponentType != ComponentType.Document))
            {
                foreach (var annotation in declaration.Annotations.OfType <IAttributeAnnotation>())
                {
                    if (MissesCorrespondingAttribute(declaration, annotation))
                    {
                        var description = string.Format(InspectionResults.MissingAttributeInspection, declaration.IdentifierName,
                                                        annotation.AnnotationType.ToString());

                        var result = new DeclarationInspectionResult(this, description, declaration,
                                                                     new QualifiedContext(declaration.QualifiedModuleName, annotation.Context));
                        result.Properties.Annotation = annotation;

                        results.Add(result);
                    }
                }
            }

            return(results);
        }
Esempio n. 5
0
        protected override IEnumerable <IInspectionResult> DoGetInspectionResults()
        {
            var declarationsWithAttributeAnnotations = State.DeclarationFinder.AllUserDeclarations
                                                       .Where(declaration => declaration.Annotations.Any(pta => pta.Annotation is IAttributeAnnotation) &&
                                                              (declaration.DeclarationType.HasFlag(DeclarationType.Module) ||
                                                               declaration.AttributesPassContext != null));
            var results = new List <DeclarationInspectionResult>();

            // prefilter declarations to reduce searchspace
            var interestingDeclarations = declarationsWithAttributeAnnotations.Where(decl => decl.QualifiedModuleName.ComponentType != ComponentType.Document &&
                                                                                     !decl.IsIgnoringInspectionResultFor(AnnotationName));

            foreach (var declaration in interestingDeclarations)
            {
                foreach (var annotationInstance in declaration.Annotations.Where(pta => pta.Annotation is IAttributeAnnotation))
                {
                    var annotation = (IAttributeAnnotation)annotationInstance.Annotation;
                    if (MissesCorrespondingAttribute(declaration, annotationInstance))
                    {
                        var description = string.Format(InspectionResults.MissingAttributeInspection, declaration.IdentifierName, annotation.Name);

                        var result = new DeclarationInspectionResult(this, description, declaration,
                                                                     new QualifiedContext(declaration.QualifiedModuleName, annotationInstance.Context));
                        result.Properties.Annotation = annotationInstance;

                        results.Add(result);
                    }
                }
            }

            return(results);
        }
        protected override IEnumerable <IInspectionResult> DoGetInspectionResults()
        {
            var moduleDeclarationsWithAttributes = State.DeclarationFinder
                                                   .UserDeclarations(DeclarationType.Module)
                                                   .Where(decl => decl.Attributes.Any());

            var declarationsToInspect = moduleDeclarationsWithAttributes
                                        // prefilter declarations to reduce searchspace
                                        .Where(decl => decl.QualifiedModuleName.ComponentType != ComponentType.Document &&
                                               !decl.IsIgnoringInspectionResultFor(AnnotationName));

            var results = new List <DeclarationInspectionResult>();

            foreach (var declaration in declarationsToInspect)
            {
                foreach (var attribute in declaration.Attributes)
                {
                    if (IsDefaultAttribute(declaration, attribute))
                    {
                        continue;
                    }

                    if (MissesCorrespondingModuleAnnotation(declaration, attribute))
                    {
                        var description = string.Format(InspectionResults.MissingMemberAnnotationInspection,
                                                        declaration.IdentifierName,
                                                        attribute.Name,
                                                        string.Join(", ", attribute.Values));

                        var result = new DeclarationInspectionResult(this, description, declaration,
                                                                     new QualifiedContext(declaration.QualifiedModuleName, declaration.Context));
                        result.Properties.AttributeName   = attribute.Name;
                        result.Properties.AttributeValues = attribute.Values;

                        results.Add(result);
                    }
                }
            }

            return(results);
        }
Esempio n. 7
0
        protected override IEnumerable <IInspectionResult> DoGetInspectionResults()
        {
            var memberDeclarationsWithAttributes = State.DeclarationFinder.AllUserDeclarations
                                                   .Where(decl => !decl.DeclarationType.HasFlag(DeclarationType.Module) &&
                                                          decl.Attributes.Any());

            var declarationsToInspect = memberDeclarationsWithAttributes
                                        .Where(decl => decl.QualifiedModuleName.ComponentType != ComponentType.Document &&
                                               !IsIgnoringInspectionResultFor(decl, AnnotationName));

            var results = new List <DeclarationInspectionResult>();

            foreach (var declaration in declarationsToInspect)
            {
                foreach (var attribute in declaration.Attributes)
                {
                    if (MissesCorrespondingMemberAnnotation(declaration, attribute))
                    {
                        var attributeBaseName = AttributeBaseName(declaration, attribute);

                        var description = string.Format(InspectionResults.MissingMemberAnnotationInspection,
                                                        declaration.IdentifierName,
                                                        attributeBaseName,
                                                        string.Join(", ", attribute.Values));

                        var result = new DeclarationInspectionResult(this, description, declaration,
                                                                     new QualifiedContext(declaration.QualifiedModuleName, declaration.Context));
                        result.Properties.AttributeName   = attributeBaseName;
                        result.Properties.AttributeValues = attribute.Values;

                        results.Add(result);
                    }
                }
            }

            return(results);
        }