Esempio n. 1
0
        public override SyntaxNode VisitAttribute(AttributeSyntax node)
        {
            if (node.Name.ToString() == nameof(MethodHasDebt))
            {
                var containingMethod = node.Ancestors().OfType <BaseMethodDeclarationSyntax>().FirstOrDefault();
                if (containingMethod == null)
                {
                    return(node);
                }

                if (containingMethod.ParameterList.Parameters.Count <= maxParameters && MethodLengthAnalyzer.GetMethodLength(containingMethod) < maxMethodLength)
                {
                    return(null);
                }
                return(Formatter.Format(MethodDebtAnnotationProvider.GetAttribute(containingMethod), workspace));
            }

            if (node.Name.ToString() == nameof(TypeHasDebt))
            {
                var containingType = node.Ancestors().OfType <TypeDeclarationSyntax>().FirstOrDefault();
                if (containingType == null)
                {
                    return(node);
                }
                if (TypeLengthAnalyzer.GetTypeLength(containingType) < maxTypeLength &&
                    FieldCountAnalyzer.GetFieldCount(containingType) < maxFieldCount)
                {
                    return(null);
                }
                return(Formatter.Format(TypeDebtAnnotationProvider.GetAttribute(containingType), workspace));
            }
            return(base.VisitAttribute(node));
        }
Esempio n. 2
0
 public static Maybe <ClassDeclarationSyntax> ResolveStaticClassWhereToInsertMethods(
     AttributeSyntax attributeSyntax)
 {
     return
         (attributeSyntax.Ancestors()
          .OfType <ClassDeclarationSyntax>()
          .FirstOrNoValue()
          .If(x => x.Modifiers.Any(IsStaticKeyword)));
 }
Esempio n. 3
0
        private static AttributeSyntax ReplaceByTestOrTheory(AttributeSyntax node)
        {
            var testMethod = node.Ancestors().SingleOrDefault(x => x is MethodDeclarationSyntax) as MethodDeclarationSyntax;

            if (testMethod == null)
            {
                return(node);
            }
            return(testMethod.HasParameter() ? Attribute(ParseName("Xunit.Theory")) : Attribute(ParseName("Xunit.Fact")));
        }
Esempio n. 4
0
                static bool IsWellKnown(AttributeSyntax attr)
                {
                    switch (attr.Name.ToString())
                    {
                    // Currently, the analyzer's test infra only understands these attributes when placed on methods.
                    case "ExpectedWarning":
                    case "LogContains":
                    case "LogDoesNotContain":
                        return(attr.Ancestors().OfType <MemberDeclarationSyntax> ().First().IsKind(SyntaxKind.MethodDeclaration));

                    case "UnrecognizedReflectionAccessPattern":
                        return(true);
                    }

                    return(false);
                }
Esempio n. 5
0
        public static bool IsAssemblyAttribute(AttributeSyntax syntax)
        {
            var attributeList = syntax.Ancestors().OfType <AttributeListSyntax>().FirstOrDefault();

            if (attributeList == null)
            {
                return(false);
            }

            var targetSpecifierSyntax = attributeList.ChildNodes().OfType <AttributeTargetSpecifierSyntax>().FirstOrDefault();

            if (targetSpecifierSyntax?.Kind() == SyntaxKind.AssemblyKeyword)
            {
                return(true);
            }

            return(false);
        }
Esempio n. 6
0
        private static string GetClassName(AttributeSyntax attributeNode)
        {
            var classNode = attributeNode.Ancestors().OfType <ClassDeclarationSyntax>().Single();

            return(classNode.Identifier.Text);
        }