Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Rename package programmatically(Rename package programmatically)
Rename package programmatically [message #1227099] Fri, 03 January 2014 14:48 Go to next message
Rick Crawford is currently offline Rick CrawfordFriend
Messages: 1
Registered: January 2014
Junior Member
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 19:36 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
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 20:43 Go to previous messageGo to next message
Rick Crawford is currently offline Rick CrawfordFriend
Messages: 6
Registered: July 2009
Junior Member
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 21:40 Go to previous message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
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: Fri Apr 19 07:05:25 GMT 2024

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

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

Back to the top