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

3

6

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

Dumb answered 10/1, 2012 at 9:35 Comment(0)
D
4

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.

Daukas answered 10/1, 2012 at 22:1 Comment(0)
C
3

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.

Cabral answered 10/1, 2012 at 16:37 Comment(0)
B
0

Go to Preferences -> General -> Keys and type "format" into the search box, you will see what keys (if any) are bound to the format commands. Then you can bind what you like or use what's available.

Bandore answered 10/1, 2012 at 16:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.