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 8f10f68  [NETBEANS-2149] Space-Formatting of == and === in PHP does 
not match "Binary Operators"
     new 0ef95bb  Merge pull request #1449 from 
junichi11/netbeans-2149-formatting-binary-operators
8f10f68 is described below

commit 8f10f6811bc133977a52299c1985eec0b92a2562
Author: Junichi Yamamoto <junich...@apache.org>
AuthorDate: Sun Aug 18 06:50:34 2019 +0900

    [NETBEANS-2149] Space-Formatting of == and === in PHP does not match 
"Binary Operators"
    
    - Don't add `WHITESPACE_[BEFORE|AFTER]_ASSIGN_OP` to `==` and `===`
    
    Example:
    ```
    $a=$b==$c;
    $a=$b===$c;
    ```
    
    Before:
    ```
    $a=$b== $c;
    $a=$b=== $c;
    ```
    
    After:
    ```
    $a=$b == $c;
    $a=$b === $c;
    ```
---
 .../modules/php/editor/indent/FormatVisitor.java   |  3 ++-
 .../formatting/spaces/netbeans2149_01.php          | 22 ++++++++++++++++
 .../spaces/netbeans2149_01.php.formatted           | 23 +++++++++++++++++
 .../formatting/spaces/netbeans2149_02.php          | 22 ++++++++++++++++
 .../spaces/netbeans2149_02.php.formatted           | 23 +++++++++++++++++
 .../formatting/spaces/netbeans2149_03.php          | 22 ++++++++++++++++
 .../spaces/netbeans2149_03.php.formatted           | 23 +++++++++++++++++
 .../formatting/spaces/netbeans2149_04.php          | 22 ++++++++++++++++
 .../spaces/netbeans2149_04.php.formatted           | 23 +++++++++++++++++
 .../php/editor/indent/PHPFormatterSpacesTest.java  | 30 ++++++++++++++++++++++
 10 files changed, 212 insertions(+), 1 deletion(-)

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 f4bbeb7..e86b1e9 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
@@ -2058,7 +2058,8 @@ public class FormatVisitor extends DefaultVisitor {
                     tokens.add(new 
FormatToken(FormatToken.Kind.WHITESPACE_AROUND_DECLARE_EQUAL, ts.offset() + 
ts.token().length()));
                     break;
                 }
-                if (TokenUtilities.endsWith(txt2, "=")) { // NOI18N
+                if (!TokenUtilities.startsWith(txt2, "==") // NOI18N 
NETBEANS-2149
+                        && TokenUtilities.endsWith(txt2, "=")) { // NOI18N
                     tokens.add(new 
FormatToken(FormatToken.Kind.WHITESPACE_BEFORE_ASSIGN_OP, ts.offset()));
                     tokens.add(new FormatToken(FormatToken.Kind.TEXT, 
ts.offset(), ts.token().text().toString()));
                     tokens.add(new 
FormatToken(FormatToken.Kind.WHITESPACE_AFTER_ASSIGN_OP, ts.offset() + 
ts.token().length()));
diff --git 
a/php/php.editor/test/unit/data/testfiles/formatting/spaces/netbeans2149_01.php 
b/php/php.editor/test/unit/data/testfiles/formatting/spaces/netbeans2149_01.php
new file mode 100644
index 0000000..3519963
--- /dev/null
+++ 
b/php/php.editor/test/unit/data/testfiles/formatting/spaces/netbeans2149_01.php
@@ -0,0 +1,22 @@
+<?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.
+ */
+
+$a=$b==$c;
+$a=$b===$c;
diff --git 
a/php/php.editor/test/unit/data/testfiles/formatting/spaces/netbeans2149_01.php.formatted
 
b/php/php.editor/test/unit/data/testfiles/formatting/spaces/netbeans2149_01.php.formatted
new file mode 100644
index 0000000..a4ffe9e
--- /dev/null
+++ 
b/php/php.editor/test/unit/data/testfiles/formatting/spaces/netbeans2149_01.php.formatted
@@ -0,0 +1,23 @@
+<?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.
+ */
+
+$a=$b == $c;
+$a=$b === $c;
diff --git 
a/php/php.editor/test/unit/data/testfiles/formatting/spaces/netbeans2149_02.php 
b/php/php.editor/test/unit/data/testfiles/formatting/spaces/netbeans2149_02.php
new file mode 100644
index 0000000..3519963
--- /dev/null
+++ 
b/php/php.editor/test/unit/data/testfiles/formatting/spaces/netbeans2149_02.php
@@ -0,0 +1,22 @@
+<?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.
+ */
+
+$a=$b==$c;
+$a=$b===$c;
diff --git 
a/php/php.editor/test/unit/data/testfiles/formatting/spaces/netbeans2149_02.php.formatted
 
b/php/php.editor/test/unit/data/testfiles/formatting/spaces/netbeans2149_02.php.formatted
new file mode 100644
index 0000000..f9c5f7f
--- /dev/null
+++ 
b/php/php.editor/test/unit/data/testfiles/formatting/spaces/netbeans2149_02.php.formatted
@@ -0,0 +1,23 @@
+<?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.
+ */
+
+$a = $b==$c;
+$a = $b===$c;
diff --git 
a/php/php.editor/test/unit/data/testfiles/formatting/spaces/netbeans2149_03.php 
b/php/php.editor/test/unit/data/testfiles/formatting/spaces/netbeans2149_03.php
new file mode 100644
index 0000000..3519963
--- /dev/null
+++ 
b/php/php.editor/test/unit/data/testfiles/formatting/spaces/netbeans2149_03.php
@@ -0,0 +1,22 @@
+<?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.
+ */
+
+$a=$b==$c;
+$a=$b===$c;
diff --git 
a/php/php.editor/test/unit/data/testfiles/formatting/spaces/netbeans2149_03.php.formatted
 
b/php/php.editor/test/unit/data/testfiles/formatting/spaces/netbeans2149_03.php.formatted
new file mode 100644
index 0000000..b8309f9
--- /dev/null
+++ 
b/php/php.editor/test/unit/data/testfiles/formatting/spaces/netbeans2149_03.php.formatted
@@ -0,0 +1,23 @@
+<?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.
+ */
+
+$a = $b == $c;
+$a = $b === $c;
diff --git 
a/php/php.editor/test/unit/data/testfiles/formatting/spaces/netbeans2149_04.php 
b/php/php.editor/test/unit/data/testfiles/formatting/spaces/netbeans2149_04.php
new file mode 100644
index 0000000..3519963
--- /dev/null
+++ 
b/php/php.editor/test/unit/data/testfiles/formatting/spaces/netbeans2149_04.php
@@ -0,0 +1,22 @@
+<?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.
+ */
+
+$a=$b==$c;
+$a=$b===$c;
diff --git 
a/php/php.editor/test/unit/data/testfiles/formatting/spaces/netbeans2149_04.php.formatted
 
b/php/php.editor/test/unit/data/testfiles/formatting/spaces/netbeans2149_04.php.formatted
new file mode 100644
index 0000000..d2805e6
--- /dev/null
+++ 
b/php/php.editor/test/unit/data/testfiles/formatting/spaces/netbeans2149_04.php.formatted
@@ -0,0 +1,23 @@
+<?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.
+ */
+
+$a=$b==$c;
+$a=$b===$c;
diff --git 
a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterSpacesTest.java
 
b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterSpacesTest.java
index d8fe0fc..3aab7c7 100644
--- 
a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterSpacesTest.java
+++ 
b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterSpacesTest.java
@@ -1426,4 +1426,34 @@ public class PHPFormatterSpacesTest extends 
PHPFormatterTestBase {
         options.put(FmtOptions.SPACE_AROUND_UNARY_OPS, true);
         
reformatFileContents("testfiles/formatting/spaces/netbeans2994_02.php", 
options);
     }
+
+    // NETBEANS-2149
+    public void testSpacesAroundBinaryOperatorsOnly() throws Exception {
+        HashMap<String, Object> options = new 
HashMap<>(FmtOptions.getDefaults());
+        options.put(FmtOptions.SPACE_AROUND_BINARY_OPS, true);
+        options.put(FmtOptions.SPACE_AROUND_ASSIGN_OPS, false);
+        
reformatFileContents("testfiles/formatting/spaces/netbeans2149_01.php", 
options);
+    }
+
+    public void testSpacesAroundAssignmentOperatorsOnly() throws Exception {
+        HashMap<String, Object> options = new 
HashMap<>(FmtOptions.getDefaults());
+        options.put(FmtOptions.SPACE_AROUND_BINARY_OPS, false);
+        options.put(FmtOptions.SPACE_AROUND_ASSIGN_OPS, true);
+        
reformatFileContents("testfiles/formatting/spaces/netbeans2149_02.php", 
options);
+    }
+
+    public void testSpacesAroundAssignmentAndBinaryOperators() throws 
Exception {
+        HashMap<String, Object> options = new 
HashMap<>(FmtOptions.getDefaults());
+        options.put(FmtOptions.SPACE_AROUND_BINARY_OPS, true);
+        options.put(FmtOptions.SPACE_AROUND_ASSIGN_OPS, true);
+        
reformatFileContents("testfiles/formatting/spaces/netbeans2149_03.php", 
options);
+    }
+
+    public void testSpacesWithoutAroundAssignmentAndBinaryOperators() throws 
Exception {
+        HashMap<String, Object> options = new 
HashMap<>(FmtOptions.getDefaults());
+        options.put(FmtOptions.SPACE_AROUND_BINARY_OPS, false);
+        options.put(FmtOptions.SPACE_AROUND_ASSIGN_OPS, false);
+        
reformatFileContents("testfiles/formatting/spaces/netbeans2149_04.php", 
options);
+    }
+
 }


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

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

Reply via email to