|
|
Re: Move refactoring via descriptors [message #248479 is a reply to message #248338] |
Mon, 08 October 2007 10:55 |
Martin Aeschlimann Messages: 71 Registered: July 2009 |
Member |
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.05323 seconds