You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by lk...@apache.org on 2020/10/30 20:45:11 UTC

[netbeans] branch delivery updated: [NETBEANS-4970] Incorrect formatting for lambda functions

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

lkishalmi pushed a commit to branch delivery
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/delivery by this push:
     new 6e3b645  [NETBEANS-4970] Incorrect formatting for lambda functions
6e3b645 is described below

commit 6e3b64554170765fe8e52da8c01753fe71b06513
Author: Junichi Yamamoto <ju...@apache.org>
AuthorDate: Fri Oct 30 21:30:27 2020 +0900

    [NETBEANS-4970] Incorrect formatting for lambda functions
    
    Before:
    ```php
    <?php
    
    function test(): callable {
        return function ($test): void {
                    echo "test";
                };
    }
    ```
    
    After
    ```php
    <?php
    
    function test(): callable {
        return function ($test): void {
            echo "test";
        };
    }
    ```
---
 .../modules/php/editor/indent/FormatVisitor.java   |  1 +
 .../data/testfiles/formatting/netbeans4970.php     | 30 ++++++++++++++++++++
 .../formatting/netbeans4970.php.formatted          | 32 ++++++++++++++++++++++
 .../php/editor/indent/PHPFormatterTest.java        |  5 ++++
 4 files changed, 68 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 d5c9dc6..9c8d46c 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
@@ -1575,6 +1575,7 @@ public class FormatVisitor extends DefaultVisitor {
 
         boolean addIndent = !isAnonymousClass(node.getExpression())
                 && !(path.size() > 2 && path.get(2) instanceof LambdaFunctionDeclaration) // #259111
+                && !(node.getExpression() instanceof LambdaFunctionDeclaration) // NETBEANS-4970
                 && !(node.getExpression() instanceof MatchExpression);
 
         if (ts.token().id() == PHPTokenId.PHP_RETURN) {
diff --git a/php/php.editor/test/unit/data/testfiles/formatting/netbeans4970.php b/php/php.editor/test/unit/data/testfiles/formatting/netbeans4970.php
new file mode 100644
index 0000000..25cf522
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/formatting/netbeans4970.php
@@ -0,0 +1,30 @@
+<?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.
+ */
+function test(): callable {
+    return function ($test): void {
+        echo "test";
+    };
+}
+
+function test2(): callable {
+return function ($test): void {
+echo "test";
+};
+}
diff --git a/php/php.editor/test/unit/data/testfiles/formatting/netbeans4970.php.formatted b/php/php.editor/test/unit/data/testfiles/formatting/netbeans4970.php.formatted
new file mode 100644
index 0000000..3b64e7b
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/formatting/netbeans4970.php.formatted
@@ -0,0 +1,32 @@
+<?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.
+ */
+
+function test(): callable {
+    return function ($test): void {
+        echo "test";
+    };
+}
+
+function test2(): callable {
+    return function ($test): void {
+        echo "test";
+    };
+}
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 643de86..9238b4f 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
@@ -883,4 +883,9 @@ public class PHPFormatterTest extends PHPFormatterTestBase {
         reformatFileContents("testfiles/formatting/php80/matchExpression_SameLine_02.php", options);
     }
 
+    public void testNetBeans4970() throws Exception {
+        HashMap<String, Object> options = new HashMap<>(FmtOptions.getDefaults());
+        reformatFileContents("testfiles/formatting/netbeans4970.php", options);
+    }
+
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists