tree-sitter-analyzer 0.9.9__py3-none-any.whl → 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of tree-sitter-analyzer might be problematic. Click here for more details.

@@ -1,167 +1,169 @@
1
- #!/usr/bin/env python3
2
- """
3
- Base formatter for language-specific table formatting.
4
- """
5
-
6
- import csv
7
- import io
8
- import os
9
- from abc import ABC, abstractmethod
10
- from typing import Any
11
-
12
-
13
- class BaseTableFormatter(ABC):
14
- """Base class for language-specific table formatters"""
15
-
16
- def __init__(self, format_type: str = "full"):
17
- self.format_type = format_type
18
-
19
- def _get_platform_newline(self) -> str:
20
- """Get platform-specific newline code"""
21
- return os.linesep
22
-
23
- def _convert_to_platform_newlines(self, text: str) -> str:
24
- """Convert regular \n to platform-specific newline code"""
25
- if os.linesep != "\n":
26
- return text.replace("\n", os.linesep)
27
- return text
28
-
29
- def format_structure(self, structure_data: dict[str, Any]) -> str:
30
- """Format structure data in table format"""
31
- if self.format_type == "full":
32
- result = self._format_full_table(structure_data)
33
- elif self.format_type == "compact":
34
- result = self._format_compact_table(structure_data)
35
- elif self.format_type == "csv":
36
- result = self._format_csv(structure_data)
37
- else:
38
- raise ValueError(f"Unsupported format type: {self.format_type}")
39
-
40
- # Finally convert to platform-specific newline code
41
- if self.format_type == "csv":
42
- return result
43
-
44
- return self._convert_to_platform_newlines(result)
45
-
46
- @abstractmethod
47
- def _format_full_table(self, data: dict[str, Any]) -> str:
48
- """Full table format (language-specific implementation)"""
49
- pass
50
-
51
- @abstractmethod
52
- def _format_compact_table(self, data: dict[str, Any]) -> str:
53
- """Compact table format (language-specific implementation)"""
54
- pass
55
-
56
- def _format_csv(self, data: dict[str, Any]) -> str:
57
- """CSV format (common implementation)"""
58
- output = io.StringIO()
59
- writer = csv.writer(output, lineterminator="\n")
60
-
61
- # Header
62
- writer.writerow(
63
- ["Type", "Name", "Signature", "Visibility", "Lines", "Complexity", "Doc"]
64
- )
65
-
66
- # Fields
67
- for field in data.get("fields", []):
68
- writer.writerow(
69
- [
70
- "Field",
71
- str(field.get("name", "")),
72
- f"{str(field.get('name', ''))}:{str(field.get('type', ''))}",
73
- str(field.get("visibility", "")),
74
- f"{field.get('line_range', {}).get('start', 0)}-{field.get('line_range', {}).get('end', 0)}",
75
- "",
76
- self._clean_csv_text(
77
- self._extract_doc_summary(str(field.get("javadoc", "")))
78
- ),
79
- ]
80
- )
81
-
82
- # Methods
83
- for method in data.get("methods", []):
84
- writer.writerow(
85
- [
86
- "Constructor" if method.get("is_constructor", False) else "Method",
87
- str(method.get("name", "")),
88
- self._clean_csv_text(self._create_full_signature(method)),
89
- str(method.get("visibility", "")),
90
- f"{method.get('line_range', {}).get('start', 0)}-{method.get('line_range', {}).get('end', 0)}",
91
- method.get("complexity_score", 0),
92
- self._clean_csv_text(
93
- self._extract_doc_summary(str(method.get("javadoc", "")))
94
- ),
95
- ]
96
- )
97
-
98
- csv_content = output.getvalue()
99
- csv_content = csv_content.replace("\r\n", "\n").replace("\r", "\n")
100
- csv_content = csv_content.rstrip("\n")
101
- output.close()
102
-
103
- return csv_content
104
-
105
- # Common helper methods
106
- def _create_full_signature(self, method: dict[str, Any]) -> str:
107
- """Create complete method signature"""
108
- params = method.get("parameters", [])
109
- param_strs = []
110
- for param in params:
111
- if isinstance(param, dict):
112
- param_type = str(param.get("type", "Object"))
113
- param_name = str(param.get("name", "param"))
114
- param_strs.append(f"{param_name}:{param_type}")
115
- else:
116
- param_strs.append(str(param))
117
-
118
- params_str = ", ".join(param_strs)
119
- return_type = str(method.get("return_type", "void"))
120
-
121
- modifiers = []
122
- if method.get("is_static", False):
123
- modifiers.append("[static]")
124
-
125
- modifier_str = " ".join(modifiers)
126
- signature = f"({params_str}):{return_type}"
127
-
128
- if modifier_str:
129
- signature += f" {modifier_str}"
130
-
131
- return signature
132
-
133
- def _convert_visibility(self, visibility: str) -> str:
134
- """Convert visibility to symbol"""
135
- mapping = {"public": "+", "private": "-", "protected": "#", "package": "~"}
136
- return mapping.get(visibility, visibility)
137
-
138
- def _extract_doc_summary(self, javadoc: str) -> str:
139
- """Extract summary from documentation"""
140
- if not javadoc:
141
- return "-"
142
-
143
- # Remove comment symbols
144
- clean_doc = (
145
- javadoc.replace("/**", "").replace("*/", "").replace("*", "").strip()
146
- )
147
-
148
- # Get first line
149
- lines = clean_doc.split("\n")
150
- first_line = lines[0].strip()
151
-
152
- # Truncate if too long
153
- if len(first_line) > 50:
154
- first_line = first_line[:47] + "..."
155
-
156
- return first_line.replace("|", "\\|").replace("\n", " ")
157
-
158
- def _clean_csv_text(self, text: str) -> str:
159
- """Text cleaning for CSV format"""
160
- if not text:
161
- return ""
162
-
163
- cleaned = text.replace("\r\n", " ").replace("\r", " ").replace("\n", " ")
164
- cleaned = " ".join(cleaned.split())
165
- cleaned = cleaned.replace('"', '""')
166
-
167
- return cleaned
1
+ #!/usr/bin/env python3
2
+ """
3
+ Base formatter for language-specific table formatting.
4
+ """
5
+
6
+ import csv
7
+ import io
8
+ from abc import ABC, abstractmethod
9
+ from typing import Any
10
+
11
+
12
+ class BaseTableFormatter(ABC):
13
+ """Base class for language-specific table formatters"""
14
+
15
+ def __init__(self, format_type: str = "full"):
16
+ self.format_type = format_type
17
+
18
+ def _get_platform_newline(self) -> str:
19
+ """Get platform-specific newline code"""
20
+ import os
21
+
22
+ return "\r\n" if os.name == "nt" else "\n" # Windows uses \r\n, others use \n
23
+
24
+ def _convert_to_platform_newlines(self, text: str) -> str:
25
+ """Convert regular \n to platform-specific newline code"""
26
+ platform_newline = self._get_platform_newline()
27
+ if platform_newline != "\n":
28
+ return text.replace("\n", platform_newline)
29
+ return text
30
+
31
+ def format_structure(self, structure_data: dict[str, Any]) -> str:
32
+ """Format structure data in table format"""
33
+ if self.format_type == "full":
34
+ result = self._format_full_table(structure_data)
35
+ elif self.format_type == "compact":
36
+ result = self._format_compact_table(structure_data)
37
+ elif self.format_type == "csv":
38
+ result = self._format_csv(structure_data)
39
+ else:
40
+ raise ValueError(f"Unsupported format type: {self.format_type}")
41
+
42
+ # Finally convert to platform-specific newline code
43
+ if self.format_type == "csv":
44
+ return result
45
+
46
+ return self._convert_to_platform_newlines(result)
47
+
48
+ @abstractmethod
49
+ def _format_full_table(self, data: dict[str, Any]) -> str:
50
+ """Full table format (language-specific implementation)"""
51
+ pass
52
+
53
+ @abstractmethod
54
+ def _format_compact_table(self, data: dict[str, Any]) -> str:
55
+ """Compact table format (language-specific implementation)"""
56
+ pass
57
+
58
+ def _format_csv(self, data: dict[str, Any]) -> str:
59
+ """CSV format (common implementation)"""
60
+ output = io.StringIO()
61
+ writer = csv.writer(output, lineterminator="\n")
62
+
63
+ # Header
64
+ writer.writerow(
65
+ ["Type", "Name", "Signature", "Visibility", "Lines", "Complexity", "Doc"]
66
+ )
67
+
68
+ # Fields
69
+ for field in data.get("fields", []):
70
+ writer.writerow(
71
+ [
72
+ "Field",
73
+ str(field.get("name", "")),
74
+ f"{str(field.get('name', ''))}:{str(field.get('type', ''))}",
75
+ str(field.get("visibility", "")),
76
+ f"{field.get('line_range', {}).get('start', 0)}-{field.get('line_range', {}).get('end', 0)}",
77
+ "",
78
+ self._clean_csv_text(
79
+ self._extract_doc_summary(str(field.get("javadoc", "")))
80
+ ),
81
+ ]
82
+ )
83
+
84
+ # Methods
85
+ for method in data.get("methods", []):
86
+ writer.writerow(
87
+ [
88
+ "Constructor" if method.get("is_constructor", False) else "Method",
89
+ str(method.get("name", "")),
90
+ self._clean_csv_text(self._create_full_signature(method)),
91
+ str(method.get("visibility", "")),
92
+ f"{method.get('line_range', {}).get('start', 0)}-{method.get('line_range', {}).get('end', 0)}",
93
+ method.get("complexity_score", 0),
94
+ self._clean_csv_text(
95
+ self._extract_doc_summary(str(method.get("javadoc", "")))
96
+ ),
97
+ ]
98
+ )
99
+
100
+ csv_content = output.getvalue()
101
+ csv_content = csv_content.replace("\r\n", "\n").replace("\r", "\n")
102
+ csv_content = csv_content.rstrip("\n")
103
+ output.close()
104
+
105
+ return csv_content
106
+
107
+ # Common helper methods
108
+ def _create_full_signature(self, method: dict[str, Any]) -> str:
109
+ """Create complete method signature"""
110
+ params = method.get("parameters", [])
111
+ param_strs = []
112
+ for param in params:
113
+ if isinstance(param, dict):
114
+ param_type = str(param.get("type", "Object"))
115
+ param_name = str(param.get("name", "param"))
116
+ param_strs.append(f"{param_name}:{param_type}")
117
+ else:
118
+ param_strs.append(str(param))
119
+
120
+ params_str = ", ".join(param_strs)
121
+ return_type = str(method.get("return_type", "void"))
122
+
123
+ modifiers = []
124
+ if method.get("is_static", False):
125
+ modifiers.append("[static]")
126
+
127
+ modifier_str = " ".join(modifiers)
128
+ signature = f"({params_str}):{return_type}"
129
+
130
+ if modifier_str:
131
+ signature += f" {modifier_str}"
132
+
133
+ return signature
134
+
135
+ def _convert_visibility(self, visibility: str) -> str:
136
+ """Convert visibility to symbol"""
137
+ mapping = {"public": "+", "private": "-", "protected": "#", "package": "~"}
138
+ return mapping.get(visibility, visibility)
139
+
140
+ def _extract_doc_summary(self, javadoc: str) -> str:
141
+ """Extract summary from documentation"""
142
+ if not javadoc:
143
+ return "-"
144
+
145
+ # Remove comment symbols
146
+ clean_doc = (
147
+ javadoc.replace("/**", "").replace("*/", "").replace("*", "").strip()
148
+ )
149
+
150
+ # Get first line
151
+ lines = clean_doc.split("\n")
152
+ first_line = lines[0].strip()
153
+
154
+ # Truncate if too long
155
+ if len(first_line) > 50:
156
+ first_line = first_line[:47] + "..."
157
+
158
+ return first_line.replace("|", "\\|").replace("\n", " ")
159
+
160
+ def _clean_csv_text(self, text: str) -> str:
161
+ """Text cleaning for CSV format"""
162
+ if not text:
163
+ return ""
164
+
165
+ cleaned = text.replace("\r\n", " ").replace("\r", " ").replace("\n", " ")
166
+ cleaned = " ".join(cleaned.split())
167
+ cleaned = cleaned.replace('"', '""')
168
+
169
+ return cleaned