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 override void VisitClassDeclaration(ClassDeclarationSyntax node) { var classLineCount = TypeLengthAnalyzer.GetTypeLength(node); var fieldCount = FieldCountAnalyzer.GetFieldCount(node); TypeStatistics.FoundClass(node.Identifier.ToString(), classLineCount, fieldCount); base.VisitClassDeclaration(node); }
static async Task <ClassAttributeUpdater> GetClassUpdater(Project project) { var compilation = await project.GetCompilationAsync(); var maxParameters = MethodParameterCountAnalyzer.GetMaxParameterCount(compilation.Assembly); var maxMethodLength = MethodLengthAnalyzer.GetMaxLineCount(compilation.Assembly); var maxTypeLength = TypeLengthAnalyzer.GetMaxLineCount(compilation.Assembly); var maxFieldCount = FieldCountAnalyzer.GetMaxFieldCount(compilation.Assembly); return(new ClassAttributeUpdater(project.Solution.Workspace, maxParameters, maxMethodLength, maxTypeLength, maxFieldCount)); }
public LinesCalculator(IAssemblySymbol assembly) : base(SyntaxWalkerDepth.Node) { this.assembly = assembly; var methodStatistics = new MethodStatistics(MethodLengthAnalyzer.GetMaxLineCount(assembly), MethodParameterCountAnalyzer.GetMaxParameterCount(assembly)); var typeStatistics = new TypeStatistics(TypeLengthAnalyzer.GetMaxLineCount(assembly), FieldCountAnalyzer.GetMaxFieldCount(assembly)); statistics = new Statistics(typeStatistics, methodStatistics); }