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

[netbeans] branch master updated: [NETBEANS-4650] Fix code completion for traits of use and group use statements

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 f2bad76  [NETBEANS-4650] Fix code completion for traits of use and group use statements
     new f986c03  Merge pull request #2533 from junichi11/netbeans-4650
f2bad76 is described below

commit f2bad76137cb79840af39ac1bf2f48688eedd2d1
Author: Junichi Yamamoto <ju...@apache.org>
AuthorDate: Sun Nov 15 00:20:45 2020 +0900

    [NETBEANS-4650] Fix code completion for traits of use and group use statements
---
 .../php/editor/completion/PHPCodeCompletion.java   | 14 ++++++
 .../testfiles/completion/lib/nb4650/nb4650.php     | 30 ++++++++++++
 .../lib/nb4650/nb4650.php.testNb4650_01.completion |  4 ++
 .../lib/nb4650/nb4650.php.testNb4650_02.completion |  4 ++
 .../issue241902.php.testUseCase1.completion        |  1 +
 .../completion/PHPCodeCompletionNb4650Test.java    | 57 ++++++++++++++++++++++
 6 files changed, 110 insertions(+)

diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/completion/PHPCodeCompletion.java b/php/php.editor/src/org/netbeans/modules/php/editor/completion/PHPCodeCompletion.java
index 62cf1e8..c9c85cc 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/completion/PHPCodeCompletion.java
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/completion/PHPCodeCompletion.java
@@ -920,6 +920,13 @@ public class PHPCodeCompletion implements CodeCompletionHandler2 {
                     }
                     completionResult.add(new PHPCompletionItem.InterfaceItem(iface, request, QualifiedNameKind.FULLYQUALIFIED, false));
                 }
+                // NETBEANS-4650
+                for (TraitElement trait : request.index.getTraits(nameQuery)) {
+                    if (CancelSupport.getDefault().isCancelled()) {
+                        return;
+                    }
+                    completionResult.add(new PHPCompletionItem.TraitItem(trait, request));
+                }
                 break;
             case CONST:
                 for (ConstantElement constant : request.index.getConstants(nameQuery)) {
@@ -975,6 +982,13 @@ public class PHPCodeCompletion implements CodeCompletionHandler2 {
                     }
                     completionResult.add(new PHPCompletionItem.InterfaceItem(iface, request, kind, false));
                 }
+                // NETBEANS-4650
+                for (TraitElement trait : request.index.getTraits(nameQuery)) {
+                    if (CancelSupport.getDefault().isCancelled()) {
+                        return;
+                    }
+                    completionResult.add(new PHPCompletionItem.TraitItem(trait, request));
+                }
                 break;
             case CONST:
                 for (ConstantElement constant : request.index.getConstants(nameQuery)) {
diff --git a/php/php.editor/test/unit/data/testfiles/completion/lib/nb4650/nb4650.php b/php/php.editor/test/unit/data/testfiles/completion/lib/nb4650/nb4650.php
new file mode 100644
index 0000000..6c1279c
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/completion/lib/nb4650/nb4650.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.
+ */
+namespace Test;
+trait MyTrait{}
+
+namespace TestTrait;
+
+use Test\MyTrait;
+use Test\{
+    MyTrait
+};
+
+class MyClass{}
diff --git a/php/php.editor/test/unit/data/testfiles/completion/lib/nb4650/nb4650.php.testNb4650_01.completion b/php/php.editor/test/unit/data/testfiles/completion/lib/nb4650/nb4650.php.testNb4650_01.completion
new file mode 100644
index 0000000..7b3e17a
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/completion/lib/nb4650/nb4650.php.testNb4650_01.completion
@@ -0,0 +1,4 @@
+Code completion result for source line:
+use Test\M|yTrait;
+(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
+CLASS      MyTrait                         [PUBLIC]   Test
diff --git a/php/php.editor/test/unit/data/testfiles/completion/lib/nb4650/nb4650.php.testNb4650_02.completion b/php/php.editor/test/unit/data/testfiles/completion/lib/nb4650/nb4650.php.testNb4650_02.completion
new file mode 100644
index 0000000..980d4c2
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/completion/lib/nb4650/nb4650.php.testNb4650_02.completion
@@ -0,0 +1,4 @@
+Code completion result for source line:
+My|Trait
+(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
+CLASS      MyTrait                         [PUBLIC]   Test
diff --git a/php/php.editor/test/unit/data/testfiles/completion/lib/tests241902/issue241902.php.testUseCase1.completion b/php/php.editor/test/unit/data/testfiles/completion/lib/tests241902/issue241902.php.testUseCase1.completion
index a12ce0d..1667053 100644
--- a/php/php.editor/test/unit/data/testfiles/completion/lib/tests241902/issue241902.php.testUseCase1.completion
+++ b/php/php.editor/test/unit/data/testfiles/completion/lib/tests241902/issue241902.php.testUseCase1.completion
@@ -6,3 +6,4 @@ PACKAGE    First                           [PUBLIC]   null
 PACKAGE    Second                          [PUBLIC]   First
 CLASS      ThirdC                          [PUBLIC]   First\Second
 CLASS      ThirdI                          [PUBLIC]   First\Second
+CLASS      ThirdT                          [PUBLIC]   First\Second
diff --git a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/completion/PHPCodeCompletionNb4650Test.java b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/completion/PHPCodeCompletionNb4650Test.java
new file mode 100644
index 0000000..48371c3
--- /dev/null
+++ b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/completion/PHPCodeCompletionNb4650Test.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 PHPCodeCompletionNb4650Test extends PHPCodeCompletionTestBase {
+
+    public PHPCodeCompletionNb4650Test(String testName) {
+        super(testName);
+    }
+
+    public void testNb4650_01() throws Exception {
+        testNb4650("use Test\\M^yTrait;");
+    }
+
+    public void testNb4650_02() throws Exception {
+        testNb4650("    My^Trait");
+    }
+
+    private void testNb4650(String caretLine) throws Exception {
+        checkCompletion("testfiles/completion/lib/nb4650/nb4650.php", caretLine, 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/nb4650"))
+            })
+        );
+    }
+}


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