28

I know Xcode has a

#pragma mark 

feature where it allows you to insert arbitrary labels in outline views / method lists to document how code is segmented.

I haven't been able to find a similar feature for Eclipse. I can't help but feel that it's right under my nose, but searches on both SO and Google haven't been enlightening... anyone know how I might do this?

Or is there some hackish workaround? That would be awesome too.

QED
  • 9,803
  • 7
  • 50
  • 87
Steven Schlansker
  • 37,580
  • 14
  • 81
  • 100

6 Answers6

29

Eclipse outline view supports categories (with @category in javadoc) for showing additional information on methods. See the following screenshots for an example of such usage.

Category definition in the editor

Category and filtering in the Outline view

Unfortunately grouping by categories has not been implemented yet. There is an open feature request for this, but it is nearly four years old and clearly stated that it needs community effort. Personally I do not know such plugin.

Csaba_H
  • 8,215
  • 1
  • 41
  • 42
  • 1
    This is why we keep saying do not outsource information on this website. I find a possible useful answer but here it is, the link is dead. – Savas Vedova Mar 24 '14 at 06:29
  • 1
    The dead link was removed and replaced with some screenshots. Thanks for the update. – Csaba_H Mar 24 '14 at 08:08
9

The horror:

@SuppressWarnings("unused")
private int _______________________________________;

Or if you prefer labels:

@SuppressWarnings("unused")
private int _______________Lifecycle_______________;

enter image description here

Bonus points for varying the number of underscores so you can have many separator lines.


My Android Studio Version

Use code regions:

//region

    ... your code here ... 

//endregion

Bonus points for making the folded presentation look like a comment:

//
//region // Lifecycle

   ... your code here ...

//endregion
//

enter image description here

QED
  • 9,803
  • 7
  • 50
  • 87
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. – rolfl Nov 15 '13 at 18:10
  • Neither does that of @ntle – QED Nov 15 '13 at 18:14
  • Maybe, but his answer did not come up flagged in my stream in the 'needs review' as a 'low quality' answer. – rolfl Nov 15 '13 at 18:16
  • There you go, I just flagged it – QED Nov 15 '13 at 18:18
  • 1
    Actually, I think this is the best answer - though it only gives a work-around. I wonder if it will work similarly when I switch to Android Studio (some day). – Tom Dec 05 '13 at 01:06
  • 2
    This is the closest anyone came to providing what was asked for... as horrifying as it may be. – WoodenKitty Mar 26 '14 at 03:00
  • Perhaps you should use methods instead of fields to reduce memory usage, like `@SuppressWarnings("unused") private void _______________Lifecycle_______________(){}`. – Pang Apr 25 '14 at 07:12
4

You can use "Add Bookmark".

One way to do that is to right-click on the left side (where line numbers are shown), and select "Add Bookmark...".

You can view them in "Bookmarks" view.

jDenis
  • 41
  • 2
4

In order to mimic the #pragma mark functionality I usually create a dummy method that works as a separator. For example:

private static void someDummyMethod(){}
Chris Cashwell
  • 22,308
  • 13
  • 63
  • 94
ntle
  • 49
  • 1
0

Following up on @ntle, (for PHP anyway), you can also use define() to create a pseudo pragma mark, or function(). See screenshot:

enter image description here

For more discussion & examples on this, see my blog post: https://peacocksoftware.com/blog/create-pragma-separator-eclipse-xcode

Richard
  • 1,912
  • 20
  • 28
0

#pragma mark is supported natively in Eclipse CDT as of about 2022-06.

#pragma mark Public API       // Inserts a bold title
#pragma mark - Public API     // Inserts a line above a bold title
#pragma mark - Public API -   // Inserts a line above and below a bold title
#pragma mark -                // Inserts a line