10

in .net you have Regions that you can collapse and remove lots of code down to one line. is there something like this in Android / Java / Eclipse.

#Region "Initialize"
private void DisplayHome(){
        Intent i = new Intent(this, SMSInternetActivity.class);
        finish();
        startActivity(i);
    }
private void DisplaySettings(){
    Intent i = new Intent(this, DisplaySettings.class);
    finish();
    startActivity(i);
}

This just being an example.. #End Region

6 Answers6

13

Using Android Studio:

//region "Initialize"

private void DisplayHome(){
    Intent i = new Intent(this, SMSInternetActivity.class);
    finish();
    startActivity(i);
}

private void DisplaySettings(){
    Intent i = new Intent(this, DisplaySettings.class);
    finish();
    startActivity(i);
}

//endregion
Sir Duende
  • 130
  • 1
  • 5
7

There's a plug-in for that! It is called Coffee-Bytes. It is not in active development, but there are some programmers out there that are keeping the functionality going by updating it for new Eclipse releases.

There's two places where you can get the most latest install for Eclipse 3.7 (Indigo):

  1. http://code.google.com/p/academic-cloud/downloads/detail?name=eclipse-folding-plugin.tar.gz&can=2&q=

  2. http://kosiara87.blogspot.com/2011/12/how-to-install-coffee-bytes-plugin-in.html

Basically, you download the archive, then unpack it. Then you copy the feature from the features folder into your Eclipse installation in the Eclipse features folder. Do the same thing with the JAR found in the plugins folder, it goes into your Eclipse plugins folder. Then restart Eclipse.

There's a good SO answer that shows how to set it up:

How to use Coffee-Bytes code folding

Note that you may have to restart Eclipse for this new style of code folding to start working. Enjoy!

Community
  • 1
  • 1
louielouie
  • 14,881
  • 3
  • 26
  • 31
2

You can use Intellij's feature for code folding using //region and //endregion. Works great in Android Studio. However for Eclipse, you'll need a plugin to do that.

Source: Taken from Answer of Alexander Bezrodniy

Community
  • 1
  • 1
0xC0DED00D
  • 19,522
  • 20
  • 117
  • 184
1

You need to perform the "surround with" operation (default key combination is CTRL+ALT+T), which allows you to use one of 2 ways to specify code as a region:

enter image description here

  • editor-fold:

    //<editor-fold desc="Description">
    code
    //</editor-fold>
    
  • region & endregion :

    //region Description
    code
    //endregion
    

As I remember, you must choose one of them to be used for the whole project. Maybe I'm wrong and it's only for a single file (and maybe there isn't a restriction at all).

android developer
  • 114,585
  • 152
  • 739
  • 1,270
1

yes, and the fastest way to do it in Android Studio

  1. highlight the code you want to surround it
  2. press ctrl + alt + t
  3. press c ==> then enter the description
  4. enjoy
Basheer AL-MOMANI
  • 14,473
  • 9
  • 96
  • 92
1

I believe this is a feature of the IDE i.e. Visual Studio, not .NET in general. You, in theory, can write a plugin for Eclipse that can collapse region in Java code. Eclipse already have the ability to collapse imports and functions.

AkaZn
  • 59
  • 1
  • 3