Background
I am creating a tool that will turn Java code into a UML Class Diagram. As I only have 3 weeks to do it, my teacher suggested I use the Java Debug Interface rather than creating a parser to do this task.
Problem
I have registered for the ClassPrepareEvents which shows when a class is loaded by the VM (see code snippet below), however classes are only loaded as and when they are needed. For example, if clicking on a button in the GUI creates an object of type A, then A won't be loaded until a user clicks on the button.
This needs to be an automated tool, so needs to load all classes within the program without user interaction, so how would one go about manually loading all these classes? Or is there something in the API that I've missed and there's another way of doing this?
Thanks in advance! :)
Code Snippet
EventRequestManager em=vm.eventRequestManager();
ClassPrepareRequest cpR = em.createClassPrepareRequest();
cpR.addClassFilter("project.*");
cpR.enable();
EventQueue eventQ=vm.eventQueue();
while (true) {
EventSet eventSet=null;
try {
eventSet=eventQ.remove();
} catch (Exception e) { // handle the error
continue;
}
EventIterator eventIterator=eventSet.eventIterator();
while (eventIterator.hasNext()) {
Event event=eventIterator.nextEvent();
if(event instanceof ClassPrepareEvent) {
ClassPrepareEvent classPrepareEvent = (ClassPrepareEvent)event;
ReferenceType refType = classPrepareEvent.referenceType();
System.out.println(refType.name() + " loaded.");
}
}
}