How can I get the root-node of a InputSource in one processor in a simple way?
I set a directory as the inputSource then process it by launcher.run(). When I process a ctClass, is there any way I can get the root-node of the generated ctModel? Thx.
Have you tried:
//From your launcher
launcher.getModel().getRootPackage()
//from your CtClass
((CtPackage) ctClass.getParent(CtModelImpl.CtRootPackage.class));
?
Have you tried:
//From your launcher launcher.getModel().getRootPackage() //from your CtClass ((CtPackage) cl.getParent(CtModelImpl.CtRootPackage.class));?
I tried just now. It worked.
I used to start my program with launcher.run() , then I replaced it with CtModel model = launcher.buildModel(); launcher.process(); , I can get the model in 'Main.java'.
I'm trying to get the CtModel in processor class.
Thank you!
If you want to access the CtModel in your processor, you can get it from the launcher and pass it as a parameter for the processor's constructor.
If you want to access the
CtModelin your processor, you can get it from the launcher and pass it as a parameter for the processor's constructor.
Good idea! While here I loaded all processors in one package automatically by an init() method, so I set CtModel object to a static field of one Utility class then I can access it anywhere. Thank you!
I close this issue, but if you are further question, don't hesitate to reopen or to open a new one.
I close this issue, but if you are further question, don't hesitate to reopen or to open a new one.
Ok, I forgot that. Thank you.