In Eclipse, how do you find methods that you have defined but not used/called anywhere in the app?
Asked Answered
S

3

5

I am concerned that some of the classes in my app have methods that are defined but not called anywhere in the app.

In Eclipse is there a way to find these methods?

Sandstorm answered 3/11, 2010 at 19:49 Comment(2)
It's not elegant, but you could do a search for them...if they appear more than once, they've been called. Obviously, this would be incredibly time consuming for any more than a couple of methods...Gardiner
Use Intellij instead. (Just kidding. (Not Really.))Beachhead
L
10

You can use Findbugs for this, but there's also a plugin dedicated to this: UCDetector.

Laruelarum answered 3/11, 2010 at 19:53 Comment(2)
+1, and thanks for the link to UCDetector. Of course, this isn't likely able to analyze the runtime behaviour of your code to know certain circumstances (e.g. if a certain override of a certain method is ever going to be called--for instance, any particular toString() override).Bosk
@Mark: UCDetector homepage also disclaims that it would only generate suggestions since the code might be referenced directly or indirectly by reflection (and frameworks using reflection under the covers like EL, JPA, javabean tools, etc). Not entirely useful plugin for enterprise applications imo, but may be useful for simple client Java applications.Laruelarum
D
0

The quickest way to find usages of a single method would be to highlight the method, right click and go to "References", from there you can choose search location like workspace, project etc.

Obviously this wouldn't be a good way to find ALL the methods in the project that aren't being used, but it might be worth using if you just looking at one odd looking method that you can't figure out why you need.

Dy answered 3/11, 2010 at 21:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.