ICompilationUnit src = JavaUtils.getCompilationUnit(project, file);
IPackageFragmentRoot root = JavaModelUtil.getPackageFragmentRoot(src);
IPackageFragment pack = root.getPackageFragment(packName);
ICompilationUnit dest = pack.getCompilationUnit(src.getElementName());
if (dest.exists()){
throw new RefactorException(Services.getMessage(
"move.element.exists",
pack.getElementName(),
src.getElementName()));
}
if(!pack.exists()){
pack = root.createPackageFragment(packName, true, null);
}
IMovePolicy policy = ReorgPolicyFactory.createMovePolicy(
new IResource[0],
new IJavaElement[]{src});
JavaMoveProcessor processor = new JavaMoveProcessor(policy);
IReorgDestination destination =
ReorgDestinationFactory.createDestination(pack);
RefactoringStatus status = processor.setDestination(destination);
if (status.hasError()){
throw new RefactorException(status);
}
Shell shell = EclimPlugin.getShell();
processor.setCreateTargetQueries(new CreateTargetQueries(shell));
processor.setReorgQueries(new ReorgQueries(shell));