Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Programatically calling eclipse Refactoring API - to rename types used and method invocations(Programatically call ltk Rename(Rename TYPE) refactoring API)
Programatically calling eclipse Refactoring API - to rename types used and method invocations [message #1705142] Wed, 12 August 2015 11:50
Srila Sankar is currently offline Srila SankarFriend
Messages: 1
Registered: August 2015
Junior Member
My requirement is to identify deprecated class usage (either as field declaration/used as method parameter/within a method as statement) and have it renamed programatically.

Similarly to also identify deprecated method usage(all method invocations of a deprecated class) and rename the method with new method name+ new argument list.

I am trying to use the RefactoringContribution and RenameJavaElementDescriptor APIs and setting IJavaRefactorings.RENAME_TYPE.

This fails in checkInitialConditions of refactoring. Given below the code piece used.

Pl advice if Rename Type is the correct one for my requirement.

code snippet
RefactoringContribution contribution =
RenameJavaElementDescriptor descriptor =
(RenameJavaElementDescriptor) contribution.createDescriptor();
descriptor.setJavaElement(field);// field declaration containing deprecated class definition
descriptor.setProject(cu.getResource().getProject().getName( ));
descriptor.setNewName(""); // new type name for a deprecated Class

RefactoringStatus status = new RefactoringStatus();
try {
Refactoring refactoring = descriptor.createRefactoring(status);

System.out.println("Refactoring instance created..." + refactoring.getName());

IProgressMonitor monitor = new NullProgressMonitor();
//for testing
//IProgressMonitor monitor = null;

System.out.println("Refactoring conditions created... start change...");

Change change = refactoring.createChange(monitor);

System.out.println("Refactoring ... change completed...");

} catch (CoreException e) {
// TODO Auto-generated catch block
logMsg.append("CoreException: " + e.getMessage());
} catch (Exception e) {
// TODO Auto-generated catch block
logMsg.append("Exception: " + e.getCause());

Thanks in advance
Previous Topic:Syntax error on token "(" expected
Next Topic:modeline or local file variable -*- line support
Goto Forum:

Current Time: Tue Oct 16 06:43:05 GMT 2018

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

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

Back to the top