3

How can I rearrange the code in a .java file in visual studio code? For example inside a Class, I want it to automatically put static variables at the top, then attributes, then methods, etc.

I tried to google "vscode rearrange code" but it always points to Prettier, which does NOT do that.

There might not be a native feature in vs code. However, I know that IntelliJ (Java) definitely has an option to do that. So I wondered if anyone has created an extension which I could use.

Also, just to clarify further, I'm not talking about rearranging imports.

EDIT: I don't mean formatting. I am talking about rearranging the code.

Bestname
  • 173
  • 2
  • 10
  • What you are looking for is called "formatting". – Koenigsberg Jul 30 '21 at 14:43
  • I tried to make it pretty clear :D No, formatting typically just aligns everything and puts everything into a neat visual shape. It has nothing to do with reorganizing the symbolic members of a java class. You could place it under the umbrella term "formatting" but if you think about it, that encompasses a lot more of what I've asked for. Furthermore, most formatting procedures don't exactly do what I described. They just align things but don't rearange things. – Bestname Jul 31 '21 at 23:39
  • Please file a report to describe your feature request in [vscode-java](https://github.com/redhat-developer/vscode-java). – Molly Wang-MSFT Aug 02 '21 at 01:49
  • AFAIK there was a feature request already. They set that use-case would rather fit an extension. – Bestname Aug 02 '21 at 02:53
  • @Bestname. Can you share the feature link? – Molly Wang-MSFT Aug 02 '21 at 03:23
  • On Windows: Shift + Alt + F According to this post: https://stackoverflow.com/questions/29973357/how-do-you-format-code-in-visual-studio-code-vscode – user7656 Sep 03 '21 at 02:35
  • @Bestname - did you find anything? In the 500lb gorilla that is Visual Studio there is an extension called [CodeMaid](https://www.codemaid.net/) that does this sort of thing. I cannot find one for VSCode ... maybe I'll port the CodeMaid over ... in my spare time. – THBBFT Jan 11 '22 at 02:46

0 Answers0