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
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 4764316..f834010 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.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 @@
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 @@
}
// 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 @@
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 @@
}
break;
case ANCHOR:
+ if (methodCallParenBalance > 0 && lastAnchor != null) {
+ lastAnchorTokenStack.push(lastAnchor);
+ }
lastAnchor = (FormatToken.AnchorToken) formatToken;
lastAnchor.setAnchorColumn(column);
break;
@@ -2221,22 +2235,25 @@
}
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 0000000..360b299
--- /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 0000000..0138ecf
--- /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 0000000..0138ecf
--- /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 0000000..f2112b5
--- /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 0000000..f2112b5
--- /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 0000000..06c0ef6
--- /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 0000000..0138ecf
--- /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 0000000..0138ecf
--- /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 0000000..f2112b5
--- /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 0000000..f2112b5
--- /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 e135576..bc8c50c 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 @@
*/
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 @@
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);
+ }
+
}