Unused method not caught by Inspection

If my class has a public method which isn't used anywhere and I run Inspection on that class (Analyze | Inspect Code), the unused method isn't getting caught in "Unused declaration"

5 comments
Comment actions Permalink

Its public. How could IntelliJ possibly know if it isn't used?

You could jar up that class in a library and that method could be used elsewhere.

0
Comment actions Permalink

Previous version of IntelliJ (before 8.0), the Inspection tool is really smart, it knows if the public method isn't used anywhere. I use that feature a lot to clean up classes.

Edited by: dota168 on Nov 13, 2008 10:46 PM

0
Comment actions Permalink

Hello dota168,

How do you invoke Inspect Code? Which scope do you use? Are you sure that
Unused declaration inspection is switched on?

Thank you
-


Anna Kozlova
JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

If my class has a public method which isn't used anywhere and I run
Inspection on that class (Analyze | Inspect Code), the unused method
isn't getting caught in "Unused declaration"



0
Comment actions Permalink

Hi Anna,

I use "Analyze | Inspect Code".

Inspection scope: File
Inspection profile: "Run with chosen profile", Default (with Declaration Redundancy -> Unused declaration checked)

I created a project from scratch to test it on a clean slate and created just 1 class:

public class TestClass {
public void testMethod1() {
System.out.println("test Method 1");
}

public void testMethod2() {
System.out.println("test Method 2");
}

public static void main(String[] args) {
TestClass test = new TestClass();
test.testMethod1();
}
}

Running "Find Usage (Alt - F7)" on testMethod2() shows a balloon with a message "No usages found on Project files".

Running "Analyze | Inspect Code" doesn't says that testMethod2() is never used.

0
Comment actions Permalink

Hello,

Indeed Declaration Redundancy presentation is broken. Should be fixed in
next EAP

For now please check 'Group by directory' toolbar button in order to get
this inspection results

Sorry for inconvenience

Thank you
-


Anna Kozlova
JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

Hi Anna,

I use "Analyze | Inspect Code".

Inspection scope: File
Inspection profile: "Run with chosen profile", Default (with
Declaration Redundancy -> Unused declaration checked)
I created a project from scratch to test it on a clean slate and
created just 1 class:

public class TestClass {
public void testMethod1() {
System.out.println("test Method 1");
}
public void testMethod2() {
System.out.println("test Method 2");
}
public static void main(String[] args) {
TestClass test = new TestClass();
test.testMethod1();
}
}
Running "Find Usage (Alt - F7)" on testMethod2() shows a balloon
with a message "No usages found on Project files".

Running "Analyze | Inspect Code" doesn't says that testMethod2() is
never used.



0

Please sign in to leave a comment.