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)); }
public static Maybe <ClassDeclarationSyntax> ResolveStaticClassWhereToInsertMethods( AttributeSyntax attributeSyntax) { return (attributeSyntax.Ancestors() .OfType <ClassDeclarationSyntax>() .FirstOrNoValue() .If(x => x.Modifiers.Any(IsStaticKeyword))); }
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"))); }
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); }
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); }
private static string GetClassName(AttributeSyntax attributeNode) { var classNode = attributeNode.Ancestors().OfType <ClassDeclarationSyntax>().Single(); return(classNode.Identifier.Text); }