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 <[email protected]>
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<Integer> lastBracedBlockIndent = new
ArrayDeque<>();
+ final Deque<FormatToken.AnchorToken> 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())
&&
docOptions.wrapMethodCallArgsAfterLeftParen) {
indentLine = true;
newLines = 1;
}
} else {
+ methodCallParenBalance--;
+ if (methodCallParenBalance > 0 &&
!lastAnchorTokenStack.isEmpty()) {
+ lastAnchor =
lastAnchorTokenStack.pop();
+ }
if
(hasNewLineWithinParensBackward(index, formatTokens, formatToken.getId())
&&
docOptions.wrapMethodCallArgsRightParen) {
indentLine = true;
@@ -1741,6 +1749,9 @@ public class TokenFormatter {
lastPHPIndent += indentDelta;
break;
case ANCHOR:
+ if (methodCallParenBalance > 0 &&
lastAnchor != null) {
+
lastAnchorTokenStack.push(lastAnchor);
+ }
lastAnchor = (FormatToken.AnchorToken)
formatToken;
lastAnchor.setAnchorColumn(column + 1);
break;
@@ -2156,6 +2167,9 @@ public class TokenFormatter {
}
break;
case ANCHOR:
+ if (methodCallParenBalance > 0 &&
lastAnchor != null) {
+ lastAnchorTokenStack.push(lastAnchor);
+ }
lastAnchor = (FormatToken.AnchorToken)
formatToken;
lastAnchor.setAnchorColumn(column);
break;
@@ -2221,22 +2235,25 @@ public class TokenFormatter {
}
delta = replaceString(doc, changeOffset, index,
oldText, newText, delta, templateEdit);
+ // GH-6714 if text have TABs, get incorrect column
+ // so, use countOfSpaces() instead of newText.length()
if (newText == null) {
- String formatTokenOldText =
formatToken.getOldText() == null ? "" : formatToken.getOldText();
- int formatTokenOldTextLength =
formatTokenOldText.length();
+ String formatTokenOldText =
formatToken.getOldText() == null ? CodeUtils.EMPTY_STRING :
formatToken.getOldText();
+ int formatTokenOldTextLength =
countOfSpaces(formatTokenOldText, docOptions.tabSize);
int lines = countOfNewLines(formatTokenOldText);
if (lines > 0) {
- int lastNewLine =
formatTokenOldText.lastIndexOf('\n'); //NOI18N
- column =
formatTokenOldText.substring(lastNewLine).length();
+ int lastNewLine =
formatTokenOldText.lastIndexOf(CodeUtils.NEW_LINE);
+ String substring =
formatTokenOldText.substring(lastNewLine);
+ column = countOfSpaces(substring,
docOptions.tabSize);
} else {
column += formatTokenOldTextLength;
}
} else {
int lines = countOfNewLines(newText);
if (lines > 0) {
- column = newText.length() - lines;
+ column = countOfSpaces(newText,
docOptions.tabSize) - lines;
} else {
- column += newText.length();
+ column += countOfSpaces(newText,
docOptions.tabSize);
}
}
newText = null;
diff --git
a/php/php.editor/test/unit/data/testfiles/formatting/alignment/gh6714_01.php
b/php/php.editor/test/unit/data/testfiles/formatting/alignment/gh6714_01.php
new file mode 100644
index 0000000000..360b299172
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/formatting/alignment/gh6714_01.php
@@ -0,0 +1,84 @@
+<?php
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+namespace NS\GH6714;
+
+use Vendor\Package\TestClass1;
+use function Vendor\Package\ {
+ function1,
+ function2,
+};
+use function Vendor\Package\ {
+ function3,
+ function4,
+};
+use const Vendor\Package\CONSTANT1;
+
+class GH6714 implements Interface1,
+Interface2,
+Interface3
+{
+ public array $x = [];
+ public array $y = [];
+
+ public function test1()
+ {
+ return something1(
+ $this->x,
+ $this->y,
+ );
+ }
+
+ public function test2(
+ $param1,
+ $param2,
+ $param3,
+ )
+ {
+ nestedCall(
+ $this->testMethod($arg1),
+$this->x,
+ $this->y,
+ );
+ return nestedCall(
+ $this->testMethod($arg1),
+$this->x,
+ $this->y,
+ );
+ }
+}
+
+array_merge(
+ $x,
+$y,
+);
+
+nestedCall(
+ something(
+ $arg1,
+ $arg2,
+ C::something(
+ $x,
+ $y,
+ $z,
+ )
+ ),
+ $y,
+ $z,
+);
diff --git
a/php/php.editor/test/unit/data/testfiles/formatting/alignment/gh6714_01.php.testGH6714WithSpaces_01a.formatted
b/php/php.editor/test/unit/data/testfiles/formatting/alignment/gh6714_01.php.testGH6714WithSpaces_01a.formatted
new file mode 100644
index 0000000000..0138ecf071
--- /dev/null
+++
b/php/php.editor/test/unit/data/testfiles/formatting/alignment/gh6714_01.php.testGH6714WithSpaces_01a.formatted
@@ -0,0 +1,84 @@
+<?php
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+namespace NS\GH6714;
+
+use Vendor\Package\TestClass1;
+use function Vendor\Package\{
+ function1,
+ function2,
+};
+use function Vendor\Package\{
+ function3,
+ function4,
+};
+use const Vendor\Package\CONSTANT1;
+
+class GH6714 implements Interface1,
+ Interface2,
+ Interface3 {
+
+ public array $x = [];
+ public array $y = [];
+
+ public function test1() {
+ return something1(
+ $this->x,
+ $this->y,
+ );
+ }
+
+ public function test2(
+ $param1,
+ $param2,
+ $param3,
+ ) {
+ nestedCall(
+ $this->testMethod($arg1),
+ $this->x,
+ $this->y,
+ );
+ return nestedCall(
+ $this->testMethod($arg1),
+ $this->x,
+ $this->y,
+ );
+ }
+}
+
+array_merge(
+ $x,
+ $y,
+);
+
+nestedCall(
+ something(
+ $arg1,
+ $arg2,
+ C::something(
+ $x,
+ $y,
+ $z,
+ )
+ ),
+ $y,
+ $z,
+);
diff --git
a/php/php.editor/test/unit/data/testfiles/formatting/alignment/gh6714_01.php.testGH6714WithSpaces_01b.formatted
b/php/php.editor/test/unit/data/testfiles/formatting/alignment/gh6714_01.php.testGH6714WithSpaces_01b.formatted
new file mode 100644
index 0000000000..0138ecf071
--- /dev/null
+++
b/php/php.editor/test/unit/data/testfiles/formatting/alignment/gh6714_01.php.testGH6714WithSpaces_01b.formatted
@@ -0,0 +1,84 @@
+<?php
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+namespace NS\GH6714;
+
+use Vendor\Package\TestClass1;
+use function Vendor\Package\{
+ function1,
+ function2,
+};
+use function Vendor\Package\{
+ function3,
+ function4,
+};
+use const Vendor\Package\CONSTANT1;
+
+class GH6714 implements Interface1,
+ Interface2,
+ Interface3 {
+
+ public array $x = [];
+ public array $y = [];
+
+ public function test1() {
+ return something1(
+ $this->x,
+ $this->y,
+ );
+ }
+
+ public function test2(
+ $param1,
+ $param2,
+ $param3,
+ ) {
+ nestedCall(
+ $this->testMethod($arg1),
+ $this->x,
+ $this->y,
+ );
+ return nestedCall(
+ $this->testMethod($arg1),
+ $this->x,
+ $this->y,
+ );
+ }
+}
+
+array_merge(
+ $x,
+ $y,
+);
+
+nestedCall(
+ something(
+ $arg1,
+ $arg2,
+ C::something(
+ $x,
+ $y,
+ $z,
+ )
+ ),
+ $y,
+ $z,
+);
diff --git
a/php/php.editor/test/unit/data/testfiles/formatting/alignment/gh6714_01.php.testGH6714WithTab_01a.formatted
b/php/php.editor/test/unit/data/testfiles/formatting/alignment/gh6714_01.php.testGH6714WithTab_01a.formatted
new file mode 100644
index 0000000000..f2112b53b4
--- /dev/null
+++
b/php/php.editor/test/unit/data/testfiles/formatting/alignment/gh6714_01.php.testGH6714WithTab_01a.formatted
@@ -0,0 +1,84 @@
+<?php
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+namespace NS\GH6714;
+
+use Vendor\Package\TestClass1;
+use function Vendor\Package\{
+ function1,
+ function2,
+};
+use function Vendor\Package\{
+ function3,
+ function4,
+};
+use const Vendor\Package\CONSTANT1;
+
+class GH6714 implements Interface1,
+ Interface2,
+ Interface3 {
+
+ public array $x = [];
+ public array $y = [];
+
+ public function test1() {
+ return something1(
+ $this->x,
+ $this->y,
+ );
+ }
+
+ public function test2(
+ $param1,
+ $param2,
+ $param3,
+ ) {
+ nestedCall(
+ $this->testMethod($arg1),
+ $this->x,
+ $this->y,
+ );
+ return nestedCall(
+ $this->testMethod($arg1),
+ $this->x,
+ $this->y,
+ );
+ }
+}
+
+array_merge(
+ $x,
+ $y,
+);
+
+nestedCall(
+ something(
+ $arg1,
+ $arg2,
+ C::something(
+ $x,
+ $y,
+ $z,
+ )
+ ),
+ $y,
+ $z,
+);
diff --git
a/php/php.editor/test/unit/data/testfiles/formatting/alignment/gh6714_01.php.testGH6714WithTab_01b.formatted
b/php/php.editor/test/unit/data/testfiles/formatting/alignment/gh6714_01.php.testGH6714WithTab_01b.formatted
new file mode 100644
index 0000000000..f2112b53b4
--- /dev/null
+++
b/php/php.editor/test/unit/data/testfiles/formatting/alignment/gh6714_01.php.testGH6714WithTab_01b.formatted
@@ -0,0 +1,84 @@
+<?php
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+namespace NS\GH6714;
+
+use Vendor\Package\TestClass1;
+use function Vendor\Package\{
+ function1,
+ function2,
+};
+use function Vendor\Package\{
+ function3,
+ function4,
+};
+use const Vendor\Package\CONSTANT1;
+
+class GH6714 implements Interface1,
+ Interface2,
+ Interface3 {
+
+ public array $x = [];
+ public array $y = [];
+
+ public function test1() {
+ return something1(
+ $this->x,
+ $this->y,
+ );
+ }
+
+ public function test2(
+ $param1,
+ $param2,
+ $param3,
+ ) {
+ nestedCall(
+ $this->testMethod($arg1),
+ $this->x,
+ $this->y,
+ );
+ return nestedCall(
+ $this->testMethod($arg1),
+ $this->x,
+ $this->y,
+ );
+ }
+}
+
+array_merge(
+ $x,
+ $y,
+);
+
+nestedCall(
+ something(
+ $arg1,
+ $arg2,
+ C::something(
+ $x,
+ $y,
+ $z,
+ )
+ ),
+ $y,
+ $z,
+);
diff --git
a/php/php.editor/test/unit/data/testfiles/formatting/alignment/gh6714_02.php
b/php/php.editor/test/unit/data/testfiles/formatting/alignment/gh6714_02.php
new file mode 100644
index 0000000000..06c0ef6ee2
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/formatting/alignment/gh6714_02.php
@@ -0,0 +1,84 @@
+<?php
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+namespace NS\GH6714;
+
+use Vendor\Package\TestClass1;
+use function Vendor\Package\ {
+ function1,
+ function2,
+};
+use function Vendor\Package\ {
+ function3,
+ function4,
+};
+use const Vendor\Package\CONSTANT1;
+
+class GH6714 implements Interface1,
+ Interface2,
+ Interface3 {
+
+ public array $x = [];
+ public array $y = [];
+
+ public function test1() {
+ return something1(
+ $this->x,
+ $this->y,
+ );
+ }
+
+ public function test2(
+ $param1,
+ $param2,
+ $param3,
+ ) {
+ nestedCall(
+ $this->testMethod($arg1),
+ $this->x,
+ $this->y,
+ );
+ return nestedCall(
+ $this->testMethod($arg1),
+ $this->x,
+ $this->y,
+ );
+ }
+}
+
+array_merge(
+ $x,
+ $y,
+);
+
+nestedCall(
+ something(
+ $arg1,
+ $arg2,
+ C::something(
+ $x,
+ $y,
+ $z,
+ )
+ ),
+ $y,
+ $z,
+);
diff --git
a/php/php.editor/test/unit/data/testfiles/formatting/alignment/gh6714_02.php.testGH6714WithSpaces_02a.formatted
b/php/php.editor/test/unit/data/testfiles/formatting/alignment/gh6714_02.php.testGH6714WithSpaces_02a.formatted
new file mode 100644
index 0000000000..0138ecf071
--- /dev/null
+++
b/php/php.editor/test/unit/data/testfiles/formatting/alignment/gh6714_02.php.testGH6714WithSpaces_02a.formatted
@@ -0,0 +1,84 @@
+<?php
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+namespace NS\GH6714;
+
+use Vendor\Package\TestClass1;
+use function Vendor\Package\{
+ function1,
+ function2,
+};
+use function Vendor\Package\{
+ function3,
+ function4,
+};
+use const Vendor\Package\CONSTANT1;
+
+class GH6714 implements Interface1,
+ Interface2,
+ Interface3 {
+
+ public array $x = [];
+ public array $y = [];
+
+ public function test1() {
+ return something1(
+ $this->x,
+ $this->y,
+ );
+ }
+
+ public function test2(
+ $param1,
+ $param2,
+ $param3,
+ ) {
+ nestedCall(
+ $this->testMethod($arg1),
+ $this->x,
+ $this->y,
+ );
+ return nestedCall(
+ $this->testMethod($arg1),
+ $this->x,
+ $this->y,
+ );
+ }
+}
+
+array_merge(
+ $x,
+ $y,
+);
+
+nestedCall(
+ something(
+ $arg1,
+ $arg2,
+ C::something(
+ $x,
+ $y,
+ $z,
+ )
+ ),
+ $y,
+ $z,
+);
diff --git
a/php/php.editor/test/unit/data/testfiles/formatting/alignment/gh6714_02.php.testGH6714WithSpaces_02b.formatted
b/php/php.editor/test/unit/data/testfiles/formatting/alignment/gh6714_02.php.testGH6714WithSpaces_02b.formatted
new file mode 100644
index 0000000000..0138ecf071
--- /dev/null
+++
b/php/php.editor/test/unit/data/testfiles/formatting/alignment/gh6714_02.php.testGH6714WithSpaces_02b.formatted
@@ -0,0 +1,84 @@
+<?php
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+namespace NS\GH6714;
+
+use Vendor\Package\TestClass1;
+use function Vendor\Package\{
+ function1,
+ function2,
+};
+use function Vendor\Package\{
+ function3,
+ function4,
+};
+use const Vendor\Package\CONSTANT1;
+
+class GH6714 implements Interface1,
+ Interface2,
+ Interface3 {
+
+ public array $x = [];
+ public array $y = [];
+
+ public function test1() {
+ return something1(
+ $this->x,
+ $this->y,
+ );
+ }
+
+ public function test2(
+ $param1,
+ $param2,
+ $param3,
+ ) {
+ nestedCall(
+ $this->testMethod($arg1),
+ $this->x,
+ $this->y,
+ );
+ return nestedCall(
+ $this->testMethod($arg1),
+ $this->x,
+ $this->y,
+ );
+ }
+}
+
+array_merge(
+ $x,
+ $y,
+);
+
+nestedCall(
+ something(
+ $arg1,
+ $arg2,
+ C::something(
+ $x,
+ $y,
+ $z,
+ )
+ ),
+ $y,
+ $z,
+);
diff --git
a/php/php.editor/test/unit/data/testfiles/formatting/alignment/gh6714_02.php.testGH6714WithTab_02a.formatted
b/php/php.editor/test/unit/data/testfiles/formatting/alignment/gh6714_02.php.testGH6714WithTab_02a.formatted
new file mode 100644
index 0000000000..f2112b53b4
--- /dev/null
+++
b/php/php.editor/test/unit/data/testfiles/formatting/alignment/gh6714_02.php.testGH6714WithTab_02a.formatted
@@ -0,0 +1,84 @@
+<?php
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+namespace NS\GH6714;
+
+use Vendor\Package\TestClass1;
+use function Vendor\Package\{
+ function1,
+ function2,
+};
+use function Vendor\Package\{
+ function3,
+ function4,
+};
+use const Vendor\Package\CONSTANT1;
+
+class GH6714 implements Interface1,
+ Interface2,
+ Interface3 {
+
+ public array $x = [];
+ public array $y = [];
+
+ public function test1() {
+ return something1(
+ $this->x,
+ $this->y,
+ );
+ }
+
+ public function test2(
+ $param1,
+ $param2,
+ $param3,
+ ) {
+ nestedCall(
+ $this->testMethod($arg1),
+ $this->x,
+ $this->y,
+ );
+ return nestedCall(
+ $this->testMethod($arg1),
+ $this->x,
+ $this->y,
+ );
+ }
+}
+
+array_merge(
+ $x,
+ $y,
+);
+
+nestedCall(
+ something(
+ $arg1,
+ $arg2,
+ C::something(
+ $x,
+ $y,
+ $z,
+ )
+ ),
+ $y,
+ $z,
+);
diff --git
a/php/php.editor/test/unit/data/testfiles/formatting/alignment/gh6714_02.php.testGH6714WithTab_02b.formatted
b/php/php.editor/test/unit/data/testfiles/formatting/alignment/gh6714_02.php.testGH6714WithTab_02b.formatted
new file mode 100644
index 0000000000..f2112b53b4
--- /dev/null
+++
b/php/php.editor/test/unit/data/testfiles/formatting/alignment/gh6714_02.php.testGH6714WithTab_02b.formatted
@@ -0,0 +1,84 @@
+<?php
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+namespace NS\GH6714;
+
+use Vendor\Package\TestClass1;
+use function Vendor\Package\{
+ function1,
+ function2,
+};
+use function Vendor\Package\{
+ function3,
+ function4,
+};
+use const Vendor\Package\CONSTANT1;
+
+class GH6714 implements Interface1,
+ Interface2,
+ Interface3 {
+
+ public array $x = [];
+ public array $y = [];
+
+ public function test1() {
+ return something1(
+ $this->x,
+ $this->y,
+ );
+ }
+
+ public function test2(
+ $param1,
+ $param2,
+ $param3,
+ ) {
+ nestedCall(
+ $this->testMethod($arg1),
+ $this->x,
+ $this->y,
+ );
+ return nestedCall(
+ $this->testMethod($arg1),
+ $this->x,
+ $this->y,
+ );
+ }
+}
+
+array_merge(
+ $x,
+ $y,
+);
+
+nestedCall(
+ something(
+ $arg1,
+ $arg2,
+ C::something(
+ $x,
+ $y,
+ $z,
+ )
+ ),
+ $y,
+ $z,
+);
diff --git
a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterAlignmentTest.java
b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterAlignmentTest.java
index e135576775..bc8c50c985 100644
---
a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterAlignmentTest.java
+++
b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterAlignmentTest.java
@@ -26,10 +26,16 @@ import java.util.HashMap;
*/
public class PHPFormatterAlignmentTest extends PHPFormatterTestBase {
+ private static final String TEST_DIRECTORY_PATH =
"testfiles/formatting/alignment/";
+
public PHPFormatterAlignmentTest(String testName) {
super(testName);
}
+ private String getTestFilePath(String fileName) {
+ return TEST_DIRECTORY_PATH + fileName;
+ }
+
public void testAlignmentKeywords01() throws Exception {
HashMap<String, Object> options = new HashMap<String,
Object>(FmtOptions.getDefaults());
options.put(FmtOptions.PLACE_WHILE_ON_NEW_LINE, true);
@@ -213,4 +219,100 @@ public class PHPFormatterAlignmentTest extends
PHPFormatterTestBase {
reformatFileContents("testfiles/formatting/alignment/issue244566.php",
options);
}
+ public void testGH6714WithTab_01a() throws Exception {
+ HashMap<String, Object> options = new
HashMap<>(FmtOptions.getDefaults());
+ options.put(FmtOptions.ALIGN_MULTILINE_CALL_ARGS, true);
+ options.put(FmtOptions.ALIGN_MULTILINE_IMPLEMENTS, true);
+ options.put(FmtOptions.WRAP_EXTENDS_IMPLEMENTS_LIST,
CodeStyle.WrapStyle.WRAP_ALWAYS);
+ options.put(FmtOptions.ALIGN_MULTILINE_METHOD_PARAMS, true);
+ options.put(FmtOptions.TAB_SIZE, 4);
+ options.put(FmtOptions.CONTINUATION_INDENT_SIZE, 4);
+ options.put(FmtOptions.EXPAND_TAB_TO_SPACES, false);
+ reformatFileContents(getTestFilePath("gh6714_01.php"), options, false,
true);
+ }
+
+ public void testGH6714WithTab_01b() throws Exception {
+ HashMap<String, Object> options = new
HashMap<>(FmtOptions.getDefaults());
+ options.put(FmtOptions.ALIGN_MULTILINE_CALL_ARGS, false);
+ options.put(FmtOptions.WRAP_EXTENDS_IMPLEMENTS_LIST,
CodeStyle.WrapStyle.WRAP_ALWAYS);
+ options.put(FmtOptions.ALIGN_MULTILINE_IMPLEMENTS, true);
+ options.put(FmtOptions.ALIGN_MULTILINE_METHOD_PARAMS, true);
+ options.put(FmtOptions.TAB_SIZE, 4);
+ options.put(FmtOptions.CONTINUATION_INDENT_SIZE, 4);
+ options.put(FmtOptions.EXPAND_TAB_TO_SPACES, false);
+ reformatFileContents(getTestFilePath("gh6714_01.php"), options, false,
true);
+ }
+
+ public void testGH6714WithTab_02a() throws Exception {
+ HashMap<String, Object> options = new
HashMap<>(FmtOptions.getDefaults());
+ options.put(FmtOptions.ALIGN_MULTILINE_CALL_ARGS, true);
+ options.put(FmtOptions.WRAP_EXTENDS_IMPLEMENTS_LIST,
CodeStyle.WrapStyle.WRAP_ALWAYS);
+ options.put(FmtOptions.ALIGN_MULTILINE_IMPLEMENTS, true);
+ options.put(FmtOptions.ALIGN_MULTILINE_METHOD_PARAMS, true);
+ options.put(FmtOptions.TAB_SIZE, 4);
+ options.put(FmtOptions.CONTINUATION_INDENT_SIZE, 4);
+ options.put(FmtOptions.EXPAND_TAB_TO_SPACES, false);
+ reformatFileContents(getTestFilePath("gh6714_02.php"), options, false,
true);
+ }
+
+ public void testGH6714WithTab_02b() throws Exception {
+ HashMap<String, Object> options = new
HashMap<>(FmtOptions.getDefaults());
+ options.put(FmtOptions.ALIGN_MULTILINE_CALL_ARGS, false);
+ options.put(FmtOptions.WRAP_EXTENDS_IMPLEMENTS_LIST,
CodeStyle.WrapStyle.WRAP_ALWAYS);
+ options.put(FmtOptions.ALIGN_MULTILINE_IMPLEMENTS, true);
+ options.put(FmtOptions.ALIGN_MULTILINE_METHOD_PARAMS, true);
+ options.put(FmtOptions.TAB_SIZE, 4);
+ options.put(FmtOptions.CONTINUATION_INDENT_SIZE, 4);
+ options.put(FmtOptions.EXPAND_TAB_TO_SPACES, false);
+ reformatFileContents(getTestFilePath("gh6714_02.php"), options, false,
true);
+ }
+
+ public void testGH6714WithSpaces_01a() throws Exception {
+ HashMap<String, Object> options = new
HashMap<>(FmtOptions.getDefaults());
+ options.put(FmtOptions.ALIGN_MULTILINE_CALL_ARGS, true);
+ options.put(FmtOptions.WRAP_EXTENDS_IMPLEMENTS_LIST,
CodeStyle.WrapStyle.WRAP_ALWAYS);
+ options.put(FmtOptions.ALIGN_MULTILINE_IMPLEMENTS, true);
+ options.put(FmtOptions.ALIGN_MULTILINE_METHOD_PARAMS, true);
+ options.put(FmtOptions.TAB_SIZE, 4);
+ options.put(FmtOptions.CONTINUATION_INDENT_SIZE, 4);
+ options.put(FmtOptions.EXPAND_TAB_TO_SPACES, true);
+ reformatFileContents(getTestFilePath("gh6714_01.php"), options, false,
true);
+ }
+
+ public void testGH6714WithSpaces_01b() throws Exception {
+ HashMap<String, Object> options = new
HashMap<>(FmtOptions.getDefaults());
+ options.put(FmtOptions.ALIGN_MULTILINE_CALL_ARGS, false);
+ options.put(FmtOptions.WRAP_EXTENDS_IMPLEMENTS_LIST,
CodeStyle.WrapStyle.WRAP_ALWAYS);
+ options.put(FmtOptions.ALIGN_MULTILINE_IMPLEMENTS, true);
+ options.put(FmtOptions.ALIGN_MULTILINE_METHOD_PARAMS, true);
+ options.put(FmtOptions.TAB_SIZE, 4);
+ options.put(FmtOptions.CONTINUATION_INDENT_SIZE, 4);
+ options.put(FmtOptions.EXPAND_TAB_TO_SPACES, true);
+ reformatFileContents(getTestFilePath("gh6714_01.php"), options, false,
true);
+ }
+
+ public void testGH6714WithSpaces_02a() throws Exception {
+ HashMap<String, Object> options = new
HashMap<>(FmtOptions.getDefaults());
+ options.put(FmtOptions.ALIGN_MULTILINE_CALL_ARGS, true);
+ options.put(FmtOptions.WRAP_EXTENDS_IMPLEMENTS_LIST,
CodeStyle.WrapStyle.WRAP_ALWAYS);
+ options.put(FmtOptions.ALIGN_MULTILINE_IMPLEMENTS, true);
+ options.put(FmtOptions.ALIGN_MULTILINE_METHOD_PARAMS, true);
+ options.put(FmtOptions.TAB_SIZE, 4);
+ options.put(FmtOptions.CONTINUATION_INDENT_SIZE, 4);
+ options.put(FmtOptions.EXPAND_TAB_TO_SPACES, true);
+ reformatFileContents(getTestFilePath("gh6714_02.php"), options, false,
true);
+ }
+
+ public void testGH6714WithSpaces_02b() throws Exception {
+ HashMap<String, Object> options = new
HashMap<>(FmtOptions.getDefaults());
+ options.put(FmtOptions.ALIGN_MULTILINE_CALL_ARGS, false);
+ options.put(FmtOptions.WRAP_EXTENDS_IMPLEMENTS_LIST,
CodeStyle.WrapStyle.WRAP_ALWAYS);
+ options.put(FmtOptions.ALIGN_MULTILINE_IMPLEMENTS, true);
+ options.put(FmtOptions.ALIGN_MULTILINE_METHOD_PARAMS, true);
+ options.put(FmtOptions.TAB_SIZE, 4);
+ options.put(FmtOptions.CONTINUATION_INDENT_SIZE, 4);
+ options.put(FmtOptions.EXPAND_TAB_TO_SPACES, true);
+ reformatFileContents(getTestFilePath("gh6714_02.php"), options, false,
true);
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists