• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Removing Unread and Unused Variable

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI
Is there anyway by using Java API we can find out whether a variable(Class level and local) is unread(unused) or not.Plz do reply
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hmmm, I don't know how they implement it, but I know IntelliJ IDEA has a code highlighting feature that does just what you're asking:

IntelliJ IDEA's On-the-Fly Code Analysis
Highlighting unused imports, throws declarations and other unused symbols
IDEA will point out all redundant import statements, throws declarations and other unused symbols (like variables and methods), and will highlight them in the editor with the corresponding links on the right gutter area for easier navigation. More information on other code analysis features can be found here.

 
Ranch Hand
Posts: 539
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Eclipse can also find unread/unused local variables, though I don't think its code analysis is in the same league as IDEA.
In 3.0, go Window->Preferences->Java->Compiler to see the options you have.
Cheers,

--Tim
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
seeing as though Eclipse is open source, you may be able to look through the code to see how they do it -- if you're interested in the actual Java code rather than just the functionality.
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
all features mentioned on Jessicas link (the girl who likes....) are available in eclipse too - so what's their league?
 
Craig Williams
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My question is thru programatically ,can we remove the unused variable or Unread variable .Is there any java API can we use?.. or any tool to remove those variables completely from our program
 
Stefan Wagner
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the difference between 'remove' and 'remove completly'?
In particular when it is unused?
Do you want to remove them from a compiled class or from source-code?
Are you looking for something like:
 
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe there are some java code beautifiers/formatters that can do this for you. Ty looking at things like Jalopy, Jindent, and Jacobe (and possibly others).

Brian
 
permaculture is a more symbiotic relationship with nature so I can be even lazier. Read tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic