fix: correct field ordering, helper placement, indentation, and blank lines in Java code replacer#1555
Merged
misrasaurabh1 merged 1 commit intoomni-javafrom Feb 20, 2026
Conversation
… lines in Java code replacer Four bugs in _insert_class_members / replace_function: 1. Extra indentation on injected methods (textwrap.dedent now normalises source before re-indenting) 2. New fields were prepended before existing ones (now inserted after the last existing field) 3. Helper methods were always appended at end of class (now placed before/after target based on their position in the optimised code) 4. No blank lines between consecutively injected helpers (each helper is now followed by a blank line) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes four bugs in
_insert_class_members/replace_functionincodeflash/languages/java/replacement.pythat caused incorrect output when an optimisation adds new static fields or helper methods to a Java class.Bug 1 – Extra indentation on injected methods: Extracted class members retained their original class-level whitespace prefix. When
_apply_indentationre-indented them it treated that existing whitespace as relative indentation and stacked the base indent on top, producing 12-space bodies instead of 8. Fixed by runningtextwrap.dedent()on each member source before re-indenting.Bug 2 – New fields inserted before existing ones: Fields were always injected at
body_node.start_byte + 1(right after{), pushing existing fields down. Fixed by finding the last existing field declaration viaanalyzer.find_fields(source, class_name=class_name)and inserting after it.Bug 3 – Helper methods always appended at end of class: All helpers landed after every existing method regardless of their intended position. Fixed by tracking each helper's index relative to the target method in the optimised code (
helpers_before_target/helpers_after_targetinParsedOptimization). Before-target helpers are now inserted immediately before the target method; after-target helpers are still appended at the end.Bug 4 – No blank lines between consecutively injected helpers: Multiple helpers were concatenated without separators. Fixed by appending
"\n"after each injected helper.Test plan
tests/test_languages/test_java/test_replacement.pyto reflect the now-correct outputtests/test_languages/suite: 1241 passed, 0 failed🤖 Generated with Claude Code