Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Move refactoring via descriptors
Move refactoring via descriptors [message #248328] Tue, 02 October 2007 16:25 Go to next message
Eclipse UserFriend
Hi all,

I'd like to do a programmatic move refactoring of a Java file.
Since eclipse 3.3 refactorings should be done via descriptors.

What I need is a instance of MoveDescriptor and tried the following snippet:

RefactoringContribution refactoringContribution =
RefactoringCore.getRefactoringContribution(IJavaRefactorings .MOVE);
MoveDescriptor refactoringDescriptor = (MoveDescriptor)
refactoringContribution.createDescriptor();

In this case the descriptor is null.
So I tried to call the following createDescriptor-method:

createDescriptor(final String id, final String project, final String
description, final String comment, final Map arguments, final int flags)

But in this case I get a instance of JDTRefactoringDescriptor.
I don't want to implement the whole move refactoring on my own and as
https://bugs.eclipse.org/bugs/show_bug.cgi?id=61817
is fixed it should be possible.

Any hints? Thanks for help.

Vera
Re: Move refactoring via descriptors [message #248338 is a reply to message #248328] Wed, 03 October 2007 07:20 Go to previous messageGo to next message
Eclipse UserFriend
You can perform the refactoring easy by the followings code:

ICompilationUnit javaFile;
....
List elementList = new ArrayList();
elementList.add(javaFile);
IResource[] resources = ReorgUtils.getResources(elementList);
IJavaElement[] elements = ReorgUtiles.getJavaElements(elementList);
IMovePolicy policy = ReorgPolicyFactory.createMovePolicy(resources,
elements);
JavaMoveProcessor processor = new JavaMoveProcessor(policy);
MoveRefactoring refactoring = new MoveRefactoring(processor);
IReorgQueries yourQueries;
....
processor.setReorgQueries(yourQueries);
// yours option here
processor.setDestination();
processor.setUpdateReferences();
processor.setUpdateQualifiedNames();
RefactoringStatus status = refactoring.checkAllConditions(monitor);
if (!status.hasFatalError()) {
Change change = refactoring.createChange(monitor);
change.initializeValidationData(monitor);
change.perform(monitor);
}



Vera Wahler wrote:
> Hi all,
>
> I'd like to do a programmatic move refactoring of a Java file.
> Since eclipse 3.3 refactorings should be done via descriptors.
>
> What I need is a instance of MoveDescriptor and tried the following
> snippet:
>
> RefactoringContribution refactoringContribution =
> RefactoringCore.getRefactoringContribution(IJavaRefactorings .MOVE);
> MoveDescriptor refactoringDescriptor = (MoveDescriptor)
> refactoringContribution.createDescriptor();
>
> In this case the descriptor is null.
> So I tried to call the following createDescriptor-method:
>
> createDescriptor(final String id, final String project, final String
> description, final String comment, final Map arguments, final int flags)
>
> But in this case I get a instance of JDTRefactoringDescriptor.
> I don't want to implement the whole move refactoring on my own and as
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=61817
> is fixed it should be possible.
>
> Any hints? Thanks for help.
>
> Vera
Re: Move refactoring via descriptors [message #248479 is a reply to message #248338] Mon, 08 October 2007 06:55 Go to previous message
Eclipse UserFriend
The code in Vera's post is how it should work. The bug is in our code
when 'null' is returned on refactoringContribution.createDescriptor().
This got fixed in 3.4 M1, but also needs to be fixed in 3.3.2
I filed https://bugs.eclipse.org/bugs/show_bug.cgi?id=205706

If you need this working in 3.3.1, instanciate the MoveDescriptor
yourself (This is only a workaround as the spec doesn't support this).

The second suggestion (using JavaMoveProcessor) is using internal
classes (see the 'internal' in the package name) and is not recommended.
There's no promise that this code will work in future versions.

Martin


Eddie Man wrote:
> You can perform the refactoring easy by the followings code:
>
> ICompilationUnit javaFile;
> ...
> List elementList = new ArrayList();
> elementList.add(javaFile);
> IResource[] resources = ReorgUtils.getResources(elementList);
> IJavaElement[] elements = ReorgUtiles.getJavaElements(elementList);
> IMovePolicy policy = ReorgPolicyFactory.createMovePolicy(resources,
> elements);
> JavaMoveProcessor processor = new JavaMoveProcessor(policy);
> MoveRefactoring refactoring = new MoveRefactoring(processor);
> IReorgQueries yourQueries;
> ...
> processor.setReorgQueries(yourQueries);
> // yours option here
> processor.setDestination();
> processor.setUpdateReferences();
> processor.setUpdateQualifiedNames();
> RefactoringStatus status = refactoring.checkAllConditions(monitor);
> if (!status.hasFatalError()) {
> Change change = refactoring.createChange(monitor);
> change.initializeValidationData(monitor);
> change.perform(monitor);
> }
>
>
>
> Vera Wahler wrote:
>
>> Hi all,
>>
>> I'd like to do a programmatic move refactoring of a Java file.
>> Since eclipse 3.3 refactorings should be done via descriptors.
>>
>> What I need is a instance of MoveDescriptor and tried the following
>> snippet:
>>
>> RefactoringContribution refactoringContribution =
>> RefactoringCore.getRefactoringContribution(IJavaRefactorings .MOVE);
>> MoveDescriptor refactoringDescriptor = (MoveDescriptor)
>> refactoringContribution.createDescriptor();
>>
>> In this case the descriptor is null.
>> So I tried to call the following createDescriptor-method:
>>
>> createDescriptor(final String id, final String project, final String
>> description, final String comment, final Map arguments, final int flags)
>>
>> But in this case I get a instance of JDTRefactoringDescriptor.
>> I don't want to implement the whole move refactoring on my own and as
>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=61817
>> is fixed it should be possible.
>>
>> Any hints? Thanks for help.
>>
>> Vera
Previous Topic:EclipseCon 2008 submissions system is open
Next Topic:Problem: Class after creation not found in model
Goto Forum:
  


Current Time: Fri May 09 23:32:31 EDT 2025

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

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

Back to the top