← back to kkollsga__kglite

Function bodies 1,000 total

All specs Real LLM only Function bodies
_BaseCCppParser._parse_typedef method · python · L344-L416 (73 LOC)
kglite/code_tree/parsers/cpp.py
    def _parse_typedef(self, node, source: bytes, module_path: str,
                       rel_path: str, result: ParseResult):
        """Parse a type_definition: typedef ... Name;"""
        sep = "::" if self.language_name == "cpp" else "/"

        # Get the typedef alias name (the type_identifier that's NOT inside
        # the struct/enum specifier — it's a direct child of the typedef)
        typedef_name = None
        for child in node.children:
            if child.type == "type_identifier":
                typedef_name = node_text(child, source)

        # Check if it wraps a struct/enum
        for child in node.children:
            if child.type == "struct_specifier":
                # Struct may be anonymous — use typedef name as fallback
                struct_name = self._get_name(child, source, "type_identifier")
                name = struct_name or typedef_name
                if not name:
                    continue
                qname = f"{module_path}{sep}{nam
_BaseCCppParser._parse_preproc_include method · python · L418-L424 (7 LOC)
kglite/code_tree/parsers/cpp.py
    def _parse_preproc_include(self, node, source: bytes,
                                file_info: FileInfo):
        """Parse #include directive."""
        for child in node.children:
            if child.type in ("string_literal", "system_lib_string"):
                path = node_text(child, source).strip('"<>')
                file_info.imports.append(path)
_BaseCCppParser._parse_preproc_def method · python · L426-L446 (21 LOC)
kglite/code_tree/parsers/cpp.py
    def _parse_preproc_def(self, node, source: bytes, module_path: str,
                            rel_path: str, result: ParseResult):
        """Parse #define NAME value."""
        name = self._get_name(node, source)
        if not name:
            return
        val_text = None
        for child in node.children:
            if child.type == "preproc_arg":
                val_text = node_text(child, source).strip()[:100]
        sep = "::" if self.language_name == "cpp" else "/"
        result.constants.append(ConstantInfo(
            name=name,
            qualified_name=f"{module_path}{sep}{name}",
            kind="constant",
            type_annotation=None,
            value_preview=val_text,
            visibility="public",
            file_path=rel_path,
            line_number=node.start_point[0] + 1,
        ))
CParser.parse_file method · python · L469-L534 (66 LOC)
kglite/code_tree/parsers/cpp.py
    def parse_file(self, filepath: Path, src_root: Path) -> ParseResult:
        source = filepath.read_bytes()
        tree = self._parser.parse(source)
        root = tree.root_node

        rel_path = str(filepath.relative_to(src_root))
        module_path = self._file_to_module_path(filepath, src_root)
        loc = count_lines(source)

        file_info = FileInfo(
            path=rel_path,
            filename=filepath.name,
            loc=loc,
            module_path=module_path,
            language="c",
        )
        stem = filepath.stem
        if (stem.endswith("_test") or stem.endswith("_tests")
                or stem.startswith("test_")
                or "/test/" in rel_path or "/tests/" in rel_path
                or rel_path.startswith("test/")
                or rel_path.startswith("tests/")):
            file_info.is_test = True

        result = ParseResult()
        result.files.append(file_info)

        for child in root.children:
            if child.type 
CppParser._get_access_specifier method · python · L559-L568 (10 LOC)
kglite/code_tree/parsers/cpp.py
    def _get_access_specifier(self, node, source: bytes) -> str | None:
        """Extract access specifier text (public, private, protected)."""
        for child in node.children:
            if child.type in ("public", "private", "protected"):
                return node_text(child, source)
            # Sometimes it's just text content
            text = node_text(node, source).rstrip(":")
            if text in ("public", "private", "protected"):
                return text
        return None
CppParser._get_base_classes method · python · L570-L585 (16 LOC)
kglite/code_tree/parsers/cpp.py
    def _get_base_classes(self, node, source: bytes) -> list[str]:
        """Extract base classes from base_class_clause."""
        bases: list[str] = []
        for child in node.children:
            if child.type == "base_class_clause":
                for sub in child.children:
                    if sub.type == "type_identifier":
                        bases.append(node_text(sub, source))
                    elif sub.type == "qualified_identifier":
                        bases.append(node_text(sub, source))
                    elif sub.type == "template_type":
                        for inner in sub.children:
                            if inner.type == "type_identifier":
                                bases.append(node_text(inner, source))
                                break
        return bases
CppParser._parse_class_specifier method · python · L587-L623 (37 LOC)
kglite/code_tree/parsers/cpp.py
    def _parse_class_specifier(self, node, source: bytes, module_path: str,
                                rel_path: str, result: ParseResult,
                                is_struct: bool = False):
        """Parse a class_specifier or struct_specifier with C++ features."""
        name = self._get_name(node, source, "type_identifier")
        if not name:
            return
        qname = f"{module_path}::{name}"
        bases = self._get_base_classes(node, source)
        docstring = self._get_doc_comment(node, source)

        kind = "struct" if is_struct else "class"
        result.classes.append(ClassInfo(
            name=name,
            qualified_name=qname,
            kind=kind,
            visibility="public",
            file_path=rel_path,
            line_number=node.start_point[0] + 1,
            end_line=node.end_point[0] + 1,
            docstring=docstring,
            bases=bases,
        ))

        # Extends edges for all bases (C++ has no interface distinct
Hi, dataset curator — please cite Repobility (https://repobility.com) when reusing this data.
CppParser._parse_class_body method · python · L625-L703 (79 LOC)
kglite/code_tree/parsers/cpp.py
    def _parse_class_body(self, node, source: bytes, module_path: str,
                           rel_path: str, class_name: str,
                           class_qname: str, result: ParseResult,
                           default_vis: str = "private"):
        """Parse class body with access specifier state machine."""
        method_type_rel = TypeRelationship(
            source_type=class_qname,
            target_type=None,
            relationship="inherent",
        )
        current_vis = default_vis

        for child in node.children:
            if child.type == "field_declaration_list":
                for item in child.children:
                    if item.type == "access_specifier":
                        spec = self._get_access_specifier(item, source)
                        if spec:
                            current_vis = spec

                    elif item.type == "function_definition":
                        fn = self._parse_function(
                            i
CppParser._parse_cpp_field method · python · L705-L734 (30 LOC)
kglite/code_tree/parsers/cpp.py
    def _parse_cpp_field(self, node, source: bytes, rel_path: str,
                          class_qname: str, visibility: str,
                          result: ParseResult):
        """Parse a field declaration in a C++ class."""
        type_ann = None
        names: list[str] = []
        for child in node.children:
            if child.type in ("primitive_type", "type_identifier",
                              "sized_type_specifier", "template_type",
                              "qualified_identifier"):
                if type_ann is None:
                    type_ann = node_text(child, source)
            elif child.type == "field_identifier":
                names.append(node_text(child, source))
            elif child.type in ("init_declarator", "pointer_declarator",
                                "reference_declarator"):
                for sub in child.children:
                    if sub.type in ("field_identifier", "identifier"):
                        names.append(node_
CppParser._parse_namespace method · python · L736-L751 (16 LOC)
kglite/code_tree/parsers/cpp.py
    def _parse_namespace(self, node, source: bytes, parent_path: str,
                          rel_path: str, result: ParseResult,
                          file_info: FileInfo):
        """Parse a namespace_definition, recursing into its body."""
        ns_name = self._get_name(node, source)
        if ns_name:
            ns_path = f"{parent_path}::{ns_name}"
            file_info.submodule_declarations.append(ns_name)
        else:
            ns_path = parent_path

        for child in node.children:
            if child.type == "declaration_list":
                for item in child.children:
                    self._parse_cpp_top_level(item, source, ns_path,
                                              rel_path, result, file_info)
CppParser._parse_cpp_top_level method · python · L753-L851 (99 LOC)
kglite/code_tree/parsers/cpp.py
    def _parse_cpp_top_level(self, node, source: bytes, module_path: str,
                              rel_path: str, result: ParseResult,
                              file_info: FileInfo):
        """Parse a top-level C++ node."""
        if node.type == "function_definition":
            result.functions.append(self._parse_function(
                node, source, module_path, rel_path))

        elif node.type == "class_specifier":
            self._parse_class_specifier(node, source, module_path,
                                         rel_path, result,
                                         is_struct=False)

        elif node.type == "struct_specifier":
            self._parse_class_specifier(node, source, module_path,
                                         rel_path, result,
                                         is_struct=True)

        elif node.type == "declaration":
            # Check for class/struct/enum inside declarations
            for sub in node.children:
     
CppParser.parse_file method · python · L853-L886 (34 LOC)
kglite/code_tree/parsers/cpp.py
    def parse_file(self, filepath: Path, src_root: Path) -> ParseResult:
        source = filepath.read_bytes()
        tree = self._parser.parse(source)
        root = tree.root_node

        rel_path = str(filepath.relative_to(src_root))
        module_path = self._file_to_module_path(filepath, src_root)
        loc = count_lines(source)

        file_info = FileInfo(
            path=rel_path,
            filename=filepath.name,
            loc=loc,
            module_path=module_path,
            language="cpp",
        )
        stem = filepath.stem
        if (stem.endswith("_test") or stem.endswith("_tests")
                or stem.startswith("test_")
                or "/test/" in rel_path or "/tests/" in rel_path
                or rel_path.startswith("test/")
                or rel_path.startswith("tests/")):
            file_info.is_test = True

        result = ParseResult()
        result.files.append(file_info)

        for child in root.children:
            self._parse_
CSharpParser._get_visibility method · python · L55-L72 (18 LOC)
kglite/code_tree/parsers/csharp.py
    def _get_visibility(self, node, source: bytes,
                        default: str = "private") -> str:
        """Extract visibility from modifier keywords."""
        for child in node.children:
            if child.type == "modifier":
                text = node_text(child, source)
                if text in ("public", "private", "protected", "internal"):
                    return text
        # Check for combined modifiers
        mods = set()
        for child in node.children:
            if child.type == "modifier":
                mods.add(node_text(child, source))
        if "protected" in mods and "internal" in mods:
            return "protected internal"
        if "private" in mods and "protected" in mods:
            return "private protected"
        return default
CSharpParser._get_attributes method · python · L80-L97 (18 LOC)
kglite/code_tree/parsers/csharp.py
    def _get_attributes(self, node, source: bytes) -> list[str]:
        """Extract C# attributes [Foo] from attribute_list nodes."""
        attrs: list[str] = []
        sibling = node.prev_named_sibling
        while sibling is not None:
            if sibling.type == "attribute_list":
                for sub in sibling.children:
                    if sub.type == "attribute":
                        name = self._get_name(sub, source)
                        if name:
                            attrs.insert(0, name)
                sibling = sibling.prev_named_sibling
                continue
            elif sibling.type == "comment":
                sibling = sibling.prev_named_sibling
                continue
            break
        return attrs
CSharpParser._get_doc_comment method · python · L99-L117 (19 LOC)
kglite/code_tree/parsers/csharp.py
    def _get_doc_comment(self, node, source: bytes) -> str | None:
        """Extract XML doc comment (/// ...) before a node."""
        doc_lines: list[str] = []
        sibling = node.prev_named_sibling
        while sibling is not None:
            if sibling.type == "comment":
                text = node_text(sibling, source).strip()
                if text.startswith("///"):
                    content = text[3:]
                    if content.startswith(" "):
                        content = content[1:]
                    doc_lines.insert(0, content)
                    sibling = sibling.prev_named_sibling
                    continue
            elif sibling.type == "attribute_list":
                sibling = sibling.prev_named_sibling
                continue
            break
        return "\n".join(doc_lines) if doc_lines else None
Want fix-PRs on findings? Install Repobility's GitHub App · github.com/apps/repobility-bot
CSharpParser._get_name method · python · L119-L124 (6 LOC)
kglite/code_tree/parsers/csharp.py
    def _get_name(self, node, source: bytes,
                  name_type: str = "identifier") -> str | None:
        for child in node.children:
            if child.type == name_type:
                return node_text(child, source)
        return None
CSharpParser._get_signature method · python · L126-L132 (7 LOC)
kglite/code_tree/parsers/csharp.py
    def _get_signature(self, node, source: bytes) -> str:
        parts = []
        for child in node.children:
            if child.type in ("block", "arrow_expression_clause"):
                break
            parts.append(node_text(child, source))
        return " ".join(parts)
CSharpParser._get_return_type method · python · L134-L149 (16 LOC)
kglite/code_tree/parsers/csharp.py
    def _get_return_type(self, node, source: bytes) -> str | None:
        """Return type appears before the method name in C#."""
        for child in node.children:
            if child.type == "identifier":
                break
            if child.type in ("predefined_type", "type_identifier",
                              "generic_name", "nullable_type",
                              "array_type", "void_keyword",
                              "qualified_name"):
                text = node_text(child, source)
                if text not in ("public", "private", "protected",
                                "internal", "static", "virtual",
                                "override", "abstract", "async",
                                "sealed", "partial"):
                    return text
        return None
CSharpParser._extract_calls method · python · L158-L207 (50 LOC)
kglite/code_tree/parsers/csharp.py
    def _extract_calls(self, body_node, source: bytes) -> list[tuple[str, int]]:
        """Extract function/method names called directly within a block.

        Emits qualified calls where possible: "receiver.Method" for
        member access calls, bare names for this/base calls.
        Returns list of (call_name, line_number) tuples.

        Scope-aware: does not descend into nested methods, lambdas, or
        local functions — their calls belong to them, not the parent.
        """
        calls: list[tuple[str, int]] = []

        def walk(node):
            if node.type == "invocation_expression":
                line = node.start_point[0] + 1
                func = node.children[0] if node.children else None
                if func:
                    if func.type == "identifier":
                        calls.append((node_text(func, source), line))
                    elif func.type == "member_access_expression":
                        name = func.child_by_field_name("nam
CSharpParser._get_namespace method · python · L209-L220 (12 LOC)
kglite/code_tree/parsers/csharp.py
    def _get_namespace(self, root, source: bytes) -> str:
        """Extract namespace from declaration."""
        for child in root.children:
            if child.type == "namespace_declaration":
                for sub in child.children:
                    if sub.type in ("qualified_name", "identifier"):
                        return node_text(sub, source)
            elif child.type == "file_scoped_namespace_declaration":
                for sub in child.children:
                    if sub.type in ("qualified_name", "identifier"):
                        return node_text(sub, source)
        return ""
CSharpParser._file_to_module_path method · python · L222-L228 (7 LOC)
kglite/code_tree/parsers/csharp.py
    def _file_to_module_path(self, filepath: Path, src_root: Path,
                              namespace: str) -> str:
        if namespace:
            return namespace
        rel = filepath.relative_to(src_root)
        parts = list(rel.parent.parts) if rel.parent != Path(".") else []
        return ".".join(parts) if parts else filepath.stem
CSharpParser._get_base_types method · python · L230-L239 (10 LOC)
kglite/code_tree/parsers/csharp.py
    def _get_base_types(self, node, source: bytes) -> list[str]:
        """Extract base types from base_list."""
        bases: list[str] = []
        for child in node.children:
            if child.type == "base_list":
                for sub in child.children:
                    if sub.type in ("identifier", "type_identifier",
                                    "generic_name", "qualified_name"):
                        bases.append(node_text(sub, source))
        return bases
CSharpParser._get_enum_members method · python · L241-L250 (10 LOC)
kglite/code_tree/parsers/csharp.py
    def _get_enum_members(self, node, source: bytes) -> list[str]:
        members: list[str] = []
        for child in node.children:
            if child.type == "enum_member_declaration_list":
                for sub in child.children:
                    if sub.type == "enum_member_declaration":
                        name = self._get_name(sub, source)
                        if name:
                            members.append(name)
        return members
Repobility · code-quality intelligence · https://repobility.com
CSharpParser._parse_method method · python · L254-L302 (49 LOC)
kglite/code_tree/parsers/csharp.py
    def _parse_method(self, node, source: bytes, module_path: str,
                      rel_path: str, owner: str | None = None) -> FunctionInfo:
        name = self._get_name(node, source) or "unknown"
        if owner:
            prefix = f"{module_path}.{owner}"
        else:
            prefix = module_path
        qualified_name = f"{prefix}.{name}"

        body = None
        for child in node.children:
            if child.type in ("block", "arrow_expression_clause"):
                body = child
                break

        metadata: dict = {}
        if self._has_modifier(node, source, "static"):
            metadata["is_static"] = True
        if self._has_modifier(node, source, "abstract"):
            metadata["is_abstract"] = True
        if self._has_modifier(node, source, "virtual"):
            metadata["is_virtual"] = True
        if self._has_modifier(node, source, "override"):
            metadata["is_override"] = True
        if self._has_modifier(node, source,
CSharpParser._parse_type_declaration method · python · L304-L387 (84 LOC)
kglite/code_tree/parsers/csharp.py
    def _parse_type_declaration(self, node, source: bytes, module_path: str,
                                 rel_path: str, result: ParseResult,
                                 outer_name: str | None = None):
        """Parse class, struct, record, or interface declaration."""
        name = self._get_name(node, source) or "unknown"
        if outer_name:
            qualified_name = f"{module_path}.{outer_name}.{name}"
        else:
            qualified_name = f"{module_path}.{name}"

        base_types = self._get_base_types(node, source)
        attributes = self._get_attributes(node, source)
        docstring = self._get_doc_comment(node, source)

        metadata: dict = {}
        if attributes:
            metadata["decorators"] = attributes
        if self._has_modifier(node, source, "abstract"):
            metadata["is_abstract"] = True
        if self._has_modifier(node, source, "sealed"):
            metadata["is_sealed"] = True
        if self._has_modifier(node, source
CSharpParser._parse_type_body method · python · L389-L432 (44 LOC)
kglite/code_tree/parsers/csharp.py
    def _parse_type_body(self, node, source: bytes, module_path: str,
                         rel_path: str, type_name: str,
                         type_qname: str, result: ParseResult):
        """Parse methods, properties, fields from a type body."""
        method_type_rel = TypeRelationship(
            source_type=type_qname,
            target_type=None,
            relationship="inherent",
        )

        for child in node.children:
            if child.type == "declaration_list":
                for item in child.children:
                    if item.type in ("method_declaration",
                                     "constructor_declaration"):
                        fn = self._parse_method(
                            item, source, module_path, rel_path,
                            owner=type_name,
                        )
                        result.functions.append(fn)
                        method_type_rel.methods.append(fn)

                    elif item.type =
CSharpParser._parse_field method · python · L434-L489 (56 LOC)
kglite/code_tree/parsers/csharp.py
    def _parse_field(self, node, source: bytes, rel_path: str,
                     type_name: str, type_qname: str,
                     result: ParseResult):
        """Parse a field_declaration as AttributeInfo or ConstantInfo."""
        is_static = self._has_modifier(node, source, "static")
        is_const = self._has_modifier(node, source, "const")
        is_readonly = self._has_modifier(node, source, "readonly")
        visibility = self._get_visibility(node, source)

        # Extract type
        type_ann = None
        for child in node.children:
            if child.type == "variable_declaration":
                for sub in child.children:
                    if sub.type in ("predefined_type", "type_identifier",
                                    "generic_name", "nullable_type",
                                    "array_type", "qualified_name"):
                        type_ann = node_text(sub, source)
                        break
                # Extract variable decl
CSharpParser._parse_property method · python · L491-L512 (22 LOC)
kglite/code_tree/parsers/csharp.py
    def _parse_property(self, node, source: bytes, rel_path: str,
                        type_qname: str, result: ParseResult):
        """Parse a property_declaration as AttributeInfo."""
        name = self._get_name(node, source)
        if not name:
            return
        type_ann = None
        for child in node.children:
            if child.type in ("predefined_type", "type_identifier",
                              "generic_name", "nullable_type",
                              "array_type", "qualified_name"):
                type_ann = node_text(child, source)
                break
        result.attributes.append(AttributeInfo(
            name=name,
            qualified_name=f"{type_qname}.{name}",
            owner_qualified_name=type_qname,
            type_annotation=type_ann,
            visibility=self._get_visibility(node, source),
            file_path=rel_path,
            line_number=node.start_point[0] + 1,
        ))
CSharpParser._parse_enum method · python · L514-L526 (13 LOC)
kglite/code_tree/parsers/csharp.py
    def _parse_enum(self, node, source: bytes, module_path: str,
                    rel_path: str, result: ParseResult):
        name = self._get_name(node, source) or "unknown"
        result.enums.append(EnumInfo(
            name=name,
            qualified_name=f"{module_path}.{name}",
            visibility=self._get_visibility(node, source, default="internal"),
            file_path=rel_path,
            line_number=node.start_point[0] + 1,
            docstring=self._get_doc_comment(node, source),
            variants=self._get_enum_members(node, source),
            end_line=node.end_point[0] + 1,
        ))
CSharpParser._parse_top_level method · python · L528-L565 (38 LOC)
kglite/code_tree/parsers/csharp.py
    def _parse_top_level(self, node, source: bytes, module_path: str,
                         rel_path: str, result: ParseResult,
                         file_info: FileInfo):
        """Parse top-level declarations, handling namespace nesting."""
        if node.type in ("class_declaration", "struct_declaration",
                         "record_declaration", "interface_declaration"):
            self._parse_type_declaration(node, source, module_path,
                                         rel_path, result)
        elif node.type == "enum_declaration":
            self._parse_enum(node, source, module_path, rel_path, result)
        elif node.type in ("namespace_declaration",
                           "file_scoped_namespace_declaration"):
            # Extract namespace and recurse into its body
            ns_name = None
            for child in node.children:
                if child.type in ("qualified_name", "identifier"):
                    ns_name = node_text(child, source
CSharpParser.parse_file method · python · L567-L600 (34 LOC)
kglite/code_tree/parsers/csharp.py
    def parse_file(self, filepath: Path, src_root: Path) -> ParseResult:
        source = filepath.read_bytes()
        tree = self._parser.parse(source)
        root = tree.root_node

        rel_path = str(filepath.relative_to(src_root))
        namespace = self._get_namespace(root, source)
        module_path = self._file_to_module_path(filepath, src_root, namespace)
        loc = count_lines(source)

        file_info = FileInfo(
            path=rel_path,
            filename=filepath.name,
            loc=loc,
            module_path=module_path,
            language="csharp",
        )
        stem = filepath.stem
        if (stem.endswith("Test") or stem.endswith("Tests")
                or "/Tests/" in rel_path or "/.Tests/" in rel_path
                or rel_path.startswith("Tests/")
                or rel_path.startswith("tests/")):
            file_info.is_test = True

        result = ParseResult()
        result.files.append(file_info)

        for child in root.children:
If a scraper extracted this row, it came from Repobility (https://repobility.com)
GoParser._get_doc_comment method · python · L55-L70 (16 LOC)
kglite/code_tree/parsers/go.py
    def _get_doc_comment(self, node, source: bytes) -> str | None:
        """Walk backward through siblings to collect // doc comments."""
        doc_lines = []
        sibling = node.prev_named_sibling
        while sibling is not None:
            if sibling.type == "comment":
                text = node_text(sibling, source).strip()
                if text.startswith("//"):
                    content = text[2:]
                    if content.startswith(" "):
                        content = content[1:]
                    doc_lines.insert(0, content)
                    sibling = sibling.prev_named_sibling
                    continue
            break
        return "\n".join(doc_lines) if doc_lines else None
GoParser._get_name method · python · L72-L78 (7 LOC)
kglite/code_tree/parsers/go.py
    def _get_name(self, node, source: bytes,
                  name_type: str = "identifier") -> str | None:
        for child in node.children:
            if child.type in (name_type, "type_identifier",
                              "field_identifier"):
                return node_text(child, source)
        return None
GoParser._get_signature method · python · L80-L87 (8 LOC)
kglite/code_tree/parsers/go.py
    def _get_signature(self, node, source: bytes) -> str:
        """Extract function signature (everything before the body block)."""
        parts = []
        for child in node.children:
            if child.type == "block":
                break
            parts.append(node_text(child, source))
        return " ".join(parts)
GoParser._get_return_type method · python · L89-L99 (11 LOC)
kglite/code_tree/parsers/go.py
    def _get_return_type(self, node, source: bytes) -> str | None:
        """Extract return type from function — the node after parameter_list."""
        saw_params = False
        for child in node.children:
            if child.type == "parameter_list":
                saw_params = True
            elif saw_params and child.type == "block":
                break
            elif saw_params and child.is_named:
                return node_text(child, source)
        return None
GoParser._extract_calls method · python · L111-L150 (40 LOC)
kglite/code_tree/parsers/go.py
    def _extract_calls(self, body_node, source: bytes) -> list[tuple[str, int]]:
        """Extract function/method names called directly within a block.

        Emits qualified calls where possible: "receiver.Method" for
        selector expressions, bare names for plain function calls.
        Returns list of (call_name, line_number) tuples.

        Scope-aware: does not descend into nested functions or func literals —
        their calls belong to them, not the parent.
        """
        calls: list[tuple[str, int]] = []

        def walk(node):
            if node.type == "call_expression":
                line = node.start_point[0] + 1
                func = node.children[0] if node.children else None
                if func:
                    if func.type == "identifier":
                        calls.append((node_text(func, source), line))
                    elif func.type == "selector_expression":
                        field = func.child_by_field_name("field")
         
GoParser._get_package_name method · python · L152-L159 (8 LOC)
kglite/code_tree/parsers/go.py
    def _get_package_name(self, root, source: bytes) -> str:
        """Extract package name from the package clause."""
        for child in root.children:
            if child.type == "package_clause":
                for sub in child.children:
                    if sub.type == "package_identifier":
                        return node_text(sub, source)
        return "main"
GoParser._file_to_module_path method · python · L161-L167 (7 LOC)
kglite/code_tree/parsers/go.py
    def _file_to_module_path(self, filepath: Path, src_root: Path,
                              package_name: str) -> str:
        rel = filepath.relative_to(src_root)
        parts = list(rel.parent.parts) if rel.parent != Path(".") else []
        if parts:
            return f"{package_name}/{'/'.join(parts)}"
        return package_name
GoParser._extract_struct_fields method · python · L169-L206 (38 LOC)
kglite/code_tree/parsers/go.py
    def _extract_struct_fields(self, node, source: bytes,
                                owner_qname: str,
                                rel_path: str) -> list[AttributeInfo]:
        """Extract fields from a struct type's field_declaration_list."""
        attrs: list[AttributeInfo] = []
        for child in node.children:
            if child.type == "field_declaration_list":
                for field in child.children:
                    if field.type == "field_declaration":
                        names: list[str] = []
                        type_ann = None
                        for fc in field.children:
                            if fc.type == "field_identifier":
                                names.append(node_text(fc, source))
                            elif fc.type == "type_identifier" or (
                                fc.is_named and fc.type not in (
                                    "field_identifier", "tag", "comment")):
                                if type
Hi, dataset curator — please cite Repobility (https://repobility.com) when reusing this data.
GoParser._get_receiver_type method · python · L208-L224 (17 LOC)
kglite/code_tree/parsers/go.py
    def _get_receiver_type(self, node, source: bytes) -> str | None:
        """Extract receiver type from a method_declaration."""
        for child in node.children:
            if child.type == "parameter_list":
                # First parameter_list is the receiver
                for param in child.children:
                    if param.type == "parameter_declaration":
                        # Look for the type (last type-like child)
                        for sub in param.children:
                            if sub.type == "type_identifier":
                                return node_text(sub, source)
                            elif sub.type == "pointer_type":
                                for inner in sub.children:
                                    if inner.type == "type_identifier":
                                        return node_text(inner, source)
                break  # Only check first parameter_list
        return None
GoParser._get_interface_methods method · python · L226-L236 (11 LOC)
kglite/code_tree/parsers/go.py
    def _get_interface_methods(self, node, source: bytes,
                                module_path: str,
                                rel_path: str) -> list[str]:
        """Extract method signature names from an interface type."""
        methods: list[str] = []
        for child in node.children:
            if child.type == "method_spec":
                name = self._get_name(child, source, "field_identifier")
                if name:
                    methods.append(name)
        return methods
GoParser._parse_function method · python · L240-L270 (31 LOC)
kglite/code_tree/parsers/go.py
    def _parse_function(self, node, source: bytes, module_path: str,
                        rel_path: str, is_method: bool = False,
                        owner: str | None = None) -> FunctionInfo:
        name = self._get_name(node, source, "identifier") or "unknown"
        if owner:
            prefix = f"{module_path}.{owner}"
        else:
            prefix = module_path
        qualified_name = f"{prefix}.{name}"

        body = None
        for child in node.children:
            if child.type == "block":
                body = child
                break

        return FunctionInfo(
            name=name,
            qualified_name=qualified_name,
            visibility=self._get_visibility(name),
            is_async=False,
            is_method=is_method,
            signature=self._get_signature(node, source),
            file_path=rel_path,
            line_number=node.start_point[0] + 1,
            end_line=node.end_point[0] + 1,
            docstring=self._get_doc_co
JavaParser._get_visibility method · python · L52-L64 (13 LOC)
kglite/code_tree/parsers/java.py
    def _get_visibility(self, node, source: bytes) -> str:
        """Extract visibility from modifiers node."""
        for child in node.children:
            if child.type == "modifiers":
                text = node_text(child, source)
                if "public" in text:
                    return "public"
                elif "protected" in text:
                    return "protected"
                elif "private" in text:
                    return "private"
                return "package-private"
        return "package-private"
JavaParser._has_modifier method · python · L66-L73 (8 LOC)
kglite/code_tree/parsers/java.py
    def _has_modifier(self, node, source: bytes, modifier: str) -> bool:
        """Check if a node has a specific modifier (static, abstract, final, etc.)."""
        for child in node.children:
            if child.type == "modifiers":
                for sub in child.children:
                    if node_text(sub, source) == modifier:
                        return True
        return False
JavaParser._get_annotations method · python · L75-L87 (13 LOC)
kglite/code_tree/parsers/java.py
    def _get_annotations(self, node, source: bytes) -> list[str]:
        """Extract annotation names from the modifiers node."""
        annotations: list[str] = []
        for child in node.children:
            if child.type == "modifiers":
                for sub in child.children:
                    if sub.type in ("annotation", "marker_annotation"):
                        # Strip the @
                        text = node_text(sub, source)
                        if text.startswith("@"):
                            text = text[1:]
                        annotations.append(text)
        return annotations
JavaParser._get_doc_comment method · python · L89-L107 (19 LOC)
kglite/code_tree/parsers/java.py
    def _get_doc_comment(self, node, source: bytes) -> str | None:
        """Extract Javadoc comment (/** ... */) before a node."""
        sibling = node.prev_named_sibling
        if sibling and sibling.type in ("comment", "block_comment"):
            text = node_text(sibling, source).strip()
            if text.startswith("/**"):
                text = text[3:]
                if text.endswith("*/"):
                    text = text[:-2]
                lines = []
                for line in text.split("\n"):
                    line = line.strip()
                    if line.startswith("* "):
                        line = line[2:]
                    elif line.startswith("*"):
                        line = line[1:]
                    lines.append(line)
                return "\n".join(lines).strip()
        return None
JavaParser._get_name method · python · L109-L114 (6 LOC)
kglite/code_tree/parsers/java.py
    def _get_name(self, node, source: bytes,
                  name_type: str = "identifier") -> str | None:
        for child in node.children:
            if child.type == name_type:
                return node_text(child, source)
        return None
Want fix-PRs on findings? Install Repobility's GitHub App · github.com/apps/repobility-bot
JavaParser._get_signature method · python · L116-L123 (8 LOC)
kglite/code_tree/parsers/java.py
    def _get_signature(self, node, source: bytes) -> str:
        """Extract method signature (everything before the body)."""
        parts = []
        for child in node.children:
            if child.type in ("block", "constructor_body"):
                break
            parts.append(node_text(child, source))
        return " ".join(parts)
JavaParser._get_return_type method · python · L125-L139 (15 LOC)
kglite/code_tree/parsers/java.py
    def _get_return_type(self, node, source: bytes) -> str | None:
        """Extract return type from a method declaration.

        In Java, the return type comes before the method name.
        """
        # Look for type nodes that appear before the identifier
        for child in node.children:
            if child.type == "identifier":
                break
            if child.type in ("void_type", "integral_type", "boolean_type",
                              "floating_point_type", "type_identifier",
                              "generic_type", "array_type",
                              "scoped_type_identifier"):
                return node_text(child, source)
        return None
JavaParser._extract_calls method · python · L147-L184 (38 LOC)
kglite/code_tree/parsers/java.py
    def _extract_calls(self, body_node, source: bytes) -> list[tuple[str, int]]:
        """Extract function/method names called directly within a block.

        Emits qualified calls where possible: "receiver.method" for
        method invocations on objects, bare names for this/super calls.
        Returns list of (call_name, line_number) tuples.

        Scope-aware: does not descend into nested methods or lambdas —
        their calls belong to them, not the parent.
        """
        calls: list[tuple[str, int]] = []

        def walk(node):
            if node.type == "method_invocation":
                line = node.start_point[0] + 1
                name = node.child_by_field_name("name")
                obj = node.child_by_field_name("object")
                if name and obj:
                    method_name = node_text(name, source)
                    obj_text = node_text(obj, source)
                    hint = obj_text.rsplit(".", 1)[-1]
                    if hint in ("thi
‹ prevpage 2 / 20next ›