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 13d2e35025 Avoid showing invalid types in the Fix Imports panel
new 20ee705d85 Merge pull request #5767 from
junichi11/php-avoid-showing-invalid-type-in-fix-imports-panel
13d2e35025 is described below
commit 13d2e35025c2f4e1b1f90d28abcc0ee7d392d9d4
Author: Junichi Yamamoto <[email protected]>
AuthorDate: Mon Apr 3 08:10:48 2023 +0900
Avoid showing invalid types in the Fix Imports panel
Ignore the following cases
- `array<int, TypeName>`
- `array{'key': TypeName}`
---
.../php/editor/actions/UsedNamesCollector.java | 5 ++-
.../testfiles/actions/testGH4614/testGH4614_01.php | 43 ++++++++++++++++++++++
.../testGH4614/testGH4614_01.php.importData | 12 ++++++
.../php/editor/actions/ImportDataCreatorTest.java | 4 ++
4 files changed, 63 insertions(+), 1 deletion(-)
diff --git
a/php/php.editor/src/org/netbeans/modules/php/editor/actions/UsedNamesCollector.java
b/php/php.editor/src/org/netbeans/modules/php/editor/actions/UsedNamesCollector.java
index 86b1f41196..b0a609cb6e 100644
---
a/php/php.editor/src/org/netbeans/modules/php/editor/actions/UsedNamesCollector.java
+++
b/php/php.editor/src/org/netbeans/modules/php/editor/actions/UsedNamesCollector.java
@@ -164,7 +164,10 @@ public class UsedNamesCollector {
}
private boolean isValidTypeName(final String typeName) {
- return !SPECIAL_NAMES.contains(typeName) &&
!Type.isPrimitive(typeName);
+ return !SPECIAL_NAMES.contains(typeName)
+ && !Type.isPrimitive(typeName)
+ && !typeName.contains("<") // NOI18N e.g. array<int,
ClassName>
+ && !typeName.contains("{"); // NOI18N e.g. array{'foo':
int, "bar": string}
}
private boolean isValidAliasTypeName(final String typeName) {
diff --git
a/php/php.editor/test/unit/data/testfiles/actions/testGH4614/testGH4614_01.php
b/php/php.editor/test/unit/data/testfiles/actions/testGH4614/testGH4614_01.php
new file mode 100644
index 0000000000..e353837309
--- /dev/null
+++
b/php/php.editor/test/unit/data/testfiles/actions/testGH4614/testGH4614_01.php
@@ -0,0 +1,43 @@
+<?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 Test1;
+
+class Foo {
+
+}
+
+namespace Test2;
+
+class Test
+{
+ /**
+ * @param array<'foo', Foo> $param
+ */
+ public function test1(array $param): Foo {
+ return $param['foo'];
+ }
+
+ /**
+ * @param array{'foo': Foo, "bar": string} $param
+ */
+ public function test2(array $param): Foo {
+ return $param['foo'];
+ }
+}
diff --git
a/php/php.editor/test/unit/data/testfiles/actions/testGH4614/testGH4614_01.php.importData
b/php/php.editor/test/unit/data/testfiles/actions/testGH4614/testGH4614_01.php.importData
new file mode 100644
index 0000000000..7bb493904d
--- /dev/null
+++
b/php/php.editor/test/unit/data/testfiles/actions/testGH4614/testGH4614_01.php.importData
@@ -0,0 +1,12 @@
+Caret position: 980
+Should show uses panel: true
+Defaults:
+ \Test1\Foo
+
+Names:
+ Foo
+
+Variants:
+ \Test1\Foo
+ Don't import.
+
diff --git
a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/actions/ImportDataCreatorTest.java
b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/actions/ImportDataCreatorTest.java
index 48b3b3c245..c923564bea 100644
---
a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/actions/ImportDataCreatorTest.java
+++
b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/actions/ImportDataCreatorTest.java
@@ -114,6 +114,10 @@ public class ImportDataCreatorTest extends PHPTestBase {
performTest("class Test^Class3 {");
}
+ public void testGH4614_01() throws Exception {
+ performTest("public function test1(array $param): F^oo {");
+ }
+
private void performTest(String caretLine) throws Exception {
performTest(caretLine, null);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists