Files
Colby Mchenry ad77e5fc8e fix(java,kotlin): extract enum constants' own bodies (#2194)
A Java enum constant or Kotlin enum entry with a class body -
`PLUS { int apply(...) { ... } }`, `NewBuffer { override fun pipe() ... }` - was
recorded as a bare enum_member: its body was never visited, so its methods
were missing and every call in them was dropped. jsoup's tokenizer
(`TokeniserState`, one `read` per state) and tree builder
(`HtmlTreeBuilderState`) are written this way.

The body is now visited under the member (QN `Op::PLUS::apply`), which
counts as class-like so its functions are methods and its properties fields.
Only a `class_body` child is visited, so Rust's struct-like variants (a
`body` field of field declarations) are untouched. Mirrored in the kernel's
Java and Kotlin walkers; kernel parity is byte-identical on the fixtures
(Torture.java gains a constant-with-body enum; torture.kt already had one)
and on gson/koin/okio.

jsoup +2156 edges, okio +138 -23, okhttp +106 -11, gson +97, halo +29,
commons-lang +16; koin, Exposed, mall unchanged.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 19:26:19 +00:00

133 lines
3.2 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;
}
}
enum Step {
NEXT(1) {
@Override
int apply(int at) {
return clamp(at + size);
}
},
BACK(-1) {
@Override
int apply(int at) { return at + size; }
};
final int size;
Step(int size) { this.size = size; }
abstract int apply(int at);
static int clamp(int at) { return Math.max(0, at); }
}
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 "";
}