Files
codegraph/__tests__/fixtures/kernel-parity/Torture.java
T
9181dd1ef3 fix(extraction): land upstream declaration initializer walks (#1511) (#1802)
Squash danusha2345's PR #1511 at d282f9e8 onto main 8c9c4761,
preserving its nine non-merge commits and main's existing Unreleased notes.
Calls in Kotlin, Java, TS/JS, Scala, Rust and Python declaration initializers
now retain the owner established by the upstream regression expectations.
Include the upstream CFML, dynamic-dispatch summary and viewer follow-ups.

Linux fail-to-pass validation (Node 22.19.0, rebuilt dist and native kernel):
- Before: TS load belonged to file:app.ts; Python/Kotlin/Scala/Rust calls
  vanished; Java lost the field-lambda, anonymous override and eager calls.
- After: all six languages PASS; 12 native/WASM LF/CRLF parity checks PASS.
- Focused initializer regressions: 10 passed with CODEGRAPH_KERNEL=0 and
  10 passed with the kernel enabled; Kotlin's grammar fallback is recorded.
- Related regression suites: 879 passed, 1 skipped across 15 test files.
- Evidence: /workspace/cg-1510-repro/before and /workspace/cg-1510-repro/after
  (combined test output: after/vitest.log).

Fixes #1510
Supersedes #1511

Co-authored-by: Colby McHenry <colbymchenry@users.noreply.github.com>
Co-authored-by: danusha2345 <ewidusoc498@gmail.com>
2026-09-08 17:33:45 -05:00

112 lines
2.8 KiB
Java

/**
* Java torture fixture — exercises every Java extraction path the kernel
* ports: package namespace, imports, javadoc, annotations, inheritance,
* fields/constants, enums, anonymous classes, method references, static
* member reads, fluent chains, Lombok synthesis, value refs + shadowing.
*/
package com.example.torture;
import java.util.List;
import java.util.Map;
import static java.util.Objects.requireNonNull;
import com.example.other.OtherClass;
import lombok.Data;
/** Javadoc for the service. */
@Service
@Component("torture")
public class TortureService extends BaseService implements Runnable, AutoCloseable {
/** A shared constant table (value-ref target). */
public static final Map<String, Integer> RETRY_LIMITS = Map.of("a", 1);
private static final String API_BASE = "https://example.test";
protected int count = 0;
private final List<String> names;
int packagePrivate, secondDeclarator;
/** Field initializers — walked scoped to the field (#693). */
private final Runnable fieldLambda = () -> helper(RETRY_LIMITS);
private final Runnable fieldAnonClass = new Runnable() {
@Override
public void run() {
helper(RETRY_LIMITS);
}
};
private final Runnable fieldMethodRef = TortureService::compute;
/** Ctor javadoc. */
public TortureService(List<String> names) {
this.names = requireNonNull(names);
register(this::onEvent);
queue(TortureService::compute);
queue(OtherClass::handle);
Runnable r = () -> helper(RETRY_LIMITS);
executor.submit(new Runnable() {
@Override
public void run() {
helper(RETRY_LIMITS);
}
});
}
@Override
@Deprecated
public void run() {
Config cfg = ConfigLoader.getInstance().load();
this.registry.lookup("x");
helper(Direction.UP);
String base = API_BASE;
int max = Limits.MAX_VALUE;
new StringBuilder(16).append(base);
}
private static Config helper(Object arg) {
return new Config();
}
private void onEvent() {}
private static void compute() {}
public void shadowed() {
String API_BASE = "local"; // shadows the class constant
log(API_BASE);
}
enum Direction {
UP,
DOWN;
Direction opposite() {
return this == UP ? DOWN : UP;
}
}
interface Listener {
void onChange(TortureService svc);
}
}
@Data
class LombokBean {
private String name;
private boolean isActive;
private final int id;
private static int counter;
private String toString; // taken: no synthetic toString field collision
public String getName() { return name; } // explicit getter — never overridden
}
@lombok.Getter
@lombok.extern.slf4j.Slf4j
@Builder
class LombokBuilderBean {
private List<String> items;
}
interface Shape extends Comparable<Shape>, Cloneable {
double area();
}
@interface Marker {
String value() default "";
}