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 =
RefactoringCore.getRefactoringContribution(IJavaRefactorings.RENAME_RENAME_TYPE);
RenameJavaElementDescriptor descriptor =
(RenameJavaElementDescriptor) contribution.createDescriptor();
descriptor.setJavaElement(field);// field declaration containing deprecated class definition
descriptor.setProject(cu.getResource().getProject().getName( ));
descriptor.setNewName("java.io.BufferedReader"); // 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;
refactoring.checkInitialConditions(monitor);
refactoring.checkFinalConditions(monitor);

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

Change change = refactoring.createChange(monitor);
change.perform(monitor);

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

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

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


Current Time: Thu Sep 19 23:23:20 GMT 2024

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

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

Back to the top