Fix sout expansion in unbraced for-loop bodies - #9595
Conversation
Preserve loop-header validation while accepting code templates in single-statement loop bodies. Add regression coverage for classic and enhanced for loops and incomplete headers. Assisted-by: GPT-5 Codex GPT-5
mbien
left a comment
There was a problem hiding this comment.
thanks, looks good so far!
We would require a proper email address in the commit header, you can check it by looking at the patch of the PR: https://github.com/apache/netbeans/pull/9595.patch
Github anonymizes the email address automatically if submitted via web interface, but there is a setting somewhere in your account options if you like to change it there. You can also fix the commit locally if you want. Once fixed you can force push into the PR.
(git commit --amend --author="Name <email@example.com>" --no-edit would change the mail of the last commit. git log to verify)
Its ok to edit the commit and force push into PR branches for this project, since we merge PRs as-is without squashing. So it should be only one commit before merge.
| assertSoutTemplateAccepted("public class Test {\n" | ||
| + " private void test() {\n" | ||
| + " for (int i = 0; i < 3; i++)\n" | ||
| + " sout\n" | ||
| + " }\n" | ||
| + "}", true); |
There was a problem hiding this comment.
nitpick: feel free to use multi line Strings. The editor has a hint to convert to it.
(same for the other new test cases you added)
Description
Fixes Apache NetBeans issue #5244. Java code templates such as
soutwere rejected when entered as the single-statement body of aforloop without braces.The filter already supported
FOR_LOOPandENHANCED_FOR_LOOP, but it applied a loop-header closing-parenthesis check to the body as well. The fix uses the loop statement source position to distinguish body context from header context, preserving the existing header validation.Tests
ant '-Dcluster.config=basic' build(baseline passed)ant -f java/java.editor/build.xml test-single -Dtest.includes=org/netbeans/modules/editor/java/JavaCodeTemplateProcessorTest.java(passed)forbody sequence expandssouttoSystem.out.println("");java.editorunit suite: unrelatedComputeImportsTestCRLF/LF fixture failures on Windows; other suites passedAssisted-by: GPT-5 Codex GPT-5