3

With reference to a Stack Overflow question from 2009...

In the last six years, have any automated Apex refactoring tools been developed? I'd like to do simple refactorings like "extract method", and I'd like a less manual way of doing it than error-prone copy-paste.

  • The answer may be yes and I will be interested. One factor that has held this back is that Salesforce had not/have not published an official grammar for Apex and have not open sourced any parser. So tool writers are left having to build their own parser based on best guesses. May also be hard to do given the fussy nature of the server-side logic. Now if they hadn't gone the proprietary route... – Keith C Jul 2 '15 at 17:14
  • @KeithC fussy nature of server-side logic? even a tool that works in a limited grammar and otherwise throws an exception would be better than nothing, right? – Charles Koppelman Jul 2 '15 at 18:30
  • Just thinking that the sort of major refactoring you might do in Java would work fine in an IDE but then when the new versions are deployed the server-side dependency checking might report errors. (The policy for Eclipse refactoring in Java is that nothing should break i.e. you can be confident and go ahead knowing your code will still compile afterwards.) But I'm 110% in favour of better tooling and any steps forward. – Keith C Jul 2 '15 at 18:38
  • Agreed that any refactoring tool should be only safe. I guess I see what you mean in the context of multiple developers working on a project. I think something like "Change Method Name" is not practical in SF except for private methods, but "Extract Method", or "Extract Variable" or "Eliminate Variable" should be generally safe. In the cases where it's not safe, a refactoring tool should fail. – Charles Koppelman Jul 2 '15 at 20:10
  • Fair point - there are potentially many refactorings that are entirely internal to a class. – Keith C Jul 2 '15 at 20:18
1

Illuminated Cloud 2 supports rename, method extract: https://www.youtube.com/watch?v=ecU1vfrnOe4

1

Four years further on, refactoring support is beginning to be added to the Salesforce extensions suite for Visual Studio Code.

The recently-released Apex Refactoring feature currently provides symbol renaming:

You can rename any valid Apex symbol defined in your source: methods, locals, fields, properties, constructors, or types (classes, triggers, or enums). To perform a rename, right-click the symbol that you want to rename and select Rename Symbol.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.