Fixed 3468 unused private method call on inner class

This commit is contained in:
John Armgardt
2021-12-10 15:10:05 -06:00
parent f18ceebd7b
commit 8df5768bc9
2 changed files with 24 additions and 0 deletions

View File

@ -230,7 +230,13 @@ public class ClassScope extends AbstractJavaScope {
Map<ClassNameDeclaration, List<NameOccurrence>> classDeclarations = getClassDeclarations();
if (result.isEmpty() && !classDeclarations.isEmpty()) {
for (ClassNameDeclaration innerClass : getClassDeclarations().keySet()) {
ASTMethodDeclarator md = innerClass.getNode().getFirstDescendantOfType(ASTMethodDeclarator.class);
if (md != null) {
images.add(md.getImage());
finder = new ImageFinderFunction(images);
}
Applier.apply(finder, innerClass.getScope().getDeclarations(VariableNameDeclaration.class).keySet().iterator());
Applier.apply(finder, innerClass.getScope().getDeclarations(MethodNameDeclaration.class).keySet().iterator());
if (finder.getDecl() != null) {
result.add(finder.getDecl());
}

View File

@ -1727,4 +1727,22 @@ public class Outer {
}
]]></code>
</test-code>
<test-code>
<description>#3468 UnusedPrivateMethod false positive when outer class calls private static method on inner class</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class OuterClass {
public void foo() {
InnerClass.doSomething();
}
static class InnerClass {
private static void doSomething() {
}
}
}
]]></code>
</test-code>
</test-data>