This is an automated email from the ASF dual-hosted git repository.

tmysik 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 c2a31881af Fix an array formatting in a match arm #5186
     new ddb1233e37 Merge pull request #5685 from 
junichi11/php-gh-5186-array-formatting-in-match-arm
c2a31881af is described below

commit c2a31881af703ae495bc332cdc823742d3e50b62
Author: Junichi Yamamoto <[email protected]>
AuthorDate: Mon Mar 20 10:47:51 2023 +0900

    Fix an array formatting in a match arm #5186
    
    - https://github.com/apache/netbeans/issues/5186
    
    e.g.
    ```php
    match(true){
            'test' => [
                    'key' => 'value',
                    ],
    };
    ```
    
    Before: An array is broken
    ```php
    match (true) {
        'test' => [
    'key' => 'value',
        ],
    };
    ```
    
    After:
    ```php
    match (true) {
        'test' => [
            'key' => 'value',
        ],
    };
    ```
---
 .../modules/php/editor/indent/FormatVisitor.java   |  1 +
 .../php80/matchExpressionWithArray_01.php          | 37 ++++++++++++++++++++++
 .../matchExpressionWithArray_01.php.formatted      | 37 ++++++++++++++++++++++
 .../php/editor/indent/PHPFormatterTest.java        |  6 ++++
 4 files changed, 81 insertions(+)

diff --git 
a/php/php.editor/src/org/netbeans/modules/php/editor/indent/FormatVisitor.java 
b/php/php.editor/src/org/netbeans/modules/php/editor/indent/FormatVisitor.java
index b23284d349..22eb8745f9 100644
--- 
a/php/php.editor/src/org/netbeans/modules/php/editor/indent/FormatVisitor.java
+++ 
b/php/php.editor/src/org/netbeans/modules/php/editor/indent/FormatVisitor.java
@@ -300,6 +300,7 @@ public class FormatVisitor extends DefaultVisitor {
             if (formatTokens.get(formatTokens.size() - 1).getId() == 
FormatToken.Kind.WHITESPACE_INDENT
                     || path.get(1) instanceof ArrayElement
                     || path.get(1) instanceof FormalParameter
+                    || path.get(1) instanceof MatchArm
                     || path.get(1) instanceof CastExpression) {
                 // when the array is on the beginning of the line, indent 
items in normal way
                 delta = options.indentArrayItems;
diff --git 
a/php/php.editor/test/unit/data/testfiles/formatting/php80/matchExpressionWithArray_01.php
 
b/php/php.editor/test/unit/data/testfiles/formatting/php80/matchExpressionWithArray_01.php
new file mode 100644
index 0000000000..4e7066e5c2
--- /dev/null
+++ 
b/php/php.editor/test/unit/data/testfiles/formatting/php80/matchExpressionWithArray_01.php
@@ -0,0 +1,37 @@
+<?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.
+ */
+
+// GH-5186
+match(true){
+       'test' => [
+               'key' => 'value',
+               ],
+};
+
+match (true) {
+'test1' => ['key' => 'value'],
+'test2' => [
+'key1' => 'value1',
+'nested' => [
+'key2' => 'value2',
+],
+],
+};
diff --git 
a/php/php.editor/test/unit/data/testfiles/formatting/php80/matchExpressionWithArray_01.php.formatted
 
b/php/php.editor/test/unit/data/testfiles/formatting/php80/matchExpressionWithArray_01.php.formatted
new file mode 100644
index 0000000000..7b3e89b8d4
--- /dev/null
+++ 
b/php/php.editor/test/unit/data/testfiles/formatting/php80/matchExpressionWithArray_01.php.formatted
@@ -0,0 +1,37 @@
+<?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.
+ */
+
+// GH-5186
+match (true) {
+    'test' => [
+        'key' => 'value',
+    ],
+};
+
+match (true) {
+    'test1' => ['key' => 'value'],
+    'test2' => [
+        'key1' => 'value1',
+        'nested' => [
+            'key2' => 'value2',
+        ],
+    ],
+};
diff --git 
a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterTest.java
 
b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterTest.java
index 0ec6786726..6feeccc9e8 100644
--- 
a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterTest.java
+++ 
b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterTest.java
@@ -943,6 +943,12 @@ public class PHPFormatterTest extends PHPFormatterTestBase 
{
         
reformatFileContents("testfiles/formatting/php80/matchExpression_SameLine_02.php",
 options);
     }
 
+    // GH-5186
+    public void testMatchExpressionWithArray_01() throws Exception {
+        HashMap<String, Object> options = new 
HashMap<>(FmtOptions.getDefaults());
+        
reformatFileContents("testfiles/formatting/php80/matchExpressionWithArray_01.php",
 options);
+    }
+
     public void testAttributeSyntax_01() throws Exception {
         HashMap<String, Object> options = new 
HashMap<>(FmtOptions.getDefaults());
         
reformatFileContents("testfiles/formatting/php80/attributeSyntax_01.php", 
options);


---------------------------------------------------------------------
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

Reply via email to