The prek mypy hook runs on changed files and bypasses the pyproject.toml
tests/ exclude, surfacing pre-existing errors in both context.py and
test_context.py that block CI for this PR. Fixes applied:
- Import Language from language_enum instead of base (base re-exports are
not explicit; strict mypy flags attr-defined)
- Annotate _extract_class_declaration, _import_to_statement,
get_java_imported_type_skeletons, and resolved_imports
- Guard None start/end_line in _extract_function_source_by_lines and
find_helper_functions; guard None file_path in the import skeleton loop
- Drop unreachable `if not node: continue` in _extract_public_method_signatures
(JavaMethodNode.node is non-nullable)
- Add -> None to every test method and fix an `int | None` comparison in
test_context.py
All 880 Java tests pass after the change.
Wildcard imports like `import org.jooq.*` expand to 870+ types, causing
5 minutes of disk I/O per function before the token budget check kicks in.
89% of jOOQ functions were skipped due to this.
When a wildcard expands to >50 types, filter to only types referenced in
the target method's code. This turns a 5-minute failure into a <1 second
resolution with only the relevant types included.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- parser.py: add `is_class_nested` flag to `JavaMethodNode`; track
`class_depth` in `_walk_tree_for_methods` (incremented each time a
type declaration is entered) and set `is_class_nested = True` when
depth ≥ 2 (method lives inside a nested/inner class)
- discovery.py: add early-exit in `_should_include_method` when
`method.is_class_nested` is True — inner-class methods cannot be
reliably instrumented or tested in isolation, so we skip them up-front
rather than wasting LLM tokens on candidates that will always be
rejected later
- replacement.py: revert Bug-4 replacement-level workarounds that are
now obsolete:
* remove `target_class_name` parameter from `_parse_optimization_source`
* restore simple first-match `break` in target-method selection
* remove class_name filter that blocked helpers from "other" classes
- tests: update `TestNestedClasses`, `TestExtractCodeContextWithInnerClasses`
to reflect the new no-inner-class-discovery contract; remove
`TestInnerClassHelperFilter` (superseded by discovery filter);
add `TestInnerClassMethodFilter` in test_discovery.py with four
scenarios covering static nested, non-static inner, outer-only, and
deeply-nested classes
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Increase imported type skeleton token budget from 2000 to 4000
- Add constructor signature summary headers to skeleton output
- Expand wildcard imports (e.g., import com.foo.*) into individual types
instead of silently skipping them
- Prioritize skeleton processing for types referenced in the target method
so parameter types are guaranteed context before less-critical types
- Fix invalid [no-arg] annotation in constructor summaries
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Bug 4 (candidate_early_exit.py - 6 tests):
- All tests failed → 0 total passed (guard triggers)
- Some tests passed → nonzero (guard does not trigger)
- Empty results → 0 passed (guard triggers)
- Only non-loop1 results → ignored by report (guard triggers)
- Mixed test types all failing → 0 across all types
- Single passing among many failures → prevents early exit
Bug 3 edge cases (context.py - 8 tests):
- Wildcard imports are skipped (class_name=None)
- Import to nonexistent class returns None skeleton
- Skeleton output is well-formed Java (has braces)
- Protected and package-private methods excluded
- Overloaded public methods all extracted
- Generic method signatures extracted correctly
- Round-trip: _extract_type_skeleton → _format_skeleton_for_context
- Round-trip with real MathHelper fixture file
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
In --all mode, stale line numbers in FunctionToOptimize caused
InvalidJavaSyntaxError when a prior optimization modified the same file.
Now extract_function_source re-parses with tree-sitter to find methods
by name, matching how Python (jedi) and Java replacement already work.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Resolve merge conflict in code_replacer.py with Java-specific handling
- Update all Java modules to use FunctionToOptimize instead of FunctionInfo
- Add Language.JAVA to language_enum.py
- Update attribute names: name→function_name, start_line→starting_line, etc.
- Update all Java tests to use correct attribute names
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>