Repository navigation
Conversation
- apache#9841 - A throw statement is an ExpressionStatement with a ThrowExpression since PHP 8.0 support (NETBEANS-4443). visit(ExpressionStatement) added the indent of a statement to it, and visit(MethodInvocation) added the indent of the chain, so the lines of a chain after throw got the continuation indent twice - Look through the ThrowExpression when deciding whether the statement adds an indent, as is done for a method call statement - Add unit tests The change and the tests were written with the help of an AI model and were not run: the formatter tests were not built or executed, only the changed class was compiled against the jars of NetBeans 31. The expected files are written by hand. The author is not a Java developer. Assisted-by: Claude Sonnet 5.5
Contributor
|
@zeleznypa thanks for taking care. As I struggle to remember the correct way to force push into a foreign branch, I decided to create a new PR instead, that picks this up. Changes there:
Could you please have a look and indicate if that is fine with you? If so I'll ping the primary PHP reviewers to get their opinion. Thank you! |
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.
Fixes #9841.
What
The PHP formatter indents the lines of a method chain after
throwtwice: 8 spaces with Continuation Indentation 4. After an assignment, and in a plain call statement, the same chain gets 4 spaces.Why
Since the PHP 8.0 support (NETBEANS-4443, 2020)
throwis an expression, sothrow ...;is anExpressionStatementthat holds aThrowExpression.visit(ExpressionStatement)adds one continuation indent to every expression statement except a method call, andvisit(MethodInvocation)adds a second one for the chain.throwis not excluded from the first one, so it gets both (4 + 4). The links to the code lines and the history are in #9841.Change
visit(ExpressionStatement)looks through theThrowExpressionwhen it decides whether the statement adds an indent (new private methodisMethodCall). Athrowof a method call is treated like a plain method call statement.Tests
Two new tests in
PHPFormatterTest:testThrowExpressionMethodChain_01(Continuation Indentation 4) andtestThrowExpressionMethodChain_02(8), with one input file and two expected files intestfiles/formatting.I did not run the tests and did not build NetBeans. The only thing checked is that the changed
FormatVisitor.javacompiles against the jars of Apache NetBeans 31. The expected files are written by hand and may need to be regenerated after a real run. I searched the formatter test data ofmasterfor a multi-linethrowstatement and found none, so I do not expect an existing expected file to change.AI assistance and my background
I am not a Java developer. The analysis, the code, the tests and this description were produced with the help of an AI model (Claude Sonnet 5.5), and I cannot judge the Java code on my own. Please review it as code from someone who does not know the codebase, and feel free to change it or to close this PR in favour of a better fix. Maintainer edits are allowed.
Assisted-by: Claude Sonnet 5.5