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

junichi11 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 86340d23dc Fix code completion for fields with single line var doc 
#6359
     new c473ac3ded Merge pull request #6364 from 
junichi11/php-gh-6359-field-cc-with-single-line-vardoc
86340d23dc is described below

commit 86340d23dc59dcd6360bed2e125969c70bdd8e70
Author: Junichi Yamamoto <junich...@apache.org>
AuthorDate: Mon Aug 21 11:41:35 2023 +0900

    Fix code completion for fields with single line var doc #6359
    
    - https://github.com/apache/netbeans/issues/6359
    - `/** @var Type $field */` is recognized as not `PHPDocBlock` but 
`PHPVarComment`, so, check it
    ```php
    // example
    class X {
        public function testX(): void {}
    }
    
    class Y {
        public function testY(): void {}
    }
    
    class GH6359 {
    
        /** @var X $testX */
        protected $testX;
        /** @var X|Y $testXorY */
        protected $testXorY;
        /** @var X&Y $testXandY */
        protected $testXandY;
    
        public function test(): void {
            $this->testX->testX();
            $this->testXorY->testX();
            $this->testXandY->testX();
        }
    }
    ```
---
 .../php/editor/model/impl/VariousUtils.java        | 12 +++++
 .../testfiles/completion/lib/gh6359/gh6359.php     | 42 ++++++++++++++++
 .../lib/gh6359/gh6359.php.testGH6359_01.completion |  4 ++
 .../lib/gh6359/gh6359.php.testGH6359_02.completion |  5 ++
 .../lib/gh6359/gh6359.php.testGH6359_03.completion |  5 ++
 .../completion/PHPCodeCompletionGH6359Test.java    | 57 ++++++++++++++++++++++
 6 files changed, 125 insertions(+)

diff --git 
a/php/php.editor/src/org/netbeans/modules/php/editor/model/impl/VariousUtils.java
 
b/php/php.editor/src/org/netbeans/modules/php/editor/model/impl/VariousUtils.java
index 47e02265e4..9f7ba9a6bd 100644
--- 
a/php/php.editor/src/org/netbeans/modules/php/editor/model/impl/VariousUtils.java
+++ 
b/php/php.editor/src/org/netbeans/modules/php/editor/model/impl/VariousUtils.java
@@ -89,6 +89,7 @@ import 
org.netbeans.modules.php.editor.parser.astnodes.PHPDocBlock;
 import org.netbeans.modules.php.editor.parser.astnodes.PHPDocTag;
 import org.netbeans.modules.php.editor.parser.astnodes.PHPDocTypeNode;
 import org.netbeans.modules.php.editor.parser.astnodes.PHPDocVarTypeTag;
+import org.netbeans.modules.php.editor.parser.astnodes.PHPVarComment;
 import org.netbeans.modules.php.editor.parser.astnodes.ParenthesisExpression;
 import org.netbeans.modules.php.editor.parser.astnodes.Program;
 import org.netbeans.modules.php.editor.parser.astnodes.Reference;
@@ -384,7 +385,18 @@ public final class VariousUtils {
                     break;
                 }
             }
+        } else if ((comment instanceof PHPVarComment) && PHPDocTag.Type.VAR == 
tagType) {
+            // GH-6359
+            // /** @var Type $field */
+            // private $field;
+            PHPVarComment varComment = (PHPVarComment) comment;
+            PHPDocVarTypeTag tag = varComment.getVariable();
+            String[] parts = WS_PATTERN.split(tag.getValue().trim(), 3); // 3: 
@var Type $field
+            if (parts.length > 1) {
+                return parts[1];
+            }
         }
+
         return null;
     }
 
diff --git 
a/php/php.editor/test/unit/data/testfiles/completion/lib/gh6359/gh6359.php 
b/php/php.editor/test/unit/data/testfiles/completion/lib/gh6359/gh6359.php
new file mode 100644
index 0000000000..c53bc705f8
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/completion/lib/gh6359/gh6359.php
@@ -0,0 +1,42 @@
+<?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 X {
+    public function testX(): void {}
+}
+
+class Y {
+    public function testY(): void {}
+}
+
+class GH6359 {
+
+    /** @var X $testX */
+    protected $testX;
+    /** @var X|Y $testXorY */
+    protected $testXorY;
+    /** @var X&Y $testXandY */
+    protected $testXandY;
+
+    public function test(): void {
+        $this->testX->testX();
+        $this->testXorY->testX();
+        $this->testXandY->testX();
+    }
+}
diff --git 
a/php/php.editor/test/unit/data/testfiles/completion/lib/gh6359/gh6359.php.testGH6359_01.completion
 
b/php/php.editor/test/unit/data/testfiles/completion/lib/gh6359/gh6359.php.testGH6359_01.completion
new file mode 100644
index 0000000000..66058090b3
--- /dev/null
+++ 
b/php/php.editor/test/unit/data/testfiles/completion/lib/gh6359/gh6359.php.testGH6359_01.completion
@@ -0,0 +1,4 @@
+Code completion result for source line:
+$this->testX->|testX();
+(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
+METHOD     testX()                         [PUBLIC]   X
diff --git 
a/php/php.editor/test/unit/data/testfiles/completion/lib/gh6359/gh6359.php.testGH6359_02.completion
 
b/php/php.editor/test/unit/data/testfiles/completion/lib/gh6359/gh6359.php.testGH6359_02.completion
new file mode 100644
index 0000000000..d75a16a408
--- /dev/null
+++ 
b/php/php.editor/test/unit/data/testfiles/completion/lib/gh6359/gh6359.php.testGH6359_02.completion
@@ -0,0 +1,5 @@
+Code completion result for source line:
+$this->testXorY->|testX();
+(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
+METHOD     testX()                         [PUBLIC]   X
+METHOD     testY()                         [PUBLIC]   Y
diff --git 
a/php/php.editor/test/unit/data/testfiles/completion/lib/gh6359/gh6359.php.testGH6359_03.completion
 
b/php/php.editor/test/unit/data/testfiles/completion/lib/gh6359/gh6359.php.testGH6359_03.completion
new file mode 100644
index 0000000000..5d377a45bb
--- /dev/null
+++ 
b/php/php.editor/test/unit/data/testfiles/completion/lib/gh6359/gh6359.php.testGH6359_03.completion
@@ -0,0 +1,5 @@
+Code completion result for source line:
+$this->testXandY->|testX();
+(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
+METHOD     testX()                         [PUBLIC]   X
+METHOD     testY()                         [PUBLIC]   Y
diff --git 
a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/completion/PHPCodeCompletionGH6359Test.java
 
b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/completion/PHPCodeCompletionGH6359Test.java
new file mode 100644
index 0000000000..32e65559d1
--- /dev/null
+++ 
b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/completion/PHPCodeCompletionGH6359Test.java
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ */
+package org.netbeans.modules.php.editor.completion;
+
+import java.io.File;
+import java.util.Collections;
+import java.util.Map;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.modules.php.project.api.PhpSourcePath;
+import org.netbeans.spi.java.classpath.support.ClassPathSupport;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+
+public class PHPCodeCompletionGH6359Test extends PHPCodeCompletionTestBase {
+
+    public PHPCodeCompletionGH6359Test(String testName) {
+        super(testName);
+    }
+
+    public void testGH6359_01() throws Exception {
+        checkCompletion("testfiles/completion/lib/gh6359/gh6359.php", 
"$this->testX->^testX();", false);
+    }
+
+    public void testGH6359_02() throws Exception {
+        checkCompletion("testfiles/completion/lib/gh6359/gh6359.php", 
"$this->testXorY->^testX();", false);
+    }
+
+    public void testGH6359_03() throws Exception {
+        checkCompletion("testfiles/completion/lib/gh6359/gh6359.php", 
"$this->testXandY->^testX();", false);
+    }
+
+    @Override
+    protected Map<String, ClassPath> createClassPathsForTest() {
+        return Collections.singletonMap(
+            PhpSourcePath.SOURCE_CP,
+            ClassPathSupport.createClassPath(new FileObject[] {
+                FileUtil.toFileObject(new File(getDataDir(), 
"/testfiles/completion/lib/gh6359"))
+            })
+        );
+    }
+}


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