Rename package programmatically [message #1227099] |
Fri, 03 January 2014 09:48  |
Eclipse User |
|
|
|
I'm attempting to build an Eclipse new project wizard which uses JDT functions to copy a template project into a user's workspace, then apply some minor refactorings as per the user's preferences. One of these refactorings is to rename one of the Java package names from the template to whatever package name the user specifies. For example, the template contains 'default.template.MyClass' which would need to be renamed to '<whatever.package.is.specified>.MyClass.
I've tried several different ways, but nothing seems to work. My latest attempt looks something like this (I've included hard-coded the values to make this easier to interpret):
IType fromClass = project.findType("default.template.MyClass");
ICompilationUnit compUnit = fromClass.getCompilationUnit();
RenameSupport support = RenameSupport.create(
fromClass.getCompilationUnit(),
"testing.MyClass",
RenameSupport.UPDATE_REFERENCES);
ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
support.perform(shell,dialog);
When I run this code, I get this error:
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
at org.eclipse.core.runtime.Assert.isTrue(Assert.java:110)
at org.eclipse.core.runtime.Assert.isTrue(Assert.java:96)
at org.eclipse.jdt.internal.ui.refactoring.RefactoringExecutionHelper.perform(RefactoringExecutionHelper.java:165)
at org.eclipse.jdt.internal.ui.refactoring.RefactoringExecutionHelper.perform(RefactoringExecutionHelper.java:151)
at org.eclipse.jdt.ui.refactoring.RenameSupport.perform(RenameSupport.java:198)
Any ideas on what's causing this error? Or maybe there's a better way to do this type of refactoring? Thanks in advance!
|
|
|
|
|
Re: Rename package programmatically [message #1229634 is a reply to message #1229614] |
Thu, 09 January 2014 16:40  |
Eclipse User |
|
|
|
Hm, if you're running the code from a wizard you should definitely have a display initialized.
Ah, wait, I mixed getCurrent() with getDefault(). If you look at Display.getCurrent() it actually tells you, that you must run this on the UI thread. So the recommended way would be to wrap your operation in a org.eclipse.ui.progress.UIJob.
HTH
Stephan
|
|
|
Powered by
FUDForum. Page generated in 0.05083 seconds