12

I'm using an UML tool that generates Java classes from the UML class diagram. Unfortunately the code inside is not indented.

How to solve this? How can I indent a file using Eclipse?

1
  • @Logan: soyatec's eUML plugin Commented Aug 18, 2011 at 10:50

4 Answers 4

24

How to indent a Java source file in Eclipse:

  1. Open the file in Eclipse's text editor.
  2. Ctrl+A to select all text.
  3. Ctrl+I to indent the text (or right click > Source > Indent).
  4. Ctrl+S to save the file.

Done.

(If you also want to correct the spacing, then use Ctrl+Shift+F or right click > Source > Format. This can be applied to a single file, or a group of files using the Project Explorer pane.)

Sign up to request clarification or add additional context in comments.

1 Comment

In Mac it's command + i oc
6

ctrl + a and then ctrl + i

Comments

2

Use the code format feature with the shortcut Ctrl+Shift+F in eclipse then you will get the code formatted using eclipse standard and not only indenting. Advanced you can write an xml file to specify your formatting preferences.

/Farmor

Comments

2

In fact, you can make the whole process fully automatic by invoking Eclipse plugin from command line:

eclipse -nosplash \
  -application org.eclipse.jdt.core.JavaCodeFormatter \
  -verbose \
  -config ~/eworkspace/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.core.prefs \
  MyClass.java

Just make sure to create workspace where you have your formatting preferences set up according to your requirements.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.