Extract base classes / implemented interfaces.
(self, node, language: str, source: bytes)
| 6061 | return None |
| 6062 | |
| 6063 | def _get_bases(self, node, language: str, source: bytes) -> list[str]: |
| 6064 | """Extract base classes / implemented interfaces.""" |
| 6065 | bases = [] |
| 6066 | if language == "python": |
| 6067 | for child in node.children: |
| 6068 | if child.type == "argument_list": |
| 6069 | for arg in child.children: |
| 6070 | if arg.type in ("identifier", "attribute"): |
| 6071 | bases.append(arg.text.decode("utf-8", errors="replace")) |
| 6072 | elif language == "java": |
| 6073 | # Java: superclass and super_interfaces wrap the keyword |
| 6074 | # (extends/implements) around type_identifier children. |
| 6075 | # Taking .text would include the keyword (e.g. "implements Foo"). |
| 6076 | # Drill into the children to extract bare type names. |
| 6077 | for child in node.children: |
| 6078 | if child.type == "superclass": |
| 6079 | for sub in child.children: |
| 6080 | if sub.type in ("type_identifier", "generic_type"): |
| 6081 | bases.append(sub.text.decode("utf-8", errors="replace")) |
| 6082 | elif child.type == "super_interfaces": |
| 6083 | for sub in child.children: |
| 6084 | if sub.type == "type_list": |
| 6085 | for ident in sub.children: |
| 6086 | if ident.type in ("type_identifier", "generic_type"): |
| 6087 | bases.append(ident.text.decode("utf-8", errors="replace")) |
| 6088 | elif language in ("csharp", "kotlin"): |
| 6089 | # Look for superclass/interfaces in extends/implements clauses |
| 6090 | for child in node.children: |
| 6091 | if child.type in ( |
| 6092 | "superclass", "super_interfaces", "extends_type", |
| 6093 | "implements_type", "type_identifier", "supertype", |
| 6094 | "delegation_specifier", |
| 6095 | ): |
| 6096 | text = child.text.decode("utf-8", errors="replace") |
| 6097 | bases.append(text) |
| 6098 | elif language == "scala": |
| 6099 | for child in node.children: |
| 6100 | if child.type == "extends_clause": |
| 6101 | for sub in child.children: |
| 6102 | if sub.type == "type_identifier": |
| 6103 | bases.append(sub.text.decode("utf-8", errors="replace")) |
| 6104 | elif sub.type == "generic_type": |
| 6105 | for ident in sub.children: |
| 6106 | if ident.type == "type_identifier": |
| 6107 | bases.append( |
| 6108 | ident.text.decode("utf-8", errors="replace") |
| 6109 | ) |
| 6110 | break |
| 6111 | elif language == "cpp": |
| 6112 | # C++: base_class_clause contains type_identifiers |
| 6113 | for child in node.children: |
| 6114 | if child.type == "base_class_clause": |
| 6115 | for sub in child.children: |
| 6116 | if sub.type == "type_identifier": |
| 6117 | bases.append(sub.text.decode("utf-8", errors="replace")) |
| 6118 | elif language in ("typescript", "javascript", "tsx"): |
| 6119 | # extends clause |
| 6120 | for child in node.children: |