You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2018/11/24 06:31:52 UTC

[GitHub] tmysik closed pull request #1027: [NETBEANS-1718] Improve Unused Variables Hint

tmysik closed pull request #1027: [NETBEANS-1718] Improve Unused Variables Hint
URL: https://github.com/apache/incubator-netbeans/pull/1027
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/verification/Bundle.properties b/php/php.editor/src/org/netbeans/modules/php/editor/verification/Bundle.properties
index d0e58ce6fb..55ab59f669 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/verification/Bundle.properties
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/verification/Bundle.properties
@@ -21,6 +21,7 @@ AccidentalAssignmentCustomizer.cbIncludeWhile.AccessibleContext.accessibleDescri
 AccidentalAssignmentCustomizer.chkTopLvlStmtOnly.AccessibleContext.accessibleDescription=Enable to check assignments in sub-statements
 AccidentalAssignmentCustomizer.cbIncludeWhile.AccessibleContext.accessibleName=Include assignments in 'while' statements
 AccidentalAssignmentCustomizer.chkTopLvlStmtOnly.AccessibleContext.accessibleName=Check assignments in sub-statements
+UnusedVariableCustomizer.checkInheritedMethodParametersCheckBox.text=Check Inherited Method Parameters
 UnusedVariableCustomizer.checkUnusedFormalParametersCheckBox.text=Check Unused Method/Function Parameters
 AccidentalAssignmentCustomizer.checkAssignmentsInSubStatementsCheckBox.text=Check assignments in sub-statements
 UninitializedVariableCustomizer.checkVariablesInitializedByReferenceCheckBox.text=Check Variables Initialized by Reference
diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/verification/UnusedVariableCustomizer.form b/php/php.editor/src/org/netbeans/modules/php/editor/verification/UnusedVariableCustomizer.form
index 9378f076d3..c0ca9d76aa 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/verification/UnusedVariableCustomizer.form
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/verification/UnusedVariableCustomizer.form
@@ -37,9 +37,12 @@
   <Layout>
     <DimensionLayout dim="0">
       <Group type="103" groupAlignment="0" attributes="0">
-          <Group type="102" alignment="0" attributes="0">
+          <Group type="102" attributes="0">
               <EmptySpace max="-2" attributes="0"/>
-              <Component id="checkUnusedFormalParametersCheckBox" min="-2" max="-2" attributes="0"/>
+              <Group type="103" groupAlignment="0" attributes="0">
+                  <Component id="checkUnusedFormalParametersCheckBox" alignment="0" min="-2" max="-2" attributes="0"/>
+                  <Component id="checkInheritedMethodParametersCheckBox" alignment="0" min="-2" max="-2" attributes="0"/>
+              </Group>
               <EmptySpace pref="53" max="32767" attributes="0"/>
           </Group>
       </Group>
@@ -49,7 +52,9 @@
           <Group type="102" alignment="0" attributes="0">
               <EmptySpace max="-2" attributes="0"/>
               <Component id="checkUnusedFormalParametersCheckBox" min="-2" max="-2" attributes="0"/>
-              <EmptySpace pref="264" max="32767" attributes="0"/>
+              <EmptySpace max="-2" attributes="0"/>
+              <Component id="checkInheritedMethodParametersCheckBox" min="-2" max="-2" attributes="0"/>
+              <EmptySpace pref="236" max="32767" attributes="0"/>
           </Group>
       </Group>
     </DimensionLayout>
@@ -66,5 +71,16 @@
         <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="checkUnusedFormalParametersCheckBoxActionPerformed"/>
       </Events>
     </Component>
+    <Component class="javax.swing.JCheckBox" name="checkInheritedMethodParametersCheckBox">
+      <Properties>
+        <Property name="mnemonic" type="int" value="73"/>
+        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+          <ResourceString bundle="org/netbeans/modules/php/editor/verification/Bundle.properties" key="UnusedVariableCustomizer.checkInheritedMethodParametersCheckBox.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
+        </Property>
+      </Properties>
+      <Events>
+        <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="checkInheritedMethodParametersCheckBoxActionPerformed"/>
+      </Events>
+    </Component>
   </SubComponents>
 </Form>
diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/verification/UnusedVariableCustomizer.java b/php/php.editor/src/org/netbeans/modules/php/editor/verification/UnusedVariableCustomizer.java
index 3c939a0da5..6e328572fa 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/verification/UnusedVariableCustomizer.java
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/verification/UnusedVariableCustomizer.java
@@ -31,6 +31,7 @@
  * @author Ondrej Brejla <ob...@netbeans.org>
  */
 public class UnusedVariableCustomizer extends javax.swing.JPanel {
+
     private final UnusedVariableHint unusedVariableHint;
     private final Preferences preferences;
 
@@ -39,18 +40,25 @@ public UnusedVariableCustomizer(Preferences preferences, UnusedVariableHint unus
         this.unusedVariableHint = unusedVariableHint;
         initComponents();
         checkUnusedFormalParametersCheckBox.setSelected(unusedVariableHint.checkUnusedFormalParameters(preferences));
+        checkInheritedMethodParametersCheckBox.setSelected(unusedVariableHint.checkInheritedMethodParameters(preferences));
+        setInheritedMethodParametersCheckBoxEnabled(checkUnusedFormalParametersCheckBox.isSelected());
+    }
+
+    private void setInheritedMethodParametersCheckBoxEnabled(boolean isEnabled) {
+        checkInheritedMethodParametersCheckBox.setEnabled(isEnabled);
     }
 
-    /** This method is called from within the constructor to
-     * initialize the form.
-     * WARNING: Do NOT modify this code. The content of this method is
-     * always regenerated by the Form Editor.
+    /**
+     * This method is called from within the constructor to initialize the form.
+     * WARNING: Do NOT modify this code. The content of this method is always
+     * regenerated by the Form Editor.
      */
     @SuppressWarnings("unchecked")
     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
     private void initComponents() {
 
         checkUnusedFormalParametersCheckBox = new javax.swing.JCheckBox();
+        checkInheritedMethodParametersCheckBox = new javax.swing.JCheckBox();
 
         checkUnusedFormalParametersCheckBox.setMnemonic('C');
         checkUnusedFormalParametersCheckBox.setText(org.openide.util.NbBundle.getMessage(UnusedVariableCustomizer.class, "UnusedVariableCustomizer.checkUnusedFormalParametersCheckBox.text")); // NOI18N
@@ -60,13 +68,23 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
             }
         });
 
+        checkInheritedMethodParametersCheckBox.setMnemonic('I');
+        checkInheritedMethodParametersCheckBox.setText(org.openide.util.NbBundle.getMessage(UnusedVariableCustomizer.class, "UnusedVariableCustomizer.checkInheritedMethodParametersCheckBox.text")); // NOI18N
+        checkInheritedMethodParametersCheckBox.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                checkInheritedMethodParametersCheckBoxActionPerformed(evt);
+            }
+        });
+
         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
         this.setLayout(layout);
         layout.setHorizontalGroup(
             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
             .addGroup(layout.createSequentialGroup()
                 .addContainerGap()
-                .addComponent(checkUnusedFormalParametersCheckBox)
+                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                    .addComponent(checkUnusedFormalParametersCheckBox)
+                    .addComponent(checkInheritedMethodParametersCheckBox))
                 .addContainerGap(53, Short.MAX_VALUE))
         );
         layout.setVerticalGroup(
@@ -74,15 +92,23 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
             .addGroup(layout.createSequentialGroup()
                 .addContainerGap()
                 .addComponent(checkUnusedFormalParametersCheckBox)
-                .addContainerGap(264, Short.MAX_VALUE))
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+                .addComponent(checkInheritedMethodParametersCheckBox)
+                .addContainerGap(236, Short.MAX_VALUE))
         );
     }// </editor-fold>//GEN-END:initComponents
 
     private void checkUnusedFormalParametersCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkUnusedFormalParametersCheckBoxActionPerformed
         unusedVariableHint.setCheckUnusedFormalParameters(preferences, checkUnusedFormalParametersCheckBox.isSelected());
+        setInheritedMethodParametersCheckBoxEnabled(checkUnusedFormalParametersCheckBox.isSelected());
     }//GEN-LAST:event_checkUnusedFormalParametersCheckBoxActionPerformed
 
+    private void checkInheritedMethodParametersCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkInheritedMethodParametersCheckBoxActionPerformed
+        unusedVariableHint.setCheckInheritedMethodParameters(preferences, checkInheritedMethodParametersCheckBox.isSelected());
+    }//GEN-LAST:event_checkInheritedMethodParametersCheckBoxActionPerformed
+
     // Variables declaration - do not modify//GEN-BEGIN:variables
+    private javax.swing.JCheckBox checkInheritedMethodParametersCheckBox;
     private javax.swing.JCheckBox checkUnusedFormalParametersCheckBox;
     // End of variables declaration//GEN-END:variables
 }
diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/verification/UnusedVariableHint.java b/php/php.editor/src/org/netbeans/modules/php/editor/verification/UnusedVariableHint.java
index 3c2f245b3d..56770469f6 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/verification/UnusedVariableHint.java
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/verification/UnusedVariableHint.java
@@ -21,9 +21,13 @@
 import java.util.ArrayDeque;
 import java.util.HashMap;
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
+import java.util.Set;
 import java.util.prefs.Preferences;
 import javax.swing.JComponent;
 import org.netbeans.api.annotations.common.CheckForNull;
@@ -33,6 +37,13 @@
 import org.netbeans.modules.csl.api.OffsetRange;
 import org.netbeans.modules.csl.spi.support.CancelSupport;
 import org.netbeans.modules.php.editor.CodeUtils;
+import org.netbeans.modules.php.editor.api.ElementQuery;
+import org.netbeans.modules.php.editor.api.elements.MethodElement;
+import org.netbeans.modules.php.editor.model.ClassScope;
+import org.netbeans.modules.php.editor.model.FileScope;
+import org.netbeans.modules.php.editor.model.InterfaceScope;
+import org.netbeans.modules.php.editor.model.ModelUtils;
+import org.netbeans.modules.php.editor.model.TraitScope;
 import org.netbeans.modules.php.editor.parser.PHPParseResult;
 import org.netbeans.modules.php.editor.parser.astnodes.ASTNode;
 import org.netbeans.modules.php.editor.parser.astnodes.Assignment;
@@ -65,6 +76,7 @@
 import org.netbeans.modules.php.editor.parser.astnodes.InstanceOfExpression;
 import org.netbeans.modules.php.editor.parser.astnodes.InterfaceDeclaration;
 import org.netbeans.modules.php.editor.parser.astnodes.LambdaFunctionDeclaration;
+import org.netbeans.modules.php.editor.parser.astnodes.MethodDeclaration;
 import org.netbeans.modules.php.editor.parser.astnodes.MethodInvocation;
 import org.netbeans.modules.php.editor.parser.astnodes.NamespaceDeclaration;
 import org.netbeans.modules.php.editor.parser.astnodes.PHPDocBlock;
@@ -101,6 +113,7 @@
 
     private static final String HINT_ID = "Unused.Variable.Hint"; //NOI18N
     private static final String CHECK_UNUSED_FORMAL_PARAMETERS = "php.verification.check.unused.formal.parameters"; //NOI18N
+    private static final String CHECK_INHERITED_METHOD_PARAMETERS = "php.verification.check.inherited.method.parameters"; //NOI18N
     private static final List<String> UNCHECKED_VARIABLES = new ArrayList<>();
     private Preferences preferences;
 
@@ -128,7 +141,7 @@ public void invoke(PHPRuleContext context, List<Hint> hints) {
             if (CancelSupport.getDefault().isCancelled()) {
                 return;
             }
-            CheckVisitor checkVisitor = new CheckVisitor(fileObject, context.doc);
+            CheckVisitor checkVisitor = new CheckVisitor(fileObject, context.doc, getInheritedMethods(context));
             phpParseResult.getProgram().accept(checkVisitor);
             if (CancelSupport.getDefault().isCancelled()) {
                 return;
@@ -137,6 +150,60 @@ public void invoke(PHPRuleContext context, List<Hint> hints) {
         }
     }
 
+    private Map<String, List<String>> getInheritedMethods(PHPRuleContext context) {
+        if (!checkUnusedFormalParameters(preferences) || checkInheritedMethodParameters(preferences)) {
+            return Collections.emptyMap();
+        }
+        FileScope fileScope = context.fileScope;
+        Collection<? extends ClassScope> allClasses = ModelUtils.getDeclaredClasses(fileScope);
+        ElementQuery.Index index = context.getIndex();
+        Map<String, List<String>> allInheritedMethods = new HashMap<>();
+        for (ClassScope classScope : allClasses) {
+            if (CancelSupport.getDefault().isCancelled()) {
+                return Collections.emptyMap();
+            }
+            Set<MethodElement> inheritedMethods = getInheritedMethods(classScope, index);
+            for (MethodElement inheritedMethod : inheritedMethods) {
+                if (CancelSupport.getDefault().isCancelled()) {
+                    return Collections.emptyMap();
+                }
+                List<String> methodElements = allInheritedMethods.get(inheritedMethod.getName());
+                if (methodElements == null) {
+                    methodElements = new ArrayList<>();
+                    methodElements.add(classScope.getName());
+                    allInheritedMethods.put(inheritedMethod.getName(), methodElements);
+                } else {
+                    methodElements.add(classScope.getName());
+                }
+            }
+        }
+        return allInheritedMethods;
+    }
+
+    private Set<MethodElement> getInheritedMethods(final ClassScope classScope, final ElementQuery.Index index) {
+        Set<MethodElement> inheritedMethods = new HashSet<>();
+        Set<MethodElement> declaredSuperMethods = new HashSet<>();
+        Set<MethodElement> accessibleSuperMethods = new HashSet<>();
+        Collection<? extends ClassScope> superClasses = classScope.getSuperClasses();
+        for (ClassScope cls : superClasses) {
+            declaredSuperMethods.addAll(index.getDeclaredMethods(cls));
+            accessibleSuperMethods.addAll(index.getAccessibleMethods(cls, classScope));
+        }
+        Collection<? extends InterfaceScope> superInterface = classScope.getSuperInterfaceScopes();
+        for (InterfaceScope interfaceScope : superInterface) {
+            declaredSuperMethods.addAll(index.getDeclaredMethods(interfaceScope));
+            accessibleSuperMethods.addAll(index.getAccessibleMethods(interfaceScope, classScope));
+        }
+        Collection<? extends TraitScope> traits = classScope.getTraits();
+        for (TraitScope traitScope : traits) {
+            declaredSuperMethods.addAll(index.getDeclaredMethods(traitScope));
+            accessibleSuperMethods.addAll(index.getAccessibleMethods(traitScope, classScope));
+        }
+        inheritedMethods.addAll(declaredSuperMethods);
+        inheritedMethods.addAll(accessibleSuperMethods);
+        return inheritedMethods;
+    }
+
     private class CheckVisitor extends DefaultVisitor {
 
         private final ArrayDeque<ASTNode> parentNodes = new ArrayDeque<>();
@@ -147,10 +214,14 @@ public void invoke(PHPRuleContext context, List<Hint> hints) {
         private final List<Hint> hints;
         private boolean forceVariableAsUsed;
         private boolean forceVariableAsUnused;
+        private boolean isInInheritedMethod;
+        private String className = ""; // NOI18N
+        private final Map<String, List<String>> allInheritedMethods; // method name, class names
 
-        CheckVisitor(FileObject fileObject, BaseDocument baseDocument) {
+        CheckVisitor(FileObject fileObject, BaseDocument baseDocument, Map<String, List<String>> allInheritedMethods) {
             this.fileObject = fileObject;
             this.baseDocument = baseDocument;
+            this.allInheritedMethods = allInheritedMethods;
             hints = new ArrayList<>();
         }
 
@@ -557,7 +628,9 @@ public void visit(ClassDeclaration node) {
             if (CancelSupport.getDefault().isCancelled()) {
                 return;
             }
+            className = node.getName().getName();
             scan(node.getBody());
+            className = ""; // NOI18N
         }
 
         @Override
@@ -603,12 +676,35 @@ public void visit(CatchClause node) {
             scan(body);
         }
 
+        @Override
+        public void visit(MethodDeclaration node) {
+            if (checkUnusedFormalParameters(preferences) && !checkInheritedMethodParameters(preferences)) {
+                String methodName = node.getFunction().getFunctionName().getName();
+                List<String> classNames = allInheritedMethods.get(methodName);
+                if (classNames != null) {
+                    for (String clsName : classNames) {
+                        if (CancelSupport.getDefault().isCancelled()) {
+                            return;
+                        }
+                        if (className.equals(clsName)) {
+                            isInInheritedMethod = true;
+                            break;
+                        }
+                    }
+                }
+                super.visit(node);
+                isInInheritedMethod = false;
+            } else {
+                super.visit(node);
+            }
+        }
+
         @Override
         public void visit(FormalParameter node) {
             if (CancelSupport.getDefault().isCancelled()) {
                 return;
             }
-            if (checkUnusedFormalParameters(preferences)) {
+            if (checkUnusedFormalParameters(preferences) && !isInInheritedMethod) {
                 scan(node.getParameterName());
             } else {
                 forceVariableAsUsed = true;
@@ -670,6 +766,7 @@ public void visit(LambdaFunctionDeclaration node) {
             if (CancelSupport.getDefault().isCancelled()) {
                 return;
             }
+            isInInheritedMethod = false;
             forceVariableAsUsed = true;
             scan(node.getLexicalVariables());
             forceVariableAsUsed = false;
@@ -849,6 +946,7 @@ public void setPreferences(Preferences preferences) {
     public JComponent getCustomizer(Preferences preferences) {
         JComponent customizer = new UnusedVariableCustomizer(preferences, this);
         setCheckUnusedFormalParameters(preferences, checkUnusedFormalParameters(preferences));
+        setCheckInheritedMethodParameters(preferences, checkInheritedMethodParameters(preferences));
         return customizer;
     }
 
@@ -860,4 +958,12 @@ public boolean checkUnusedFormalParameters(Preferences preferences) {
         return preferences.getBoolean(CHECK_UNUSED_FORMAL_PARAMETERS, true);
     }
 
+    public void setCheckInheritedMethodParameters(Preferences preferences, boolean isEnabled) {
+        preferences.putBoolean(CHECK_INHERITED_METHOD_PARAMETERS, isEnabled);
+    }
+
+    public boolean checkInheritedMethodParameters(Preferences preferences) {
+        return preferences.getBoolean(CHECK_INHERITED_METHOD_PARAMETERS, true);
+    }
+
 }
diff --git a/php/php.editor/test/unit/data/testfiles/verification/testUnusedVariableInInheritedMethodParameters.php b/php/php.editor/test/unit/data/testfiles/verification/testUnusedVariableInInheritedMethodParameters.php
new file mode 100644
index 0000000000..a2872d7206
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/verification/testUnusedVariableInInheritedMethodParameters.php
@@ -0,0 +1,69 @@
+<?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.
+ */
+
+abstract class ParentClass {
+
+    abstract function test1($param1, $param2);
+
+    abstract function test2($param1, $param2);
+
+    abstract function test3($param1, $param2);
+
+    public function parentMethod(string $param1, int $param2): string {
+        return $param1 . $param2;
+    }
+
+}
+
+interface InterfaceTest {
+
+    public function interfaceMethod(string $test): void;
+}
+
+class ChildClass extends ParentClass implements InterfaceTest {
+
+    public function interfaceMethod(string $test): void {
+        
+    }
+
+    public function parentMethod(string $param1, int $param2): string {
+        
+    }
+
+    public function test($param1, string $param2): void {
+        
+    }
+
+    public function test1($param1, $param2) {
+        
+    }
+
+    public function test2($param1, $param2) {
+        $anon = function($anonParam) {
+            
+        };
+    }
+
+    public function test3($param1, $param2) {
+        
+    }
+
+}
diff --git a/php/php.editor/test/unit/data/testfiles/verification/testUnusedVariableInInheritedMethodParameters.php.testUnusedVariableInInheritedMethodParameters_01.hints b/php/php.editor/test/unit/data/testfiles/verification/testUnusedVariableInInheritedMethodParameters.php.testUnusedVariableInInheritedMethodParameters_01.hints
new file mode 100644
index 0000000000..74b10f5fe3
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/verification/testUnusedVariableInInheritedMethodParameters.php.testUnusedVariableInInheritedMethodParameters_01.hints
@@ -0,0 +1,27 @@
+    public function interfaceMethod(string $test): void {
+                                            ----
+HINT:Variable $test seems to be unused in its scope
+    public function parentMethod(string $param1, int $param2): string {
+                                                      ------
+HINT:Variable $param1 seems to be unused in its scope
+HINT:Variable $param2 seems to be unused in its scope
+    public function test($param1, string $param2): void {
+                                          ------
+HINT:Variable $param1 seems to be unused in its scope
+HINT:Variable $param2 seems to be unused in its scope
+    public function test1($param1, $param2) {
+                                    ------
+HINT:Variable $param1 seems to be unused in its scope
+HINT:Variable $param2 seems to be unused in its scope
+    public function test2($param1, $param2) {
+                                    ------
+HINT:Variable $param1 seems to be unused in its scope
+HINT:Variable $param2 seems to be unused in its scope
+        $anon = function($anonParam) {
+                          ---------
+HINT:Variable $anon seems to be unused in its scope
+HINT:Variable $anonParam seems to be unused in its scope
+    public function test3($param1, $param2) {
+                                    ------
+HINT:Variable $param1 seems to be unused in its scope
+HINT:Variable $param2 seems to be unused in its scope
diff --git a/php/php.editor/test/unit/data/testfiles/verification/testUnusedVariableInInheritedMethodParameters.php.testUnusedVariableInInheritedMethodParameters_02.hints b/php/php.editor/test/unit/data/testfiles/verification/testUnusedVariableInInheritedMethodParameters.php.testUnusedVariableInInheritedMethodParameters_02.hints
new file mode 100644
index 0000000000..0b5fec3627
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/verification/testUnusedVariableInInheritedMethodParameters.php.testUnusedVariableInInheritedMethodParameters_02.hints
@@ -0,0 +1,8 @@
+    public function test($param1, string $param2): void {
+                                          ------
+HINT:Variable $param1 seems to be unused in its scope
+HINT:Variable $param2 seems to be unused in its scope
+        $anon = function($anonParam) {
+                          ---------
+HINT:Variable $anon seems to be unused in its scope
+HINT:Variable $anonParam seems to be unused in its scope
diff --git a/php/php.editor/test/unit/data/testfiles/verification/testUnusedVariableInInheritedMethodParameters.php.testUnusedVariableInInheritedMethodParameters_03.hints b/php/php.editor/test/unit/data/testfiles/verification/testUnusedVariableInInheritedMethodParameters.php.testUnusedVariableInInheritedMethodParameters_03.hints
new file mode 100644
index 0000000000..590d81dd20
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/verification/testUnusedVariableInInheritedMethodParameters.php.testUnusedVariableInInheritedMethodParameters_03.hints
@@ -0,0 +1,3 @@
+        $anon = function($anonParam) {
+         ----
+HINT:Variable $anon seems to be unused in its scope
diff --git a/php/php.editor/test/unit/data/testfiles/verification/testUnusedVariableInInheritedMethodParameters.php.testUnusedVariableInInheritedMethodParameters_04.hints b/php/php.editor/test/unit/data/testfiles/verification/testUnusedVariableInInheritedMethodParameters.php.testUnusedVariableInInheritedMethodParameters_04.hints
new file mode 100644
index 0000000000..590d81dd20
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/verification/testUnusedVariableInInheritedMethodParameters.php.testUnusedVariableInInheritedMethodParameters_04.hints
@@ -0,0 +1,3 @@
+        $anon = function($anonParam) {
+         ----
+HINT:Variable $anon seems to be unused in its scope
diff --git a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/verification/UnusedVariableHintTest.java b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/verification/UnusedVariableHintTest.java
index 8f24288aa8..da1ef4b214 100644
--- a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/verification/UnusedVariableHintTest.java
+++ b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/verification/UnusedVariableHintTest.java
@@ -54,11 +54,35 @@ public void testIssue246230() throws Exception {
         checkHints(new UnusedVariableHintStub(false), "testIssue246230.php");
     }
 
+    // NETBEANS-1718
+    public void testUnusedVariableInInheritedMethodParameters_01() throws Exception {
+        checkHints(new UnusedVariableHintStub(true, true), "testUnusedVariableInInheritedMethodParameters.php");
+    }
+
+    public void testUnusedVariableInInheritedMethodParameters_02() throws Exception {
+        checkHints(new UnusedVariableHintStub(true, false), "testUnusedVariableInInheritedMethodParameters.php");
+    }
+
+    public void testUnusedVariableInInheritedMethodParameters_03() throws Exception {
+        checkHints(new UnusedVariableHintStub(false, true), "testUnusedVariableInInheritedMethodParameters.php");
+    }
+
+    public void testUnusedVariableInInheritedMethodParameters_04() throws Exception {
+        checkHints(new UnusedVariableHintStub(false, false), "testUnusedVariableInInheritedMethodParameters.php");
+    }
+
     private class UnusedVariableHintStub extends UnusedVariableHint {
         private final boolean unusedFormalParameters;
+        private final boolean inheritedMethodParameters;
 
         public UnusedVariableHintStub(boolean unusedFormalParameters) {
             this.unusedFormalParameters = unusedFormalParameters;
+            this.inheritedMethodParameters = false;
+        }
+
+        public UnusedVariableHintStub(boolean unusedFormalParameters, boolean inheritedMethodParameters) {
+            this.unusedFormalParameters = unusedFormalParameters;
+            this.inheritedMethodParameters = inheritedMethodParameters;
         }
 
         @Override
@@ -66,6 +90,11 @@ public boolean checkUnusedFormalParameters(Preferences preferences) {
             return unusedFormalParameters;
         }
 
+        @Override
+        public boolean checkInheritedMethodParameters(Preferences preferences) {
+            return inheritedMethodParameters;
+        }
+
     }
 
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists