unused: search for main in inner classes (IDEA-178721)

This commit is contained in:
Anna Kozlova
2017-09-11 19:02:58 +03:00
parent 25a1f5b3f3
commit e129868d33
3 changed files with 21 additions and 1 deletions
@@ -400,7 +400,9 @@ public class UnusedDeclarationInspectionBase extends GlobalInspectionTool {
if (isAddServletEnabled() && servlet != null && aClass.isInheritor(servlet, true)) {
return true;
}
if (isAddMainsEnabled() && PsiMethodUtil.hasMainMethod(aClass)) return true;
if (isAddMainsEnabled()) {
if (hasMainMethodDeep(aClass)) return true;
}
}
if (element instanceof PsiModifierListOwner) {
final EntryPointsManager entryPointsManager = EntryPointsManager.getInstance(project);
@@ -414,6 +416,16 @@ public class UnusedDeclarationInspectionBase extends GlobalInspectionTool {
return RefUtil.isImplicitUsage(element);
}
private static boolean hasMainMethodDeep(PsiClass aClass) {
if (PsiMethodUtil.hasMainMethod(aClass)) return true;
for (PsiClass innerClass : aClass.getInnerClasses()) {
if (innerClass.hasModifierProperty(PsiModifier.STATIC) && PsiMethodUtil.hasMainMethod(innerClass)) {
return true;
}
}
return false;
}
public boolean isGlobalEnabledInEditor() {
return myEnabledInEditor;
}
@@ -0,0 +1,7 @@
class Test {
static class NestedTest {
public static void main(String[] args) {
new Test();
}
}
}
@@ -35,6 +35,7 @@ public class UnusedSymbolLocalTest extends DaemonAnalyzerTestCase {
}
public void testInnerClass() throws Exception { doTest(); }
public void testInnerClassWithMainMethod() throws Exception { doTest(); }
public void testInnerUsesSelf() throws Exception { doTest(); }
public void testLocalClass() throws Exception { doTest(); }
public void testPrivateConstructor() throws Exception { doTest(); }