Coder Perfect

Java equivalent to #region in C#

Problem

In Eclipse, I’d want to use regions for code folding; how can I achieve this in Java?

In C#, here’s an example:

#region name
//code
#endregion

Asked by Pentium10

Solution #1

This feature is available in Jet Brains IDEA. You can do this with the hotkey surround (ctrl + alt + T). It’s simply an IDEA feature.

There appear to be regions there that look like

//region Description

Some code

//endregion

Answered by Alexander Bezrodniy

Solution #2

There isn’t a standard equivalent for this. Some IDEs, such as Intellij or Eclipse, can fold based on the code types involved (constructors, imports, and so on), but nothing compares to #region.

Answered by Brian Agnew

Solution #3

Try this with Android Studio:

//region VARIABLES
private String _sMyVar1;
private String _sMyVar2;
//endregion

Make sure there’s no blank line after /region…

You’ll also get:

Answered by Cyril Jacquart

Solution #4

There isn’t a linguistic equivalent… On the basis of IDEs…

For instance, in Netbeans:

This syntax is supported by NetBeans/Creator:

// <editor-fold defaultstate="collapsed" desc="Your Fold Comment">
...
// </editor-fold>

http://forums.java.net/jive/thread.jspa?threadID=1311

Answered by Kevin LaBranche

Solution #5

The CoffeeScript code folding plugin can be used to add a custom code folding capability to eclipse.

This has been tested with the eclipses Luna and Juno. The steps are as follows:

You may also download the archive and discover the steps on this blog.

Answered by DeltaCap019

Post is based on https://stackoverflow.com/questions/2344524/java-equivalent-to-region-in-c-sharp