Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Rename package programmatically(Rename package programmatically)
Rename package programmatically [message #1227099] Fri, 03 January 2014 09:48 Go to next message
Eclipse UserFriend
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 #1229591 is a reply to message #1227099] Thu, 09 January 2014 14:36 Go to previous messageGo to next message
Eclipse UserFriend
Looking at the referenced line in RefactoringExecutionHelper, I see:
		Assert.isTrue(Display.getCurrent() != null);


Are you trying to run your operation in a headless environment?

Stephan
Re: Rename package programmatically [message #1229614 is a reply to message #1229591] Thu, 09 January 2014 15:43 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for the response. If by 'headless' you mean no UI (running it outside of Eclipse), I'm not running headless. I'm trying to kick this operation off from w/in Eclipse from a custom wizard.

The wizard uses standard JDT functions to implement the import operation. This piece is intended to apply package renaming (refactoring) based on the package name that the user entered as he/she filled out pages w/in the wizard.
Re: Rename package programmatically [message #1229634 is a reply to message #1229614] Thu, 09 January 2014 16:40 Go to previous message
Eclipse UserFriend
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

Previous Topic:CallBack Object creation in Host plugin
Next Topic:java question?
Goto Forum:
  


Current Time: Thu Apr 24 09:24:35 EDT 2025

Powered by FUDForum. Page generated in 0.05083 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top