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 3c18c5a  [NETBEANS-3103] Formatting is broken with class constant code 
completion(self::)
     new 47d3e95  Merge pull request #1510 from 
junichi11/netbeans-3103-const-formatting
3c18c5a is described below

commit 3c18c5a5f0bb6ef42052acee8dfaf6f20e369008
Author: Junichi Yamamoto <junich...@apache.org>
AuthorDate: Tue Sep 17 09:39:35 2019 +0900

    [NETBEANS-3103] Formatting is broken with class constant code 
completion(self::)
    
    - The parser ignores "::" because example code is incorrect syntax
    - Check whether the token behind self or parent is "::" in the FormatVisitor
    
    Example code:
    ```
    <?php
    class ClassName {
    
        // ^ is the caret position
        // select "self::" or "parent::" in CC list
        // i.e. private const CONSTANT = self::;
        private const CONSTANT = ^;
    
    }
    ```
    
    Before:
    ```
    <?php
    class ClassName {
    
        private const CONSTANT = self
    
        ::;
    
    }
    ```
    
    After:
    ```
    <?php
    class ClassName {
    
        private const CONSTANT = self::;
    
    }
    ```
---
 .../modules/php/editor/indent/FormatVisitor.java   | 13 ++++++++++++
 .../formatting/broken/netbeans3103_parent_01.php   | 24 ++++++++++++++++++++++
 .../broken/netbeans3103_parent_01.php.formatted    | 24 ++++++++++++++++++++++
 .../formatting/broken/netbeans3103_parent_02.php   | 24 ++++++++++++++++++++++
 .../broken/netbeans3103_parent_02.php.formatted    | 24 ++++++++++++++++++++++
 .../formatting/broken/netbeans3103_self_01.php     | 24 ++++++++++++++++++++++
 .../broken/netbeans3103_self_01.php.formatted      | 24 ++++++++++++++++++++++
 .../formatting/broken/netbeans3103_self_02.php     | 24 ++++++++++++++++++++++
 .../broken/netbeans3103_self_02.php.formatted      | 24 ++++++++++++++++++++++
 .../php/editor/indent/PHPFormatterBrokenTest.java  | 20 ++++++++++++++++++
 10 files changed, 225 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 e86b1e9..65afcbb 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
@@ -914,6 +914,19 @@ public class FormatVisitor extends DefaultVisitor {
 
             }
             scan(node.getInitializers());
+            if (ts.token().id() == PHPTokenId.PHP_SELF || ts.token().id() == 
PHPTokenId.PHP_PARENT) {
+                // NETBEANS-3103 check whether the token behind self|parent is 
"::"
+                // e.g. const CONSTANT = self::;
+                int originalOffset = ts.offset();
+                if (ts.moveNext()) {
+                    if (ts.token().id() == 
PHPTokenId.PHP_PAAMAYIM_NEKUDOTAYIM) { // ::
+                        addFormatToken(formatTokens);
+                    } else {
+                        ts.move(originalOffset);
+                        ts.moveNext();
+                    }
+                }
+            }
             formatTokens.add(new 
FormatToken.IndentToken(node.getStartOffset(), options.continualIndentSize * 
-1));
             if (index == statements.size() - 1
                     || ((index < statements.size() - 1) && 
!(statements.get(index + 1) instanceof ConstantDeclaration))) {
diff --git 
a/php/php.editor/test/unit/data/testfiles/formatting/broken/netbeans3103_parent_01.php
 
b/php/php.editor/test/unit/data/testfiles/formatting/broken/netbeans3103_parent_01.php
new file mode 100644
index 0000000..247d6a3
--- /dev/null
+++ 
b/php/php.editor/test/unit/data/testfiles/formatting/broken/netbeans3103_parent_01.php
@@ -0,0 +1,24 @@
+<?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.
+ */
+class ClassName {
+
+    private const CONSTANT = /*FORMAT_START*/parent::/*FORMAT_END*/;
+
+}
diff --git 
a/php/php.editor/test/unit/data/testfiles/formatting/broken/netbeans3103_parent_01.php.formatted
 
b/php/php.editor/test/unit/data/testfiles/formatting/broken/netbeans3103_parent_01.php.formatted
new file mode 100644
index 0000000..fb60f1b
--- /dev/null
+++ 
b/php/php.editor/test/unit/data/testfiles/formatting/broken/netbeans3103_parent_01.php.formatted
@@ -0,0 +1,24 @@
+<?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.
+ */
+class ClassName {
+
+    private const CONSTANT = parent::;
+
+}
diff --git 
a/php/php.editor/test/unit/data/testfiles/formatting/broken/netbeans3103_parent_02.php
 
b/php/php.editor/test/unit/data/testfiles/formatting/broken/netbeans3103_parent_02.php
new file mode 100644
index 0000000..94ff2cf
--- /dev/null
+++ 
b/php/php.editor/test/unit/data/testfiles/formatting/broken/netbeans3103_parent_02.php
@@ -0,0 +1,24 @@
+<?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.
+ */
+class ClassName {
+
+    private const CONSTANT = /*FORMAT_START*/parent::/*FORMAT_END*/
+
+}
diff --git 
a/php/php.editor/test/unit/data/testfiles/formatting/broken/netbeans3103_parent_02.php.formatted
 
b/php/php.editor/test/unit/data/testfiles/formatting/broken/netbeans3103_parent_02.php.formatted
new file mode 100644
index 0000000..f296309
--- /dev/null
+++ 
b/php/php.editor/test/unit/data/testfiles/formatting/broken/netbeans3103_parent_02.php.formatted
@@ -0,0 +1,24 @@
+<?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.
+ */
+class ClassName {
+
+    private const CONSTANT = parent::
+
+}
diff --git 
a/php/php.editor/test/unit/data/testfiles/formatting/broken/netbeans3103_self_01.php
 
b/php/php.editor/test/unit/data/testfiles/formatting/broken/netbeans3103_self_01.php
new file mode 100644
index 0000000..f2d8d45
--- /dev/null
+++ 
b/php/php.editor/test/unit/data/testfiles/formatting/broken/netbeans3103_self_01.php
@@ -0,0 +1,24 @@
+<?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.
+ */
+class ClassName {
+
+    private const CONSTANT = /*FORMAT_START*/self::/*FORMAT_END*/;
+
+}
diff --git 
a/php/php.editor/test/unit/data/testfiles/formatting/broken/netbeans3103_self_01.php.formatted
 
b/php/php.editor/test/unit/data/testfiles/formatting/broken/netbeans3103_self_01.php.formatted
new file mode 100644
index 0000000..fd65f8d
--- /dev/null
+++ 
b/php/php.editor/test/unit/data/testfiles/formatting/broken/netbeans3103_self_01.php.formatted
@@ -0,0 +1,24 @@
+<?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.
+ */
+class ClassName {
+
+    private const CONSTANT = self::;
+
+}
diff --git 
a/php/php.editor/test/unit/data/testfiles/formatting/broken/netbeans3103_self_02.php
 
b/php/php.editor/test/unit/data/testfiles/formatting/broken/netbeans3103_self_02.php
new file mode 100644
index 0000000..b24e7ef
--- /dev/null
+++ 
b/php/php.editor/test/unit/data/testfiles/formatting/broken/netbeans3103_self_02.php
@@ -0,0 +1,24 @@
+<?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.
+ */
+class ClassName {
+
+    private const CONSTANT = /*FORMAT_START*/self::/*FORMAT_END*/
+
+}
diff --git 
a/php/php.editor/test/unit/data/testfiles/formatting/broken/netbeans3103_self_02.php.formatted
 
b/php/php.editor/test/unit/data/testfiles/formatting/broken/netbeans3103_self_02.php.formatted
new file mode 100644
index 0000000..bb24d32
--- /dev/null
+++ 
b/php/php.editor/test/unit/data/testfiles/formatting/broken/netbeans3103_self_02.php.formatted
@@ -0,0 +1,24 @@
+<?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.
+ */
+class ClassName {
+
+    private const CONSTANT = self::
+
+}
diff --git 
a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterBrokenTest.java
 
b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterBrokenTest.java
index f7a95d2..854ee3d 100644
--- 
a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterBrokenTest.java
+++ 
b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterBrokenTest.java
@@ -53,4 +53,24 @@ public class PHPFormatterBrokenTest extends 
PHPFormatterTestBase {
         options.put(FmtOptions.CONTINUATION_INDENT_SIZE, 4);
         reformatFileContents("testfiles/formatting/broken/issue197074_04.php", 
options);
     }
+
+    public void testNetBeans3103SelectedSelf_01() throws Exception {
+        HashMap<String, Object> options = new 
HashMap<>(FmtOptions.getDefaults());
+        
reformatFileContents("testfiles/formatting/broken/netbeans3103_self_01.php", 
options);
+    }
+
+    public void testNetBeans3103SelectedSelf_02() throws Exception {
+        HashMap<String, Object> options = new 
HashMap<>(FmtOptions.getDefaults());
+        
reformatFileContents("testfiles/formatting/broken/netbeans3103_self_02.php", 
options);
+    }
+
+    public void testNetBeans3103SelectedParent_01() throws Exception {
+        HashMap<String, Object> options = new 
HashMap<>(FmtOptions.getDefaults());
+        
reformatFileContents("testfiles/formatting/broken/netbeans3103_parent_01.php", 
options);
+    }
+
+    public void testNetBeans3103SelectedParent_02() throws Exception {
+        HashMap<String, Object> options = new 
HashMap<>(FmtOptions.getDefaults());
+        
reformatFileContents("testfiles/formatting/broken/netbeans3103_parent_02.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