This is an automated email from the ASF dual-hosted git repository.
junichi11 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push:
new 5f687eb28c Fix the formatting for the method call arguments alignment
option #6714
new f4da2b4df3 Merge pull request #6877 from
junichi11/php-gh-6714-formatting-for-alignment
5f687eb28c is described below
commit 5f687eb28c5b46baf961bc0e6c33718c6cbfc400
Author: Junichi Yamamoto
AuthorDate: Sun Dec 24 19:00:22 2023 +0900
Fix the formatting for the method call arguments alignment option #6714
- https://github.com/apache/netbeans/issues/6714
- Consider the TAB size when a column size is got
Example:
```php
array_merge(
$x,
$y,
);
```
Before:
```php
array_merge(
$x,
$y,
);
```
After:
```php
array_merge(
$x,
$y,
);
```
- Keep the last anchor to a stack when a method calls are nested
Example:
```php
nestedCall(
something(
$arg1,
$arg2,
C::something(
$x,
$y,
$z,
)
),
$y,
$z,
);
```
Before:
```php
nestedCall(
something(
$arg1,
$arg2,
C::something(
$x,
$y,
$z,
)
),
$y,
$z,
);
```
After:
```php
nestedCall(
something(
$arg1,
$arg2,
C::something(
$x,
$y,
$z,
)
),
$y,
$z,
);
```
- Add unit tests
---
.../modules/php/editor/indent/TokenFormatter.java | 29 --
.../testfiles/formatting/alignment/gh6714_01.php | 84 +
...h6714_01.php.testGH6714WithSpaces_01a.formatted | 84 +
...h6714_01.php.testGH6714WithSpaces_01b.formatted | 84 +
.../gh6714_01.php.testGH6714WithTab_01a.formatted | 84 +
.../gh6714_01.php.testGH6714WithTab_01b.formatted | 84 +
.../testfiles/formatting/alignment/gh6714_02.php | 84 +
...h6714_02.php.testGH6714WithSpaces_02a.formatted | 84 +
...h6714_02.php.testGH6714WithSpaces_02b.formatted | 84 +
.../gh6714_02.php.testGH6714WithTab_02a.formatted | 84 +
.../gh6714_02.php.testGH6714WithTab_02b.formatted | 84 +
.../editor/indent/PHPFormatterAlignmentTest.java | 102 +
12 files changed, 965 insertions(+), 6 deletions(-)
diff --git
a/php/php.editor/src/org/netbeans/modules/php/editor/indent/TokenFormatter.java
b/php/php.editor/src/org/netbeans/modules/php/editor/indent/TokenFormatter.java
index 4764316575..f834010651 100644
---
a/php/php.editor/src/org/netbeans/modules/php/editor/indent/TokenFormatter.java
+++
b/php/php.editor/src/org/netbeans/modules/php/editor/indent/TokenFormatter.java
@@ -36,6 +36,7 @@ import org.netbeans.editor.Utilities;
import org.netbeans.modules.csl.spi.GsfUtilities;
import org.netbeans.modules.csl.spi.ParserResult;
import org.netbeans.modules.editor.indent.spi.Context;
+import org.netbeans.modules.php.editor.CodeUtils;
import org.netbeans.modules.php.editor.lexer.LexUtilities;
import org.netbeans.modules.php.editor.lexer.PHPTokenId;
import org.netbeans.modules.php.editor.parser.PHPParseResult;
@@ -455,7 +456,9 @@ public class TokenFormatter {
int extraLines;
int column = 0;
int indentOfOpenTag = 0;
+int methodCallParenBalance = 0; // GH-6714 for nested
arguments
final Deque lastBracedBlockIndent = new
ArrayDeque<>();
+final Deque lastAnchorTokenStack
= new ArrayDeque<>(); // GH-6714 for nested arguments
FormatToken formatToken;
String newText = null;
@@ -1455,12 +1458,17 @@ public class TokenFormatter {
}
// NETBEANS-3391
if (isLeftParen(formatTokens.get(index
- 1))) {
+methodCallParenBalance++;
if
(hasNewLineWithinParensForward(index, formatTokens, formatToken.getId())
&&