Does anyone have an example how to redefine an import in a java source file using the Eclipse JDT Core API?
I have the following (which does not work) and it's driving me mad.
try {
for (IPackageFragmentRoot root : project.getPackageFragmentRoots()) {
if (root.getElementName().equals("src")) {
for (ICompilationUnit unit : root.getPackageFragment("soap.service.implementation.strongProfile.delegate").getCompilationUnits()) {
System.out.println(unit.getElementName());
for (IImportDeclaration dec : unit.getImports()) {
dec.rename("soap.service.implementation.strongProfile.reader.HeadlineReader", true, null);
}
}
}
}
}catch(Exception e) {
e.printStackTrace();
}
The exception I get is:
Java Model Exception: Java Model Status [Invalid name specified: soap.service.implementation.strongProfile.reader.HeadlineReader]
I take the import name and paste it in to my java source file and it's perfect, it doesn't give me any errors. Any help or guidance would be appreciated.