• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java source code analyser  RSS feed

 
puff li
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to find classes which extends "Thread" or implements "Runnable" from java source code and then replace code of its instance which starts a new thread with another piece of code. Is there any existing tool completing this task?

Thanks.
 
Naman Patidar
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use Eclipse for this. Select the class or interface and press Ctr+Shift+g. It will search and list the references.
 
puff li
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Namam,

Thanks. I think I didn't make myself clear. I wanna write a program to do this automatically. I have a bunch of source file to process.
 
Martin Vanyavchich
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure if I understand what you're asking, but dosen't every class that extends Thread or implements Runnable do exactly what you described? Look here. If I misunderstood you please refrase the question
 
puff li
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know how to start a thread. My problem is to replace normal way of starting a thread with the way of Javaflow. So I need to look at the source code and replace obj.start() with Continuation.startWith(obj). Since other classes can also have the start() method, I can't simply find start() in source code and replace it directly. I need to make sure the obj extends Thread. The situation is complicated because you can return a Thread object from a function (ie. a.returnThread().start()), then I have to make sure a.returnThread() returns an object of Thread.

Am I clear?
 
Martin Vanyavchich
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry I don't know of any such tool. If you find it please report back, it seems like a powerfull thing ... if it exists
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The original answer of "use Eclipse" is not a bad idea, actually. You could write an Eclipse plug-in which leveraged the Java development tools in Eclipse -- it would work the same way that the various refactorings do. There are plenty of example open-source Eclipse plugins that implement various refactorings, so you can probably find something quite close to what you want and modify it.

Another alternative would be a bytecode-processing library like Javassist, which lets you read, write, and modify class files directly. You wouldn't have the modified source code then, of course.

 
Campbell Ritchie
Marshal
Posts: 56595
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you looked in the API documentation for Runnable or Thread? Doesn't it give a list of implementing classes and subclasses?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!