Java : Import a class programmatically [message #1702517] |
Wed, 22 July 2015 19:48 |
Viktor Py Messages: 1 Registered: July 2015 |
Junior Member |
|
|
I have a CompilationUnit that contains a class where a reference to another class is not imported. Eclipse resolves that kind of issue easily and proposes to import the missing class (which is located in the parent package).
How can I import a missing class programmatically without knowing its name or location ?
Reflection, injection, ClassLoader and other runtime mechanisms are not the right choice as I'm processing the classes statically through the Eclipse JDT API. Please, I'm just looking for a static oriented solution.
FYI : this how we list the imports from a CompilationUnit :
List<ImportDeclaration> existingImports = aCompilationUnit.imports();
The problem is that I don't know how to generate missing ImportDeclaration.
Thanks.
[Updated on: Wed, 22 July 2015 20:07] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03704 seconds