|
Re: Calling Refactorings Programmatically [message #245652 is a reply to message #245512] |
Fri, 13 July 2007 08:36 |
Eclipse User |
|
|
|
Originally posted by: jacek.pospychala.pl.ibm.com
Máirtín,
You're right, accessing RenamCompilationUnitProcessor directly from your
code is not a good idea.
Please take a look at org.eclipse.ltk (Refactoring Language Toolkit)
framework. Also this article should give you some hints on how to use
refactorings:
http://www.eclipse.org/articles/article.php?file=Article-Unl eashing-the-Power-of-Refactoring/index.html
Máirtín wrote:
> I want to use Eclipse refactorings programmatically. As far as I can
> see the only way to do this is to use internal classes.
>
> For example to rename a compilation unit I would need to use
>
> org.eclipse.jdt.internal.corext.refactoring.rename.RenameCom pilationUnitProcessor
>
>
> Is this correct? That I can only use the refactorings that Eclipse
> ships by using internal classes?
>
>
> If so does this break the guidelines for using the Eclipse API as
> outlined on this page?
>
> http://www.eclipse.org/articles/article.php?file=Article-API -Use/index.html
>
>
> If so, does this mean that one cannot safely use Eclipse refactorings
> programmatically?
>
>
>
>
>
> On a related note, with regards developing custom refactorings I see
> even Tobias Widmer in his article "Unleashing the Power of Refactoring"
>
> http://www.eclipse.org/articles/article.php?file=Article-Unl eashing-the-Power-of-Refactoring/index.html
>
>
> uses internal classes (org.eclipse.jdt.internal.corext.dom.NodeFinder)
> in order to develop his custom refactoring.
>
> Once again, is this not bad practice at a minimum and unsafe with
> regards it breaking when running against future releases of Eclipse
> due to dependencies on internal API?
> I want to develop some custom refactorings - is it just the case that
> in order to develop custom refactorings I will more than likely need
> to use some internal classes? And the best I can do is to request any
> internal API I use to be put into the published API in the future and
> fix things down the line, whilst in the meantime dealing with any
> breakage in the code between Eclipse releases due to dependencies on
> internal API?
>
>
>
>
> Any help greatly appreciated,
>
> Thanks,
>
> Máirtín
>
|
|
|
|
Re: Calling Refactorings Programmatically [message #245682 is a reply to message #245662] |
Fri, 13 July 2007 10:32 |
Eclipse User |
|
|
|
Originally posted by: jacek.pospychala.pl.ibm.com
Máirtín,
I wonder, if this is the preferred way, but you may try the following
code to create a refactoring through API:
ICompilationUnit cu = ... // an ICompilationUnit to rename
RefactoringContribution contribution =
RefactoringCore.getRefactoringContribution(IJavaRefactorings .RENAME_COMPILATION_UNIT);
RenameJavaElementDescriptor descriptor =
(RenameJavaElementDescriptor) contribution.createDescriptor();
descriptor.setProject(cu.getResource().getProject().getName( ));
descriptor.setNewName("NewClass"); // new name for a Class
descriptor.setJavaElement(cu);
RefactoringStatus status = new RefactoringStatus();
try {
Refactoring refactoring = descriptor.createRefactoring(status);
IProgressMonitor monitor = new NullProgressMonitor();
refactoring.checkInitialConditions(monitor);
refactoring.checkFinalConditions(monitor);
Change change = refactoring.createChange(monitor);
change.perform(monitor);
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Máirtín wrote:
> Jacek Pospychala wrote:
>
>> Also this article should give you some hints on how to use refactorings:
>>
>> http://www.eclipse.org/articles/article.php?file=Article-Unl eashing-the-Power-of-Refactoring/index.html
>>
>
> Yes, I had a look at that article:
>
>> Máirtín wrote:
>>> On a related note, with regards developing custom refactorings I see
>>> even Tobias Widmer in his article "Unleashing the Power of Refactoring"
>>>
>>>
> http://www.eclipse.org/articles/article.php?file=Article-Unl eashing-the-Power-of-Refactoring/index.html
>
>>>
>>>
>>> uses internal classes
>>> (org.eclipse.jdt.internal.corext.dom.NodeFinder) in order to develop
>>> his custom refactoring.
>>>
>>> Once again, is this not bad practice at a minimum and unsafe with
>>> regards it breaking when running against future releases of Eclipse
>>> due to dependencies on internal API?
>>> I want to develop some custom refactorings - is it just the case
>>> that in order to develop custom refactorings I will more than likely
>>> need to use some internal classes? And the best I can do is to
>>> request any internal API I use to be put into the published API in
>>> the future and fix things down the line, whilst in the meantime
>>> dealing with any breakage in the code between Eclipse releases due
>>> to dependencies on internal API?
>>>
>
> And my point was that even in this article Tobias Widmer uses internal
> classes - so my question was is it the case that it is virtually
> impossible to use refactorings that are provided by Eclipse
> programmatically without using internal classes.
>
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03793 seconds