Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7603347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:38:03+00:00 2026-05-30T23:38:03+00:00

I need to refactor code in a wide term. I know that from inside

  • 0

I need to refactor code in a wide term. I know that from inside the Eclipse IDE I can refactor my classes. But is there any API that I can use in a java project so that I can refactor projects dynamically through code?


I need some idea on how to achieve the following: a program that calls all the Eclipse refactorings for renaming and moving in a loop to refactoring the entire project in one shot!


I don’t want to introduce new refactoring types by extending the refactoring classes. I just want to call them programmatically.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:38:04+00:00Added an answer on May 30, 2026 at 11:38 pm

    The answer below is great, but I answered with a wider perspective for the people who need a more bulky and tasty crunch of this wonderful cake:

        RefactoringStatus status = new RefactoringStatus();
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        IWorkspaceRoot root = workspace.getRoot();
        IProject[] projects = root.getProjects();
    

    then:

    for (ICompilationUnit unit : mypackage.getCompilationUnits()) {
        IType primary = unit.findPrimaryType();
        IMethod[] methods = primary.getMethods();
        int i = 1;
        for (IMethod method : methods) {
            if (method.isConstructor()) {
                continue;
            }
        makeChangetoMethods(status, method,"changedMethodVersion_" + i);
        ++i;
        }
    }
    

    After that:

    IProgressMonitor monitor = new NullProgressMonitor();
    status = new RefactoringStatus();
    Refactoring refactoring = performMethodsRefactoring(status, methodToRename, newName);
    

    then:

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

    find below the code for setting the descriptor:

    String id = IJavaRefactorings.RENAME_METHOD;
    RefactoringContribution contrib = RefactoringCore.getRefactoringContribution(id);
    RenameJavaElementDescriptor desc = contrib.createDescriptor();
    desc.setUpdateReferences(true);
    desc.setJavaElement(methodToRename);
    desc.setNewName(newName);
    desc.createRefactoring(status);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to refactor existing code by collapsing a method that's copy-and-pasted between various
There's some legacy code that I would like to refactor. There is some data
I need to refactor this code to not use a parameter when using the
I have a solution that is missing a lot of code coverage. I need
I feel the need to refactor my old CF5 based code into CFC's. We
I'm trying to refactor some code here that was done previously by other guys,
I have a number of collections of classes which I need to refactor into
I have a problem with some code I need to refactor. Right now it
How can I refactor the following code to avoid repetition? r = @lots.fetch @lots.keys.sample
I am just embarking on my first large-scale refactor, and need to split an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.