fix(java): link new-expression to constructor and class instantiation#658
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds support for tracking Java object creation expressions (new Foo(...)) as call nodes. It updates constants, handles TS_OBJECT_CREATION_EXPRESSION in the call processor to resolve the class name, and routes CALLS edges to all declared constructors of the instantiated class. Additionally, a new test suite is added to verify these relationships. There are no review comments, so I have no feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Greptile SummaryThis PR links Java
Confidence Score: 5/5Safe to merge with minimal risk. The change is tightly scoped to Java object creation handling and keeps the new behavior language-gated. The constructor path includes guards for non-class targets and tests for the key simple, overloaded, generic, and scoped cases. No files require special attention.
What T-Rex did
Important Files Changed
Sequence Diagram%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant JavaAST as Java AST
participant Query as LANGUAGE_SPECS call_query
participant Processor as CallProcessor
participant Resolver as CallResolver
participant Graph as Graph relationships
JavaAST->>Query: object_creation_expression type capture
Query->>Processor: call_node new X(...)
Processor->>Processor: extract type name and strip generic args
Processor->>Resolver: resolve_function_call(type_name)
Resolver-->>Processor: resolved class qualified name
Processor->>Graph: "INSTANTIATES caller -> class"
Processor->>Resolver: java_constructor_targets(class_qn)
Resolver-->>Processor: direct declared constructors
Processor->>Graph: "CALLS caller -> constructor(s)"
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant JavaAST as Java AST
participant Query as LANGUAGE_SPECS call_query
participant Processor as CallProcessor
participant Resolver as CallResolver
participant Graph as Graph relationships
JavaAST->>Query: object_creation_expression type capture
Query->>Processor: call_node new X(...)
Processor->>Processor: extract type name and strip generic args
Processor->>Resolver: resolve_function_call(type_name)
Resolver-->>Processor: resolved class qualified name
Processor->>Graph: "INSTANTIATES caller -> class"
Processor->>Resolver: java_constructor_targets(class_qn)
Resolver-->>Processor: direct declared constructors
Processor->>Graph: "CALLS caller -> constructor(s)"
Reviews (2): Last reviewed commit: "fix(java): capture generic and scoped ne..." | Re-trigger Greptile |
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…class construction
|
@greptile review |
|



Found by dogfooding the dead-code eval on google/gson (Java's first dead-code dogfood). Drives gson core from 114 to 92 false positives by fixing the single largest class.
The class: Java
new X(...)never linked to constructorsSPEC_JAVA_CALL_TYPEScollected onlymethod_invocation, neverobject_creation_expression, sonew X(...)produced no INSTANTIATES edge to the class and no CALLS edge to the constructor. Every constructor reached only vianewtherefore looked dead (45 of gson's 114 false positives).Fix (mirrors the JS
new_expression/ Python class-call path)object_creation_expressiontoSPEC_JAVA_CALL_TYPES._get_call_target_namenames a Javaobject_creation_expressionby itstypefield (strips generic args, e.g.new ArrayList<T>()->ArrayList; a scopedOuter.Inneris left for the resolver), routing construction through the normal resolve loop.java_constructor_targetshelper. A Java constructor is registered as a method named like its class (Foo.Foo(int)); the helper matches only constructors DIRECTLY on the class (a nested class's constructor has an extra qn segment and is excluded). Argument-type overload selection is not attempted, which is unnecessary for reachability and never fabricates a call to a non-constructor.Tests
test_java_constructor_calls.py: anew X(...)both instantiates the class and calls the constructor; an overloaded class has every constructor reached.Verified: gson 114 -> 92, full suite green (4427 passed), 522 Java tests pass, no cross-language effect (every new path is
language == JAVA-gated).