Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can do code alignment in Eclipse base Force.com IDE

How can do code alignment with Eclipse base Force.com IDE. Alignment shortcut key 'CTRL+SHIFT+F' is not working for Apex code.

like image 231
Channa Avatar asked Jan 10 '12 09:01

Channa


People also ask

Which option is used for alignment of lines in the editor window in Eclipse?

If you mean formatting, then Ctrl + Shift + F . Save this answer.

How do I fix indentation in Eclipse?

You can use Ctrl + A to select the entire file, then use this shortcut to quickly fix all the indentation. You can also change how Eclipse handles indentation by going to Window > Preferences, then in the left panel, navigate to Java > Code Style > Formatter > Edit... > Indentation.


2 Answers

None of the suggestions so far work for me. Note that the Force IDE opens the Apex class in an Apex Editor. This editor does not appear in the list of contexts that you can associate with a key event. For example, this list contains such contexts as "editing in structured text", "editing in Java Source", etc.

The Apex Editor does not contribute a "Source" menu option to the right click menu. So there is no way to get to the formatting features.

I tried to open the apex class in the Java. Now the "Source" menu option appears the format option doesn't do anything. (Hence no key event will be able to do anything.)

The only thing I can get to work is this ...

Select file.... Open With... Other ... locate Java Editor. Once file is open ... select all text .. right click and select Source ... Correct Indentation .

This does not reformat but it does fix the indentation problem.

Someday I hope SFDC will make the code for the Force IDE open source. Then we, as a community, could build more developer-friendly tools.

like image 106
Bryan Avatar answered Oct 05 '22 11:10

Bryan


Apex classes and triggers use a different editor than Java. The auto formatter (or code alignment) does not work with Apex Code (or the Apex Code Editor). I couldn't get CTRL-SHIFT+F to work in the most recent version of Eclipse with the Force.com IDE, either. I believe this is because the auto formatter is designed to work with Java only.

However, if you switch to the Java perspective and open your Apex class with the Java Editor, CTRL+I does correct indentation properly.

like image 28
Matt K Avatar answered Oct 05 '22 11:10

Matt K