Skip to content

Java parser indexes return type as method name — Function nodes unresolvable for domain object return types #281

@eagle750

Description

@eagle750

Summary

For Java methods that return domain objects (non-primitive types), the
Tree-sitter parser incorrectly extracts the return type identifier as
the function node name instead of the actual method name. This makes
query_graph("callers_of", ...) and all function-level queries
unreliable for Java codebases.

Reproduction

# Create a Java class with domain object return types
cat > /tmp/test-repo/src/InvoiceService.java << 'EOF'
public class InvoiceService {
    public MyDomainObject processBusinessLogic(String param) {
        return new MyDomainObject();
    }
    public void simpleMethod(String param) {
        // void method — works correctly
    }
}
EOF

cd /tmp/test-repo
code-review-graph build

# Query by actual method name — returns 0 results
code-review-graph query_graph callers_of processBusinessLogic

Returns "summary": "Found 0 result(s)" despite the method
existing in the codebase.

Root cause

Raw node data in SQLite shows:
Function node name: MyDomainObject ← return type (WRONG)
Expected node name: processBusinessLogic ← method name (CORRECT)

The Tree-sitter Java grammar traversal is picking up the first
identifier in the method_declaration node (which is the return
type) instead of the identifier inside method_declarator.

Java AST structure:
method_declaration
modifiers
type_identifier ← "MyDomainObject" (being picked up incorrectly)
method_declarator
identifier ← "processBusinessLogic" (should be picked up)
formal_parameters

Affected queries

  • callers_of — always returns empty for methods with domain object return types
  • callees_of — same issue
  • query_graph function lookups — method nodes not found by actual name
  • semantic_search_nodes — indexes wrong names

Not affected

  • Methods returning primitives (void, int, String, boolean)
  • File-level features (get_architecture_overview, get_review_context)
  • get_impact_radius — uses file-level traversal, unaffected

Expected behavior

The function node name should always be the method name
(processBusinessLogic), not the return type (MyDomainObject).
The fix should target method_declarator → identifier in the
Java Tree-sitter grammar traversal inside parser.py.

Environment

  • code-review-graph v2.3.2
  • Java Spring Boot microservice codebase (500+ files)
  • macOS
  • Python 3.x

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions