Bug 13672 - [painting] Horizontal line between methods/members when editing class
Summary: [painting] Horizontal line between methods/members when editing class
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 2.0   Edit
Hardware: All All
: P3 enhancement with 18 votes (vote)
Target Milestone: ---   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: bugday, helpwanted
: 80100 92965 199630 214282 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-04-12 12:52 EDT by Jeff Roberts CLA
Modified: 2021-08-06 02:48 EDT (History)
27 users (show)

See Also:


Attachments
Fix (22.58 KB, patch)
2010-11-10 13:51 EST, Rajesh CLA
no flags Details | Diff
Patch (39.58 KB, patch)
2010-11-14 23:59 EST, Rajesh CLA
daniel_megert: review-
Details | Diff
Icons (2.31 KB, application/octet-stream)
2010-11-15 00:01 EST, Rajesh CLA
no flags Details
Patch (51.77 KB, patch)
2010-11-21 15:36 EST, Rajesh CLA
no flags Details | Diff
Patch (55.67 KB, patch)
2010-11-23 18:27 EST, Rajesh CLA
no flags Details | Diff
Patch (58.51 KB, patch)
2010-11-24 02:01 EST, Rajesh CLA
no flags Details | Diff
patch (59.00 KB, patch)
2010-11-24 04:18 EST, Rajesh CLA
daniel_megert: review-
Details | Diff
horizontal line doesn't go past whole line highlighting (3.58 KB, image/png)
2017-06-02 15:03 EDT, Ian Pun CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jeff Roberts CLA 2002-04-12 12:52:25 EDT
I'm a prior user of the IntelliJ Idea Java IDE and one feature I particularly 
liked was the ability to turn on/off horizontal lines between methods and 
member variables when editing a class.  The setting was an application-wide 
property and it made it very easy to see the method boundaries when editing 
code.  I'd like to request this as a new feature in Eclipse and make it 
something that is configurable through Preferences.
Comment 1 Adam Kiezun CLA 2002-04-12 13:29:16 EDT
+1 here
Comment 2 Erich Gamma CLA 2002-04-13 09:02:59 EDT
The painting architecture to support this is in-place in the Java Editor. We 
have considered this feature and came to the conclusion that 1) it is noise and 
2) it costs cycles (and painting is on the critical performance path). However, 
we have never developed ourselves with such separators. This feedback sounds 
that such add real value. We should investigate how much effort it is to add 
this feature.
Comment 3 Erich Gamma CLA 2002-05-09 17:37:58 EDT
unfortunately not for 2.0
Comment 4 Geoff Longman CLA 2002-12-18 20:44:13 EST
+1 for this feature!
Comment 5 Swapnonil Mukherjee CLA 2004-05-30 14:55:25 EDT
+1 from my side.

It's been 2 years this since this feature request was forwarded! Still no action.
Comment 6 Eric Rizzo CLA 2004-08-10 10:59:53 EDT
Any chance of this getting some attention for 3.1?
Comment 7 Dani Megert CLA 2004-12-06 04:24:02 EST
*** Bug 80100 has been marked as a duplicate of this bug. ***
Comment 8 Dani Megert CLA 2005-04-27 18:09:36 EDT
*** Bug 92965 has been marked as a duplicate of this bug. ***
Comment 9 Eric Rizzo CLA 2006-04-24 13:11:31 EDT
4 years, 2 duplicates, 6 CCs, and 4 votes later and this still has no attention?
C'mon - EG says the architectureis already in place - how much effort can it be to implement from there?
Comment 10 Dani Megert CLA 2007-09-06 03:17:21 EDT
Get rid of deprecated state.
Comment 11 Dani Megert CLA 2007-09-06 03:18:49 EDT
*** Bug 199630 has been marked as a duplicate of this bug. ***
Comment 12 Dani Megert CLA 2008-01-07 12:43:34 EST
*** Bug 214282 has been marked as a duplicate of this bug. ***
Comment 13 Dani Megert CLA 2009-03-12 06:18:28 EDT
Not for 3.5.
Comment 14 Rajesh CLA 2010-11-10 13:51:16 EST
Created attachment 182840 [details]
Fix

Here is what the feature does -

- Draws boundary lines to demarcate methods.
- This can be turned ON/OFF using 'Method Boundary Lines' in the Java > Editor preference page.
- The color of the line can be changed from the same preference page.
- By default it draws boundaries for collapsed methods as well - this can be turned off by setting 'drawBoundaryForCollapsedMethods' to 'false' in JavaEditor.java.

I haven't yet looked for the performance tests - will do so next. Following is a sample set of scenarios for testing - 
- Rapidly move the horizontal or vertical scroll bars and watch for refresh issues.
- Do the above with as many small methods in the visible area as possible.
- Switch editor tabs, applications and/or move another window over the editor area.
- Expand collapse methods, javadocs and other elements.
- Type/Delete/Paste within a method.
- etc.
Comment 15 Eric Rizzo CLA 2010-11-10 16:04:16 EST
Thanks, Rajesh, for spending some time on this!
I have one UI suggestion that I think is critical for usability: provide a toolbar button to toggle the preference, similar to the "Show source of selected element only" preference. I'd like to say I can add that part as a contribution, but I don't see myself realistically having the time between now and 3.7M4 (or M5).
Comment 16 Dani Megert CLA 2010-11-11 03:16:41 EST
(In reply to comment #15)
> Thanks, Rajesh, for spending some time on this!
> I have one UI suggestion that I think is critical for usability: provide a
> toolbar button to toggle the preference, similar to the "Show source of
> selected element only" preference. I'd like to say I can add that part as a
> contribution, but I don't see myself realistically having the time between now
> and 3.7M4 (or M5).

Yes, we should do that, but it has to be hidden by default just like the other button is. Another/additional possibility would be to offer a command that allows to toggle it.
Comment 17 Deepak Azad CLA 2010-11-12 09:53:06 EST
(In reply to comment #0)
> ability to turn on/off horizontal lines between methods and 
> member variables when editing a class. 
The request is for methods *and member variables*. 

The patch adds horizontal lines only before *and* after a method. I think it will be more consistent to add lines before *or* after a java element - method, inner type, member variable. 

It might be overkill but the separators for different elements could be slightly different - color, dotted/dashed/solid/thicker line ?
Comment 18 Rajesh CLA 2010-11-14 23:16:53 EST
(In reply to comment #17)
> (In reply to comment #0)
> > ability to turn on/off horizontal lines between methods and 
> > member variables when editing a class. 
> The request is for methods *and member variables*. 
> 
It says 'between methods and member variables' and not necessarily between member variables. Anyway, besides interpreting that statement, I am not convinced about the utility of separators between member variables if that's what you are implying. 

> The patch adds horizontal lines only before *and* after a method. I think it
> will be more consistent to add lines before *or* after a java element - method,
> inner type, member variable.

Adding 'before *or* after' instead of 'before *and* after' - that would work only if, 1. we added separators between all types of elements, 2. For methods, we could search if the previous and next elements are methods and accordingly draw the lines. The first approach could lead to severe clutter and probably an overkill. The second would make the processing slower, but we could try and see if the performance is acceptable.
Comment 19 Rajesh CLA 2010-11-14 23:59:03 EST
Created attachment 183100 [details]
Patch

Added the following -

1. Toolbar button to toggle the feature ON/OFF
2. Icons for toolbar and help docs (please copy the attached icons.zip into your workspace folder and unzip)
3. Updated the various Help Docs
Comment 20 Rajesh CLA 2010-11-15 00:01:17 EST
Created attachment 183101 [details]
Icons

Place the zip in your workspace folder and extract there.
Comment 21 Dani Megert CLA 2010-11-15 11:35:45 EST
LAF:
- opening e.g. ArrayList I see two lines between each method
- line draws too far on the right (should be aligned with line highlighter)
- should also draw line between types (thicker or two lines to see the diff)
- I would rename the preference (e.g. "[Draw] horizontal line between types and 
  method)
- once we've decided on what it does and how we name it in the UI we have to
  change all the constants and Javadoc
- The tool bar button must not be visible by default

CODE:
- the code should be triggered by changes in the Java model and not compute
  the state on each redraw
- getElementAtOffset(int) must not be used as it forces a reconcile in the
  UI thread which is not good
- the new class should be placed outside the Java editor
==> I think it would be much easier to follow a similar approach like the folding structure provider: simply add an annotation for each line and let the
annotation painter infrastructure do all the work. You would register a new AnnotationPainter.IDrawingStrategy which would draw the horizontal line for your new annotation type.
Comment 22 Deepak Azad CLA 2010-11-15 12:26:58 EST
(In reply to comment #21)
> LAF:
> - opening e.g. ArrayList I see two lines between each method
> - should also draw line between types (thicker or two lines to see the diff)
What happens if you have the following snippets? What all lines and of what type do we draw?

1)
class A {
    private void foo() {
    }

    int a =100;
    int b =200;

    private void bar() {
    }
}

2) 
class A{
    class InnerClass {
    }

    int a =100;
    int b =100;

    private void foo() {
    }

    private void bar() {
    }
}
Comment 23 Dani Megert CLA 2010-11-16 03:31:40 EST
> What happens if you have the following snippets? What all lines and of what
> type do we draw?

We will have to see how it looks but something like this:
> 
> 1)
> class A {
-----------------------------
>     private void foo() {
>     }
> 
>     int a =100;
>     int b =200;
-----------------------------
>     private void bar() {
>     }
> }
> 
> 2) 
> class A{
-----------------------------
-----------------------------
>     class InnerClass {
>     }
-----------------------------
-----------------------------
>     int a =100;
>     int b =100;
-----------------------------
>     private void foo() {
>     }
-----------------------------
>     private void bar() {
>     }
-----------------------------
> }

I would leave the lines around the top-level class away unless there are more than one.
Comment 24 Dani Megert CLA 2010-11-16 03:33:16 EST
-----------------------------
     private void foo() {
     }
-----------------------------

-----------------------------
     private void bar() {
     }
-----------------------------

Probably also needs to be change (only 1 line between methods):

-----------------------------
     private void foo() {
     }

-----------------------------

     private void bar() {
     }
-----------------------------
Otherwise I sometimes get 1 and sometimes 2 lines.
Comment 25 Dani Megert CLA 2010-11-16 03:55:57 EST
The annotation based approach I mentioned in comment 21 has another benefit: we could provide different drawing strategies in the future, e.g. box around the method instead of horizontal lines.
Comment 26 Rajesh CLA 2010-11-21 15:36:05 EST
Created attachment 183542 [details]
Patch

The new patch has following - 

- Rewrote the feature using the annotations framework.
- Separator drawn for Types and Methods.
- Separator not drawn for Primary type (see ITypeRoot#getPrimaryType()).
- Type separator is a thicker line.
- Separators drawn at the top of types and methods.
- Various scenarios such as paste/delete of entire Types/Methods, multiple top-level types and inner types are all handled.
 
Issues-
- The annotation painter seems to be behaving differently for collapsed javadoc versus collapsed method by ignoring annotations at the first line of javadoc, but works fine for collapsed methods.
- When there are field declarations between 2 types/methods, then a separator would make sense at the bottom of the type/method above. Still looking into this.
Comment 27 Deepak Azad CLA 2010-11-21 21:54:19 EST
(In reply to comment #26)
> - When there are field declarations between 2 types/methods, then a separator
> would make sense at the bottom of the type/method above. Still looking into
> this.

We could show a separator before a field declaration 'block' (instead of a separator for every field declaration)
e.g.
 
class A{
*****************************
    class InnerClass {
    }
............................
    int a= 100;
    int b= 100;
-----------------------------
    private void foo() {
    }
............................
    int c= 100;
-----------------------------
    private void bar() {
    }
}
Comment 28 Rajesh CLA 2010-11-22 00:07:58 EST
(In reply to comment #27)
> (In reply to comment #26)
> > - When there are field declarations between 2 types/methods, then a separator
> > would make sense at the bottom of the type/method above. Still looking into
> > this.
> 
> We could show a separator before a field declaration 'block' (instead of a
> separator for every field declaration)

Yes, what you have shown is kind of the idea, but the challenges are - 
1. Firstly, the model doesn't have a notion of a 'field block' so one needs to parse line by line and reliably process a block. All additions/deletions/edits to the block will have to processed for each field.
2. Another way could be to associate the annotation with the last line of the type/method that has a field declaration following it. Here, if the field declaration is deleted or a new one inserted, the model currently won't flag type/method above as 'element changed'.
Need to keep it simple, so will dig deeper and get back.
Comment 29 Rajesh CLA 2010-11-23 18:27:58 EST
Created attachment 183719 [details]
Patch

Added the following -

1. If between 2 Methods/Types, there are other types such as field declarations, there would be a separator to show the end of the Method/Type. This is shown in e.g. below.
2. Modified label on Preference page - need to finalize name, I was thinking of a name like JavaSourceSeparatorLine.
3. Paste/Delete/Typing tested to work.

class A{
*****************************
    class InnerClass {
    }
-----------------------------
    int a= 100;
    int b= 100;
-----------------------------
    private void foo() {
    }
-----------------------------
    int c= 100;
-----------------------------
    private void bar() {
    }
}
Comment 30 Rajesh CLA 2010-11-24 02:01:00 EST
Created attachment 183730 [details]
Patch

Optimized the code and fixed few issues.
Comment 31 Rajesh CLA 2010-11-24 04:18:00 EST
Created attachment 183737 [details]
patch

Fixed a small issue with the toggle on/off.
Comment 32 Deepak Azad CLA 2010-11-24 06:58:31 EST
I tried this feature with real code, and it does not look too bad.

The one improvement I can think of is in handling of anonymous classes
e.g.
	private IInformationControlCreator getInformationControlCreator() {
		return new IInformationControlCreator() {
			public IInformationControl createInformationControl(Shell parent) {
				return new DefaultInformationControl(parent, JavaPlugin.getAdditionalInfoAffordanceString());
			}
		};
	}
Comment 33 Dani Megert CLA 2010-11-24 09:50:39 EST
from my last review (comment 21):
>- line draws too far on the right (should be aligned with line highlighter)
Not fixed:
1. paste the following into Package Explorer:
public class A {

	void foo() {
		class B {
		}
	}
	
	class C {
		void bar() {
		}
	}
}
2. enable horizontal lines
==> draws further than current line painting
NOTE: you might want to look at the WhitespaceCharacterPainter on how the clipping is done there (especially the changes Markus made recently).

>- The tool bar button must not be visible by default
Not fixed.

Feature work/changes:
- The icon needs green dots
- The icon should be to the right of 'Toggle Mark Occurrences'
- The class should also get a thick line at the end, e.g.
    void foo() {
        class A {
        }
        toString();
    } 
- In some situations, also methods probably need a terminating HL, e.g. when
  having anonymous inner classes (not 100% sure yet though).


Bugs:
- There's small cheese on the right when hitting 'Enter':
  ==> this is probably caused because you paint to far to the right (see above)
- Horizontal lines (HLs) are gone after File > Revert.
- Disabling the HLs does not remove it:
  1. open a CU
  2. enable HLs
  3. change a method name
  4. disable HLs
  ==> HLs still there
- Changing the color when HL painting isn't enabled gives an NPE.
- Something with the update code looks wrong i.e. I don't get the HLs but
  I see the new methods in the outline and the folding icons. This happens
  when methods with the same name are there, e.g. select a method with its
  body and then Ctrl+Alt+Up.
- If an inner class is folded then the folding marker on the right is sometimes
  drawn in bold. This is probably because you don't reset the line style in
  your painter.
- Your painter/layer should be below the annotation layer used do draw the
  linked mode stuff: try rename on a method ==> you don't see the upper line
  of the box.
- There shouldn't be a HL at the top when in segmented mode (method only view).
- Platform Doc needs no changes (the action is only in JDT).


When all is done (committed in HEAD) we also need to investigate whether it looks better if the lines start closer to the parents indentation than right at the left side.
Comment 34 Dani Megert CLA 2010-11-24 11:50:24 EST
- IJavaEditorActionDefinitionIds
  - don't add an empty line before the @since
  - don't touch code outside your changes (gives me more to review)

-plugin.xml
  - methodBoundaryLinesColor definition is missing

- JavaEditor
  - the provider should not be created when not needed
  - the provider should not be created inside createPartControl

- MethodBoundaryLinesProvider
  - the copyright is missing
  - use install/uninstall instead of (de-)activate
  NOTE: more detailed review once issues from comment 33 are fixed
Comment 35 Mark McLaren CLA 2011-03-05 07:54:31 EST
This feature is becoming the Duke Nukem Forever of the Eclipse platform!
Comment 36 Mark Mckenzie CLA 2013-06-08 03:48:31 EDT
Probably gonna regret asking this since this thread been dead for over 2 years but whatever happened to this work? I like some of the others in the post are an ex Intelli-J user attempting to convert to Eclipse and also struggle without the method seperators. Is this available now as standard in Eclipse but hidden somewhere?
Comment 37 Nathan Reynolds CLA 2013-06-08 09:49:28 EDT
As far as I can tell, it is not available in Eclipse Juno SR 2 release (20130225-0426).  :(  I, too, am still hoping to see this feature implemented.
Comment 38 John Malc CLA 2013-06-08 12:16:17 EDT
who doesn't :)))
Comment 39 Jeff Roberts CLA 2013-06-08 15:57:26 EDT
I authored this crazy request 11 years ago. I don't even use Eclipse anymore. I was originally told that it was too expensive since it was part of the paint routine.

Maybe someone in the next 11 years can take the time to do this. It seems it would be trivial.

I get notified when someone comments and I'm surprised it's still living.
Comment 40 Nicolas Bihan CLA 2014-01-29 13:26:17 EST
Well,

I have developers adding comments lines in the code to achieve that.
It drives me crazy...
Is there any ETA on that because well, it doesn't sounds to be that difficult to achieve nowadays :)
When I ask them, to remove the lines it's OK, but buy me an IntelliJ license then...
I see the issue is not assigned so I have little hope.
Oh well...
Comment 41 Dani Megert CLA 2014-01-30 04:41:31 EST
Note that this bug already contains an initial patch with review comments. I'd be happy to review the next version of it, if someone steps up and provides it.
Comment 42 Eric Rizzo CLA 2016-01-22 14:25:38 EST
Ceremonial every-second-year ping on this old feature request. It has a reviewed patch, can anyone try to revive that patch and address the review comments?
Comment 43 Eclipse Genie CLA 2017-06-02 14:59:21 EDT
New Gerrit change created: https://git.eclipse.org/r/98567
Comment 44 Ian Pun CLA 2017-06-02 15:02:52 EDT
Hi Dani,

I did some update and brought along Rajesh's most recent patches so that they are now part of Gerrit. As of the latest integration builds of Eclipse, I don't see the horizontal line drawing further than current line painting in Comment 33. Could you confirm this is still happening? I've attached how it looks like on my current build.
Comment 45 Ian Pun CLA 2017-06-02 15:03:37 EDT
Created attachment 268731 [details]
horizontal line doesn't go past whole line highlighting
Comment 46 Dani Megert CLA 2017-06-05 11:55:09 EDT
(In reply to Ian Pun from comment #45)
> Created attachment 268731 [details]
> horizontal line doesn't go past whole line highlighting

I don't see any horizontal line in that screenshot.
Comment 47 Dani Megert CLA 2017-06-05 11:58:03 EDT
(In reply to Ian Pun from comment #44)
> Hi Dani,
> 
> I did some update and brought along Rajesh's most recent patches...

See my comment in Gerrit.
Comment 48 Reto Hoehener CLA 2021-08-06 02:48:21 EDT
Like Nicolas Bihan mentioned, I'm one of those people who is adding demarcation comment lines before methods, but I would prefer not having to do this. Side note: Using the javadoc style instead of // keeps the line with the method when rearranging them via the outline view:

/** ------------------------------------ */