Files
auto-readme-cli/src/auto_readme/analyzers/analyzer_factory.py
7000pctAUTO c2603e5993
Some checks failed
CI / build (push) Has been cancelled
CI / release (push) Has been cancelled
CI / test (push) Has been cancelled
Add code analyzers (Python, JS, Go, Rust) with tree-sitter
2026-02-05 08:42:32 +00:00

40 lines
1.1 KiB
Python

"""Code analyzer factory for routing to correct analyzer."""
from pathlib import Path
from typing import Optional
from . import CodeAnalyzer
from .python_analyzer import PythonAnalyzer
from .javascript_analyzer import JavaScriptAnalyzer
from .go_analyzer import GoAnalyzer
from .rust_analyzer import RustAnalyzer
class CodeAnalyzerFactory:
"""Factory for creating appropriate code analyzers."""
ANALYZERS = [
PythonAnalyzer(),
JavaScriptAnalyzer(),
GoAnalyzer(),
RustAnalyzer(),
]
@classmethod
def get_analyzer(cls, path: Path) -> Optional[CodeAnalyzer]:
"""Get the appropriate analyzer for a file."""
for analyzer in cls.ANALYZERS:
if analyzer.can_analyze(path):
return analyzer
return None
@classmethod
def get_all_analyzers(cls) -> list[CodeAnalyzer]:
"""Get all available analyzers."""
return cls.ANALYZERS.copy()
@classmethod
def can_analyze(cls, path: Path) -> bool:
"""Check if any analyzer can handle the file."""
return cls.get_analyzer(path) is not None