Welcome to Dream.In.Code
Become a Java Expert!

Join 150,135 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,228 people online right now. Registration is fast and FREE... Join Now!




Finding unused variables in java through code

 
Reply to this topicStart new topic

Finding unused variables in java through code

codequest
7 Aug, 2008 - 03:18 AM
Post #1

New D.I.C Head
*

Joined: 7 Aug, 2008
Posts: 1

Hi All,
I am planning to create a project analyzer tool which will find the unused variables and functions present in the java project and list it out. Please give me your valuable suggestions how i can go about it. How we can find the variables in the java program by parsing through the file.

Thanks,
CodeQuest
User is offlineProfile CardPM
+Quote Post

1lacca
RE: Finding Unused Variables In Java Through Code
7 Aug, 2008 - 03:55 AM
Post #2

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 12 times
My Contributions
You write a parser against the Java language specification.
Or use something that is already there, like ANTLR or the built-in things in NetBeans, Eclipse or some other popular open source IDE / framework.
However once a project uses reflection to call methods and access variables, it becomes pretty much impossible to create such a tool...
User is offlineProfile CardPM
+Quote Post

potator
RE: Finding Unused Variables In Java Through Code
8 Aug, 2008 - 08:58 PM
Post #3

D.I.C Head
Group Icon

Joined: 2 Dec, 2007
Posts: 78



Thanked: 1 times
Dream Kudos: 175
My Contributions
One solution:

1) search the file for variable declaration.
2) search subsequent code for references to the same object.

It's basically a searching problem.
User is offlineProfile CardPM
+Quote Post

jTopcoder
RE: Finding Unused Variables In Java Through Code
14 Sep, 2008 - 01:23 PM
Post #4

New D.I.C Head
*

Joined: 14 Sep, 2008
Posts: 1

There is a similar tool: UCDetector
I think this tool is limited to Eclipse IDE and uses the internal eclipse parser.

Here the description from the homepage:
UCDetector (Unecessary Code Detector) is a Open Source eclipse PlugIn Tool to find unecessary (dead) java code. It also tries to make code final, protected or private.
UCDetector also finds cyclic dependencies between classes.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 01:56AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month