40 lines
1.1 KiB
Python
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
|