// MIT License - Copyright (c) 2025 wallstop // Full license text: https://github.com/wallstop/unity-helpers/blob/main/LICENSE namespace WallstopStudios.UnityHelpers.Editor.Tools.UnityMethodAnalyzer { #if UNITY_EDITOR using System.Collections.Generic; /// /// Represents the severity level of a detected issue. /// public enum IssueSeverity { Critical = 1, High = 2, Medium = 3, Low = 4, Info = 5, } /// /// Categorizes issues by their context. /// public enum IssueCategory { UnityLifecycle, UnityInheritance, GeneralInheritance, } /// /// Represents a detected issue in the codebase. /// public sealed class AnalyzerIssue { public string FilePath { get; set; } public string ClassName { get; set; } public string MethodName { get; set; } public string IssueType { get; set; } public string Description { get; set; } public IssueSeverity Severity { get; set; } public string RecommendedFix { get; set; } public int LineNumber { get; set; } public IssueCategory Category { get; set; } public string BaseClassName { get; set; } public string BaseMethodSignature { get; set; } public string DerivedMethodSignature { get; set; } public AnalyzerIssue( string filePath, string className, string methodName, string issueType, string description, IssueSeverity severity, string recommendedFix, int lineNumber, IssueCategory category = IssueCategory.GeneralInheritance, string baseClassName = null, string baseMethodSignature = null, string derivedMethodSignature = null ) { FilePath = filePath; ClassName = className; MethodName = methodName; IssueType = issueType; Description = description; Severity = severity; RecommendedFix = recommendedFix; LineNumber = lineNumber; Category = category; BaseClassName = baseClassName; BaseMethodSignature = baseMethodSignature; DerivedMethodSignature = derivedMethodSignature; } } /// /// Contains information about a method declaration. /// public sealed class AnalyzerMethodInfo { public string Name { get; set; } public string Signature { get; set; } public bool IsVirtual { get; set; } public bool IsOverride { get; set; } public bool IsNew { get; set; } public bool IsAbstract { get; set; } public bool IsSealed { get; set; } public bool IsPrivate { get; set; } public bool IsProtected { get; set; } public bool IsPublic { get; set; } public bool IsInternal { get; set; } public bool IsStatic { get; set; } public int LineNumber { get; set; } public string ReturnType { get; set; } public List Parameters { get; set; } public List ParameterTypes { get; set; } /// /// Indicates whether this method is marked with [SuppressAnalyzer] attribute. /// Methods marked as suppressed will not generate analyzer warnings. /// public bool IsSuppressed { get; set; } /// /// Cached joined parameter types string for efficient comparison. /// Lazily computed on first access to avoid allocations when not needed. /// private string _cachedParameterTypesString; /// /// Gets the parameter types as a joined string for efficient comparison. /// This value is cached after first computation to avoid repeated allocations. /// public string ParameterTypesString { get { if (_cachedParameterTypesString == null && ParameterTypes != null) { _cachedParameterTypesString = string.Join(", ", ParameterTypes); } return _cachedParameterTypesString ?? string.Empty; } } public AnalyzerMethodInfo() { Parameters = new List(); ParameterTypes = new List(); } } /// /// Contains information about a class declaration. /// public sealed class AnalyzerClassInfo { public string Name { get; set; } public string FullName { get; set; } public string BaseClassName { get; set; } public string FilePath { get; set; } public Dictionary> Methods { get; set; } public int LineNumber { get; set; } /// /// The generic type parameters declared by this class (e.g., ["TKey", "TValue"]). /// public List GenericTypeParameters { get; set; } /// /// The concrete type arguments provided to the base class (e.g., ["int", "string"]). /// Maps positionally to the base class's GenericTypeParameters. /// public List BaseClassTypeArguments { get; set; } /// /// The full base class declaration including generic arguments (e.g., "WDropDownSelectorBase<int>"). /// public string BaseClassFullDeclaration { get; set; } /// /// The list of interfaces implemented by this class. /// public List ImplementedInterfaces { get; set; } /// /// Indicates whether this class is marked with [SuppressAnalyzer] attribute. /// Classes marked as suppressed will not generate analyzer warnings. /// public bool IsSuppressed { get; set; } public AnalyzerClassInfo() { Methods = new Dictionary>(); GenericTypeParameters = new List(); BaseClassTypeArguments = new List(); ImplementedInterfaces = new List(); } } #endif }