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 2021/07/19 14:44:12 UTC

[netbeans] branch master updated: [NETBEANS-5719] Unused property hint is shown when the property is used as a constructor argument

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 ffa25de  [NETBEANS-5719] Unused property hint is shown when the property is used as a constructor argument
     new 062895f  Merge pull request #3065 from junichi11/netbeans-5719-unused-hint
ffa25de is described below

commit ffa25de111f84ecf2df178fd4f98c3bc42763389
Author: Junichi Yamamoto <ju...@apache.org>
AuthorDate: Mon Jul 19 13:48:33 2021 +0900

    [NETBEANS-5719] Unused property hint is shown when the property is used as a constructor argument
    
    https://issues.apache.org/jira/browse/NETBEANS-5719
    
    - Scan constructor arguments of an anonymous class
---
 .../modules/php/editor/csl/SemanticAnalysis.java   |  3 ++
 .../data/testfiles/semantic/netbeans5719_01.php    | 49 ++++++++++++++++++++
 .../semantic/netbeans5719_01.php.semantic          | 49 ++++++++++++++++++++
 .../data/testfiles/semantic/netbeans5719_02.php    | 52 ++++++++++++++++++++++
 .../semantic/netbeans5719_02.php.semantic          | 52 ++++++++++++++++++++++
 .../php/editor/csl/SemanticAnalyzerTest.java       |  8 ++++
 6 files changed, 213 insertions(+)

diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/csl/SemanticAnalysis.java b/php/php.editor/src/org/netbeans/modules/php/editor/csl/SemanticAnalysis.java
index a8b41d4..1f8909f 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/csl/SemanticAnalysis.java
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/csl/SemanticAnalysis.java
@@ -576,6 +576,9 @@ public class SemanticAnalysis extends SemanticAnalyzer {
                 return;
             }
             if (node.isAnonymous()) {
+                // NETBEANS-5719 scan ctor params before ClassInstanceCreationTypeInfo is created
+                // to avoid recognizing $this as an instance of an anonymous class
+                scan(node.ctorParams());
                 addToPath(node);
                 typeInfo = new ClassInstanceCreationTypeInfo(node);
                 scan(node.getAttributes());
diff --git a/php/php.editor/test/unit/data/testfiles/semantic/netbeans5719_01.php b/php/php.editor/test/unit/data/testfiles/semantic/netbeans5719_01.php
new file mode 100644
index 0000000..82fcc8e
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/semantic/netbeans5719_01.php
@@ -0,0 +1,49 @@
+<?php declare(strict_types = 1);
+/*
+ * 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 NetBeans5719;
+
+class Test
+{
+    public function __construct(private bool $usedParameter, private bool $unusedParameter)
+    {
+    }
+
+    public function create(): TestInterface
+    {
+        return new class ($this->usedParameter) implements TestInterface // used here
+        {
+            public function __construct(private bool $anonParameter)
+            {
+            }
+
+            public function test(): bool
+            {
+                return $this->anonParameter;
+            }
+        };
+    }
+}
+
+
+interface TestInterface
+{
+    function test(): bool;
+}
diff --git a/php/php.editor/test/unit/data/testfiles/semantic/netbeans5719_01.php.semantic b/php/php.editor/test/unit/data/testfiles/semantic/netbeans5719_01.php.semantic
new file mode 100644
index 0000000..0601332
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/semantic/netbeans5719_01.php.semantic
@@ -0,0 +1,49 @@
+<?php declare(strict_types = 1);
+/*
+ * 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 NetBeans5719;
+
+class |>CLASS:Test<|
+{
+    public function |>METHOD:__construct<|(private bool $|>FIELD:usedParameter<|, private bool $|>FIELD,UNUSED:unusedParameter<|)
+    {
+    }
+
+    public function |>METHOD:create<|(): TestInterface
+    {
+        return new class ($this->|>FIELD:usedParameter<|) implements TestInterface // used here
+        {
+            public function |>METHOD:__construct<|(private bool $|>FIELD:anonParameter<|)
+            {
+            }
+
+            public function |>METHOD:test<|(): bool
+            {
+                return $this->|>FIELD:anonParameter<|;
+            }
+        };
+    }
+}
+
+
+interface |>CLASS:TestInterface<|
+{
+    function |>METHOD:test<|(): bool;
+}
diff --git a/php/php.editor/test/unit/data/testfiles/semantic/netbeans5719_02.php b/php/php.editor/test/unit/data/testfiles/semantic/netbeans5719_02.php
new file mode 100644
index 0000000..da275f1
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/semantic/netbeans5719_02.php
@@ -0,0 +1,52 @@
+<?php declare(strict_types = 1);
+/*
+ * 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 NetBeans5719;
+
+class Test
+{
+    private bool $usedParameter;
+    private bool $unusedParameter;
+
+    public function __construct()
+    {
+    }
+
+    public function create(): TestInterface
+    {
+        return new class ($this->usedParameter) implements TestInterface // used here
+        {
+            public function __construct(private bool $anonParameter)
+            {
+            }
+
+            public function test(): bool
+            {
+                return $this->anonParameter;
+            }
+        };
+    }
+}
+
+
+interface TestInterface
+{
+    function test(): bool;
+}
diff --git a/php/php.editor/test/unit/data/testfiles/semantic/netbeans5719_02.php.semantic b/php/php.editor/test/unit/data/testfiles/semantic/netbeans5719_02.php.semantic
new file mode 100644
index 0000000..00ece89
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/semantic/netbeans5719_02.php.semantic
@@ -0,0 +1,52 @@
+<?php declare(strict_types = 1);
+/*
+ * 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 NetBeans5719;
+
+class |>CLASS:Test<|
+{
+    private bool $|>FIELD:usedParameter<|;
+    private bool $|>FIELD,UNUSED:unusedParameter<|;
+
+    public function |>METHOD:__construct<|()
+    {
+    }
+
+    public function |>METHOD:create<|(): TestInterface
+    {
+        return new class ($this->|>FIELD:usedParameter<|) implements TestInterface // used here
+        {
+            public function |>METHOD:__construct<|(private bool $|>FIELD:anonParameter<|)
+            {
+            }
+
+            public function |>METHOD:test<|(): bool
+            {
+                return $this->|>FIELD:anonParameter<|;
+            }
+        };
+    }
+}
+
+
+interface |>CLASS:TestInterface<|
+{
+    function |>METHOD:test<|(): bool;
+}
diff --git a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/csl/SemanticAnalyzerTest.java b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/csl/SemanticAnalyzerTest.java
index c4a3315..d454d82 100644
--- a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/csl/SemanticAnalyzerTest.java
+++ b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/csl/SemanticAnalyzerTest.java
@@ -201,4 +201,12 @@ public class SemanticAnalyzerTest extends SemanticAnalysisTestBase {
     public void testNamedArgumentsColoring() throws Exception {
         checkSemantic("testfiles/semantic/namedArgumentsColoring.php");
     }
+
+    public void testNETBEANS5719_01() throws Exception {
+        checkSemantic("testfiles/semantic/netbeans5719_01.php");
+    }
+
+    public void testNETBEANS5719_02() throws Exception {
+        checkSemantic("testfiles/semantic/netbeans5719_02.php");
+    }
 }

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