Weijiang Yu wrote: > My question is, how can I obtain all classes in which the method m could > be overrided? In other words, how can I obtain all methods that can be > called at runtime? It requires some kind of class tree, and I don't know > if BCEL provides ways to do that.
First of all, note that an invokevirtual class.method can actually end up calling methods defined in *superclasses* of "class", because of the late binding mechanism: A a = new A(); a.toString(); calls Object.toString() if A extends Object and A does not redefine toString(). The information you are looking for is not directly provided by bcel since it is not contained in the .class files. A class does not know which are its subclasses. You have to scan the .class files accessible through the classpath, and check if they define a method which can be called by the invokevirtual. As I showed before, this is not just a matter of checking for a subclass. Moreover, parsing all such classes through bcel would be slow and memory consuming. Think about using standard Java reflection instead. Remeber, finally, that the result would be different in different running environments, where different classes might be installed... By the way, your problem is called "class hierarchy analysis". Check Dean, Grove and Chambers, "Optimization of OO Programs using Static Class Hierarchy Analysis", ECOOP'95, volume 952 of Lecture Notes in Computer Science, Springer-Verlag, 1995. - Fausto Spoto --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
