unused declaration: report methods directly called from test sources (IDEA-160530)

This commit is contained in:
Anna Kozlova
2016-09-05 07:57:43 +03:00
parent b041f6f0e9
commit 874d6d8d5b
6 changed files with 53 additions and 0 deletions
@@ -122,6 +122,11 @@ public class UnusedDeclarationPresentation extends DefaultInspectionToolPresenta
final int problemCount = super.getElementProblemCount(refElement);
if (problemCount > - 1) return problemCount;
if (!((RefElementImpl)refElement).hasSuspiciousCallers() || ((RefJavaElementImpl)refElement).isSuspiciousRecursive()) return 1;
for (RefElement element : refElement.getInReferences()) {
if (((UnusedDeclarationInspectionBase)myTool).isEntryPoint(element)) return 1;
}
return 0;
}
}
@@ -10,5 +10,15 @@
<line>1</line>
<description>Class has one instantiation but it is not reachable from entry points.</description>
</problem>
<problem>
<file>Test.java</file>
<line>2</line>
<description>&lt;ul&gt;&lt;li&gt;Method owner class is never instantiated OR&lt;/li&gt;&lt;li&gt;An instantiation is not reachable from entry points.&lt;/li&gt;&lt;/ul&gt;</description>
</problem>
<problem>
<file>Test.java</file>
<line>1</line>
<description>Class has one instantiation but it is not reachable from entry points.</description>
</problem>
</problems>
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>2</line>
<description>Method has one usage but it is not reachable from entry points.</description>
</problem>
<problem>
<file>Main.java</file>
<line>6</line>
<description>Method is never used.</description>
</problem>
</problems>
@@ -0,0 +1,3 @@
public class Test {
public static void doSmth() {}
}
@@ -0,0 +1,9 @@
public class Main {
public static void main(String[] args) {
Test.doSmth();
}
public static void unusedInTestScope() {
System.out.println("hey");
}
}
@@ -37,6 +37,16 @@ public class UnusedDeclarationInProjectTest extends AbstractUnusedDeclarationTes
}
}
public void testInstantiatedInTestOnlyStatic() throws Exception {
myTool.setTestEntryPoints(false);
try {
doTest();
}
finally {
myTool.setTestEntryPoints(true);
}
}
public void testIgnoreUnusedFields() throws Exception {
myTool.getSharedLocalInspectionTool().FIELD = false;
try {