6

Possible Duplicate:
Java equivalent to #region in c#

Is there something in Java that would allow for structuring the source code as it is done in C# with the pre-processor directives

#region

and

#endregion

?

Community
  • 1
  • 1
Ta Sas
  • 9,573
  • 15
  • 51
  • 73

4 Answers4

13

No, there is nothing equivalent.

Code folding is an IDE feature, not a language feature.

Eclipse has code folding for classes and members when Java files are loaded in it. It may be extended (for example) to add code folding on carefully crafted comment lines.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
  • 1
    Pitty, anyway thanks. I am using idea (full version). Any equivalent to eclipse's folding? – Ta Sas Sep 22 '10 at 19:15
  • @user268098 - I never used `idea`, so I can't help with that. Read the help file... – Oded Sep 22 '10 at 19:17
  • I highly recommend Eclipse for Java development. It allows folding of any methods or documentation blocks. AFAIK it doesn't allow arbitrary regions to be defined, however. – Erick Robertson Sep 22 '10 at 19:18
  • 2
    @use268098: Yes, IDEA has code folding. I think it's on by default, but configuration is at IDE Settings -> Editor -> Code Folding. – ColinD Sep 22 '10 at 19:19
  • @Oded: thanks again ... I feel ashamed, I should have considered RTFM myself ;-) – Ta Sas Sep 22 '10 at 19:20
  • @Erick Robertson: IDEA is a seriously awesome IDE, for the record. – ColinD Sep 22 '10 at 19:20
  • @ColinD, @Erick Robertson: Without going too much off the topic, but IDEA really *is* awesome, especially when you use Spring. There is a good reason why I prefer to pay some hundreds of dollar for a Java IDE from my private money. – Ta Sas Sep 22 '10 at 19:23
  • Is **arbitrary** code folding really necessary? I'm not convinced. – Kelly S. French Sep 22 '10 at 19:34
  • @Kelly French - necessary? No. Nice to have? Sometimes. Easy to abuse? Definitely. – Oded Sep 22 '10 at 19:40
  • Nitpick: although the ability to collapse code is indeed an IDE feature, it is nonetheless a language feature that it allows `#region` and `#endregion` and that the compiler enforces the existence of matching pairs (C# language specification, §2.5.6 Region directives). – Timwi Sep 22 '10 at 20:03
  • @Timwi agreed, I've had builds fail from unmatched regions. You would think that the compiler would ignore both terms and save the trouble. – Kelly S. French Sep 22 '10 at 20:08
  • @Kelly French: Let me put it this way: I found it extremely useful for me to fold regions ... and I really miss it in Java ... – Ta Sas Sep 22 '10 at 20:41
  • I'm not knocking IDEA. I've never even heard of it, but I do not do Spring development. I posted my comment here before @user268098 edited his first comment to add that he was using IDEA. – Erick Robertson Sep 23 '10 at 11:30
4

No, there's no built-in solution to that.

However there are some Java IDE's which support folding for certain comment-patterns. And of course all IDE's support folding the code by classes, methods etc.

Gamlor
  • 12,978
  • 7
  • 43
  • 70
3

region is a language feature and NOT an IDE feature. Specifically, it is part of the C# programming language and Visual Studio knows how to interpret it.

Johann
  • 1,977
  • 3
  • 19
  • 18
2

Not as such. Bear in mind that these preprocessor directives are more for VS's benefit than they are a part of the C# or VB language spec. Preprocessor directives in Java would be the IDE's business.

KeithS
  • 70,210
  • 21
  • 112
  • 164