• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

How can I check whether a class uses a particular other class?  RSS feed

 
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In our application, we have a class doing debug-related stuff. Every call to it is supposed to be protected by a check of the value of a particular constant, set by generated code which is different, depending on whether the build is for debug or release purposes. The idea is that a release build will not use, or even load, the debug class.

This works fine, except when people forget to protect their code appropriately. Therefore, I would like to make a little tool, to run during the build process, to check whether we have successfully excluded the debug class.

The approach that currently seems most attractive is to look in each class file to see if there are any bytecodes that refer to the debug class. There shouldn't be any, for a release build.

Is this feasible? What would be the best way to examine the class file?

Any other ideas? I did a very quick program that did a rather dumb examination of the source. It was pretty good at spotting the mistakes, but created quite a lot of false positives (where it thought there was a mistake, but there wasn't really).
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For what it's worth, if I had to do something like that, I would look at whether a byte code manipulation library like ASM or BCEL could help me.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suppose something like BCEL could be used, but it seems rather heavyweight, for my one, relatively simple requirement.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!