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 60c71c7  [NETBEANS-6087] Use the refactoring feature for private 
members of trait instead of the instant renamer
     new e46dd1d  Merge pull request #3257 from 
junichi11/netbeans-6087-rename-private-trait-method
60c71c7 is described below

commit 60c71c7a1f17a21fcf00a584890b65fac3d3427d
Author: Junichi Yamamoto <[email protected]>
AuthorDate: Wed Oct 20 19:46:41 2021 +0900

    [NETBEANS-6087] Use the refactoring feature for private members of trait 
instead of the instant renamer
    
    - https://issues.apache.org/jira/browse/NETBEANS-6087
    - Classes can also use private members of traits. If the declaration of the 
member is in another file, only member names in the same file are renamed using 
the instant renamer. So, we have to use the refactoring feature instead of it.
---
 .../modules/php/editor/csl/InstantRenamerImpl.java |  7 +++--
 .../php/findusages/WhereUsedSupport.java           |  5 ++-
 .../data/testfiles/findusages/testNB6087/index.php | 36 ++++++++++++++++++++++
 ...x.php.testNB6087_PrivateTraitField01.findUsages | 14 +++++++++
 ...x.php.testNB6087_PrivateTraitField02.findUsages | 14 +++++++++
 ....php.testNB6087_PrivateTraitMethod01.findUsages | 14 +++++++++
 ....php.testNB6087_PrivateTraitMethod02.findUsages | 14 +++++++++
 .../testfiles/findusages/testNB6087/nb6087.php     | 31 +++++++++++++++++++
 ...7.php.testNB6087_PrivateTraitField03.findUsages | 14 +++++++++
 ....php.testNB6087_PrivateTraitMethod03.findUsages | 14 +++++++++
 .../php/findusages/FindUsagesTestBase.java         | 13 +++++++-
 .../php/findusages/WhereUsedSupportTest.java       | 24 +++++++++++++++
 12 files changed, 196 insertions(+), 4 deletions(-)

diff --git 
a/php/php.editor/src/org/netbeans/modules/php/editor/csl/InstantRenamerImpl.java
 
b/php/php.editor/src/org/netbeans/modules/php/editor/csl/InstantRenamerImpl.java
index f0ee97a..769674d 100644
--- 
a/php/php.editor/src/org/netbeans/modules/php/editor/csl/InstantRenamerImpl.java
+++ 
b/php/php.editor/src/org/netbeans/modules/php/editor/csl/InstantRenamerImpl.java
@@ -32,6 +32,7 @@ import 
org.netbeans.modules.php.editor.api.elements.FieldElement;
 import org.netbeans.modules.php.editor.api.elements.MethodElement;
 import org.netbeans.modules.php.editor.api.elements.PhpElement;
 import org.netbeans.modules.php.editor.api.elements.TypeConstantElement;
+import org.netbeans.modules.php.editor.api.elements.TypeElement;
 import org.netbeans.modules.php.editor.model.Model;
 import org.netbeans.modules.php.editor.model.Occurence;
 import org.netbeans.modules.php.editor.model.Occurence.Accuracy;
@@ -75,13 +76,15 @@ public class InstantRenamerImpl implements InstantRenamer {
                     } else if (decl instanceof MethodElement) {
                         MethodElement meth = (MethodElement) decl;
                         PhpModifiers phpModifiers = meth.getPhpModifiers();
-                        if (phpModifiers.isPrivate()) {
+                        if (phpModifiers.isPrivate() && 
!meth.getType().isTrait()) {
+                            // NETBEANS-6087 private methods of trait are used 
in classes
                             return checkAll(caretOccurence);
                         }
                     } else if (decl instanceof FieldElement) {
                         FieldElement fld = (FieldElement) decl;
                         PhpModifiers phpModifiers = fld.getPhpModifiers();
-                        if (phpModifiers.isPrivate()) {
+                        if (phpModifiers.isPrivate() && 
!fld.getType().isTrait()) {
+                            // NETBEANS-6087 private field of trait are used 
in classes
                             return checkAll(caretOccurence);
                         }
                     } else if (decl instanceof TypeConstantElement) {
diff --git 
a/php/php.refactoring/src/org/netbeans/modules/refactoring/php/findusages/WhereUsedSupport.java
 
b/php/php.refactoring/src/org/netbeans/modules/refactoring/php/findusages/WhereUsedSupport.java
index 112555d..48c8961 100644
--- 
a/php/php.refactoring/src/org/netbeans/modules/refactoring/php/findusages/WhereUsedSupport.java
+++ 
b/php/php.refactoring/src/org/netbeans/modules/refactoring/php/findusages/WhereUsedSupport.java
@@ -55,6 +55,8 @@ import org.netbeans.modules.php.editor.model.ModelElement;
 import org.netbeans.modules.php.editor.model.ModelFactory;
 import org.netbeans.modules.php.editor.model.ModelUtils;
 import org.netbeans.modules.php.editor.model.Occurence;
+import org.netbeans.modules.php.editor.model.Scope;
+import org.netbeans.modules.php.editor.model.TraitScope;
 import org.netbeans.modules.php.editor.model.TypeScope;
 import org.netbeans.modules.php.editor.model.VariableName;
 import org.netbeans.modules.php.editor.parser.PHPParseResult;
@@ -244,7 +246,8 @@ public final class WhereUsedSupport {
             if (!variable.isGloballyVisible()) {
                 return Collections.singleton(mElement.getFileObject());
             }
-        } else if (mElement != null && mElement.getPhpModifiers().isPrivate()) 
{
+        } else if (mElement != null && mElement.getPhpModifiers().isPrivate() 
&& !(mElement.getInScope() instanceof TraitScope)) {
+            // NETBEANS-6087 private members of trait are used in classes
             return Collections.singleton(mElement.getFileObject());
         }
 
diff --git 
a/php/php.refactoring/test/unit/data/testfiles/findusages/testNB6087/index.php 
b/php/php.refactoring/test/unit/data/testfiles/findusages/testNB6087/index.php
new file mode 100644
index 0000000..fa2ef60
--- /dev/null
+++ 
b/php/php.refactoring/test/unit/data/testfiles/findusages/testNB6087/index.php
@@ -0,0 +1,36 @@
+<?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.
+ */
+
+trait NetBeans6087Trait {
+
+    private int $privateField = 1;
+
+    private function privateMethod(): void
+    {
+        
+    }
+
+    public function testMethod()
+    {
+        $this->privateField;
+        $this->privateMethod();
+    }
+
+}
diff --git 
a/php/php.refactoring/test/unit/data/testfiles/findusages/testNB6087/index.php.testNB6087_PrivateTraitField01.findUsages
 
b/php/php.refactoring/test/unit/data/testfiles/findusages/testNB6087/index.php.testNB6087_PrivateTraitField01.findUsages
new file mode 100644
index 0000000..87ecc89
--- /dev/null
+++ 
b/php/php.refactoring/test/unit/data/testfiles/findusages/testNB6087/index.php.testNB6087_PrivateTraitField01.findUsages
@@ -0,0 +1,14 @@
+Display text: private int $<b>privateField</b> = 1;
+File name: index.php
+Name: $privateField
+Position: BEGIN: 859 END: 871
+
+Display text: $this-><b>privateField</b>;
+File name: index.php
+Name: $privateField
+Position: BEGIN: 997 END: 1009
+
+Display text: echo $this-><b>privateField</b>;
+File name: nb6087.php
+Name: $privateField
+Position: BEGIN: 929 END: 941
\ No newline at end of file
diff --git 
a/php/php.refactoring/test/unit/data/testfiles/findusages/testNB6087/index.php.testNB6087_PrivateTraitField02.findUsages
 
b/php/php.refactoring/test/unit/data/testfiles/findusages/testNB6087/index.php.testNB6087_PrivateTraitField02.findUsages
new file mode 100644
index 0000000..87ecc89
--- /dev/null
+++ 
b/php/php.refactoring/test/unit/data/testfiles/findusages/testNB6087/index.php.testNB6087_PrivateTraitField02.findUsages
@@ -0,0 +1,14 @@
+Display text: private int $<b>privateField</b> = 1;
+File name: index.php
+Name: $privateField
+Position: BEGIN: 859 END: 871
+
+Display text: $this-><b>privateField</b>;
+File name: index.php
+Name: $privateField
+Position: BEGIN: 997 END: 1009
+
+Display text: echo $this-><b>privateField</b>;
+File name: nb6087.php
+Name: $privateField
+Position: BEGIN: 929 END: 941
\ No newline at end of file
diff --git 
a/php/php.refactoring/test/unit/data/testfiles/findusages/testNB6087/index.php.testNB6087_PrivateTraitMethod01.findUsages
 
b/php/php.refactoring/test/unit/data/testfiles/findusages/testNB6087/index.php.testNB6087_PrivateTraitMethod01.findUsages
new file mode 100644
index 0000000..ee6da1a
--- /dev/null
+++ 
b/php/php.refactoring/test/unit/data/testfiles/findusages/testNB6087/index.php.testNB6087_PrivateTraitMethod01.findUsages
@@ -0,0 +1,14 @@
+Display text: private function <b>privateMethod</b>(): void
+File name: index.php
+Name: privateMethod
+Position: BEGIN: 899 END: 912
+
+Display text: $this-><b>privateMethod</b>();
+File name: index.php
+Name: privateMethod
+Position: BEGIN: 1026 END: 1039
+
+Display text: $this-><b>privateMethod</b>();
+File name: nb6087.php
+Name: privateMethod
+Position: BEGIN: 958 END: 971
\ No newline at end of file
diff --git 
a/php/php.refactoring/test/unit/data/testfiles/findusages/testNB6087/index.php.testNB6087_PrivateTraitMethod02.findUsages
 
b/php/php.refactoring/test/unit/data/testfiles/findusages/testNB6087/index.php.testNB6087_PrivateTraitMethod02.findUsages
new file mode 100644
index 0000000..ee6da1a
--- /dev/null
+++ 
b/php/php.refactoring/test/unit/data/testfiles/findusages/testNB6087/index.php.testNB6087_PrivateTraitMethod02.findUsages
@@ -0,0 +1,14 @@
+Display text: private function <b>privateMethod</b>(): void
+File name: index.php
+Name: privateMethod
+Position: BEGIN: 899 END: 912
+
+Display text: $this-><b>privateMethod</b>();
+File name: index.php
+Name: privateMethod
+Position: BEGIN: 1026 END: 1039
+
+Display text: $this-><b>privateMethod</b>();
+File name: nb6087.php
+Name: privateMethod
+Position: BEGIN: 958 END: 971
\ No newline at end of file
diff --git 
a/php/php.refactoring/test/unit/data/testfiles/findusages/testNB6087/nb6087.php 
b/php/php.refactoring/test/unit/data/testfiles/findusages/testNB6087/nb6087.php
new file mode 100644
index 0000000..ef8296c
--- /dev/null
+++ 
b/php/php.refactoring/test/unit/data/testfiles/findusages/testNB6087/nb6087.php
@@ -0,0 +1,31 @@
+<?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 NetBeans6087Class {
+
+    use NetBeans6087Trait;
+
+    public function testMethod()
+    {
+        echo $this->privateField;
+        $this->privateMethod();
+    }
+
+}
diff --git 
a/php/php.refactoring/test/unit/data/testfiles/findusages/testNB6087/nb6087.php.testNB6087_PrivateTraitField03.findUsages
 
b/php/php.refactoring/test/unit/data/testfiles/findusages/testNB6087/nb6087.php.testNB6087_PrivateTraitField03.findUsages
new file mode 100644
index 0000000..87ecc89
--- /dev/null
+++ 
b/php/php.refactoring/test/unit/data/testfiles/findusages/testNB6087/nb6087.php.testNB6087_PrivateTraitField03.findUsages
@@ -0,0 +1,14 @@
+Display text: private int $<b>privateField</b> = 1;
+File name: index.php
+Name: $privateField
+Position: BEGIN: 859 END: 871
+
+Display text: $this-><b>privateField</b>;
+File name: index.php
+Name: $privateField
+Position: BEGIN: 997 END: 1009
+
+Display text: echo $this-><b>privateField</b>;
+File name: nb6087.php
+Name: $privateField
+Position: BEGIN: 929 END: 941
\ No newline at end of file
diff --git 
a/php/php.refactoring/test/unit/data/testfiles/findusages/testNB6087/nb6087.php.testNB6087_PrivateTraitMethod03.findUsages
 
b/php/php.refactoring/test/unit/data/testfiles/findusages/testNB6087/nb6087.php.testNB6087_PrivateTraitMethod03.findUsages
new file mode 100644
index 0000000..ee6da1a
--- /dev/null
+++ 
b/php/php.refactoring/test/unit/data/testfiles/findusages/testNB6087/nb6087.php.testNB6087_PrivateTraitMethod03.findUsages
@@ -0,0 +1,14 @@
+Display text: private function <b>privateMethod</b>(): void
+File name: index.php
+Name: privateMethod
+Position: BEGIN: 899 END: 912
+
+Display text: $this-><b>privateMethod</b>();
+File name: index.php
+Name: privateMethod
+Position: BEGIN: 1026 END: 1039
+
+Display text: $this-><b>privateMethod</b>();
+File name: nb6087.php
+Name: privateMethod
+Position: BEGIN: 958 END: 971
\ No newline at end of file
diff --git 
a/php/php.refactoring/test/unit/src/org/netbeans/modules/refactoring/php/findusages/FindUsagesTestBase.java
 
b/php/php.refactoring/test/unit/src/org/netbeans/modules/refactoring/php/findusages/FindUsagesTestBase.java
index 4227cd7..e577417 100644
--- 
a/php/php.refactoring/test/unit/src/org/netbeans/modules/refactoring/php/findusages/FindUsagesTestBase.java
+++ 
b/php/php.refactoring/test/unit/src/org/netbeans/modules/refactoring/php/findusages/FindUsagesTestBase.java
@@ -19,6 +19,7 @@
 package org.netbeans.modules.refactoring.php.findusages;
 
 import java.util.Collections;
+import java.util.concurrent.Future;
 import org.netbeans.modules.parsing.api.ParserManager;
 import org.netbeans.modules.parsing.api.ResultIterator;
 import org.netbeans.modules.parsing.api.Source;
@@ -49,6 +50,12 @@ public abstract class FindUsagesTestBase extends 
RefactoringTestBase {
         assertDescriptionMatches(exactFileName, result, true, ".findUsages");
     }
 
+    protected void findUsages(final String caretLine, String filePath) throws 
Exception {
+        final String exactFileName = getTestFolderPath() + "/" + filePath;
+        final String result = getTestResult(exactFileName, caretLine);
+        assertDescriptionMatches(exactFileName, result, true, ".findUsages");
+    }
+
     private String getTestResult(final String exactFileName, final String 
caretLine) throws Exception {
         FileObject testFile = getTestFile(exactFileName);
         Source testSource = getTestSource(testFile);
@@ -60,7 +67,8 @@ public abstract class FindUsagesTestBase extends 
RefactoringTestBase {
             caretOffset = -1;
         }
         final String[] result = new String[1];
-        ParserManager.parse(Collections.singleton(testSource), new UserTask() {
+        // wait for the scan to finish
+        Future<Void> future = 
ParserManager.parseWhenScanFinished(Collections.singleton(testSource), new 
UserTask() {
 
             @Override
             public void run(final ResultIterator resultIterator) throws 
Exception {
@@ -90,6 +98,9 @@ public abstract class FindUsagesTestBase extends 
RefactoringTestBase {
                 result[0] = sb.toString().trim();
             }
         });
+        if (!future.isDone()) {
+            future.get();
+        }
         return result[0];
     }
 
diff --git 
a/php/php.refactoring/test/unit/src/org/netbeans/modules/refactoring/php/findusages/WhereUsedSupportTest.java
 
b/php/php.refactoring/test/unit/src/org/netbeans/modules/refactoring/php/findusages/WhereUsedSupportTest.java
index 1a3f159..34d7198 100644
--- 
a/php/php.refactoring/test/unit/src/org/netbeans/modules/refactoring/php/findusages/WhereUsedSupportTest.java
+++ 
b/php/php.refactoring/test/unit/src/org/netbeans/modules/refactoring/php/findusages/WhereUsedSupportTest.java
@@ -248,4 +248,28 @@ public class WhereUsedSupportTest extends 
FindUsagesTestBase {
         findUsages("(new Two)->get^Two();");
     }
 
+    public void testNB6087_PrivateTraitMethod01() throws Exception {
+        findUsages("private function private^Method(): void");
+    }
+
+    public void testNB6087_PrivateTraitMethod02() throws Exception {
+        findUsages("$this->privateMetho^d();");
+    }
+
+    public void testNB6087_PrivateTraitMethod03() throws Exception {
+        findUsages("$this->privateMetho^d();", "nb6087.php");
+    }
+
+    public void testNB6087_PrivateTraitField01() throws Exception {
+        findUsages("private int $privateFi^eld = 1;");
+    }
+
+    public void testNB6087_PrivateTraitField02() throws Exception {
+        findUsages("$this->privateFie^ld;");
+    }
+
+    public void testNB6087_PrivateTraitField03() throws Exception {
+        findUsages("echo $this->privateFi^eld;", "nb6087.php");
+    }
+
 }

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

Reply via email to