Bug 60929 - [projection] Folding for Java code blocks
Summary: [projection] Folding for Java code blocks
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.0   Edit
Hardware: All All
: P3 enhancement with 16 votes (vote)
Target Milestone: ---   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 67431 74879 76469 78020 96191 101758 148518 195339 195387 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-05-04 12:46 EDT by Eugene Kuleshov CLA
Modified: 2022-06-23 16:03 EDT (History)
28 users (show)

See Also:
noopur_gupta: review-


Attachments
Patch For Bug Fix 60929 (29.08 KB, patch)
2013-09-17 16:38 EDT, Austin Richards CLA
no flags Details | Diff
Screenshot with issues (32.85 KB, image/png)
2013-10-11 09:13 EDT, Noopur Gupta CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Eugene Kuleshov CLA 2004-05-04 12:46:10 EDT
It is great to see that general folding functionality for editors finally has
been implemented and bug http://bugs.eclipse.org/bugs/show_bug.cgi?id=9355 has
been closed. 

However it is not clear if support for folding Java code blocks (basicallsy any
pair of {...} including if, for, do/while, try/catch/finally, unnamed and
synchronized blocks) is going to be supported in future.
Comment 1 Dani Megert CLA 2004-05-05 04:52:39 EDT
Do you mean blocks or any selected text (also covering blocks)?
Comment 2 Eugene Kuleshov CLA 2004-05-05 06:51:28 EDT
Not selected text, but Java code between btackets {...}
Comment 3 Dani Megert CLA 2004-05-05 07:07:37 EDT
Note that you can provide this yourself with an additional plug-in which
contributes a folding structure provider.
Comment 4 Eugene Kuleshov CLA 2004-05-05 09:46:17 EDT
Is there are any examples how to do that?

From other hand it is quite common functionality for Java editor.I'm not sure if
it will be just enough to take any pair of matching {...} or it has to know
about  Java grammar. See how grammar-based outline was working for Together -
http://w8.platonoff.com/together/folding.gif
Comment 5 Dani Megert CLA 2004-05-05 10:01:31 EDT
Doc/example phase comes later.
Comment 6 Hossein Safavi CLA 2004-05-15 19:44:15 EDT
I understand that at this state the documentation may not be ready, but I had a 
question:
I assume that the folding structure that currently works (folding methods and 
some comments) are implemented some place. Could you tell me where they are 
implemented? This way I may be able to understand a bit more without proper 
documentation. What I mean is which extension currently included in the eclipse 
sdk uses the IJavaFoldingStructureProvider extension point?
I was unable to find this on my own which is why I am asking.

Thanks in advance
Comment 7 Tom Hofmann CLA 2004-05-17 03:30:15 EDT
see DefaultJavaFoldingStructureProvider
Comment 8 Dani Megert CLA 2004-06-16 09:05:27 EDT
*** Bug 67431 has been marked as a duplicate of this bug. ***
Comment 9 R.J. Lorimer CLA 2004-08-17 09:55:54 EDT
FYI - for those of you that want this functionality, please see my folding
editor plug-in:

http://www.coffee-bytes.com/servlet/PlatformSupport
Comment 10 Dani Megert CLA 2004-09-24 03:21:02 EDT
*** Bug 74879 has been marked as a duplicate of this bug. ***
Comment 11 Dani Megert CLA 2004-10-18 11:22:34 EDT
*** Bug 76469 has been marked as a duplicate of this bug. ***
Comment 12 Dani Megert CLA 2004-11-08 05:17:23 EST
*** Bug 78020 has been marked as a duplicate of this bug. ***
Comment 13 Dani Megert CLA 2005-05-21 06:20:53 EDT
*** Bug 96191 has been marked as a duplicate of this bug. ***
Comment 14 Dani Megert CLA 2005-06-27 05:03:02 EDT
*** Bug 101758 has been marked as a duplicate of this bug. ***
Comment 15 Jörg von Frantzius CLA 2005-11-10 15:12:57 EST
(In reply to comment #3)
> Note that you can provide this yourself with an additional plug-in which
> contributes a folding structure provider.
> 

This would be a nice feature for dealing e.g. with large if/else blocks. Don't
you find it useful enough or why do you want people to implement it themselves?
Comment 16 Dani Megert CLA 2005-11-10 16:27:30 EST
>Don't
>you find it useful enough or why do you want people to implement it themselves?
I said neither of it, didn't I? I only mentioned how it can be achieved. An
other option for people giving this a higher priority than we currently do is to
participate in the Eclipse open source project and provide us with a good patch
that implements this.
Comment 17 Jörg von Frantzius CLA 2005-11-11 05:06:46 EST
(In reply to comment #16)
> I said neither of it, didn't I? I only mentioned how it can be achieved. An
> other option for people giving this a higher priority than we currently do is to
> participate in the Eclipse open source project and provide us with a good patch
> that implements this.

Sorry I had been staring at that huge if-statement for so long that I started
wondering why the best IDE on the planet still can't fold control structures ;)

Coffee-bytes seems to work with Eclipse 3.2M3, maybe you could take over some
code from there? I'd bet rjlorimer wouldn't mind you doing so if you tell him...
Comment 18 Dani Megert CLA 2005-11-11 05:18:40 EST
>Coffee-bytes seems to work with Eclipse 3.2M3, maybe you could take over some
>code from there? I'd bet rjlorimer wouldn't mind you doing so if you tell him...
Since he's listening to this PR as well he can comment on this himself. As
stated above we'd be happy to get contributions.
Comment 19 Jörg von Frantzius CLA 2005-11-11 06:26:05 EST
Is he (In reply to comment #18)
> >Coffee-bytes seems to work with Eclipse 3.2M3, maybe you could take over some
> >code from there? I'd bet rjlorimer wouldn't mind you doing so if you tell him...
> Since he's listening to this PR as well he can comment on this himself. As
> stated above we'd be happy to get contributions.

I can't find him on the CC and I don't believe Bugzilla CCs everybody who has
ever commented on a PR. I'll allow myself to put him on the CC.

Hello R.J. Lorimer, are you listening?
Comment 20 Dani Megert CLA 2005-11-11 06:30:59 EST
You're right. I parsed the cc-list too quickly ;-)
Comment 21 Eugene Kuleshov CLA 2006-04-04 17:12:22 EDT
Is this issue can be addressed for Eclipse 3.2? 

Unfortunately folding provider from coffee-bytes does not work with Eclipse 3.2M6, so I wonder if there could be a native support in Eclipse.
Comment 22 Dani Megert CLA 2006-04-04 17:32:24 EDT
Sorry not for 3.2: we're beyond feature work.
Comment 23 Dani Megert CLA 2006-06-26 03:26:21 EDT
*** Bug 148518 has been marked as a duplicate of this bug. ***
Comment 24 Don Kleppinger CLA 2007-03-13 19:04:49 EDT
Can I vote for this feature.  It would be extremely valueable for me.
Comment 25 Dani Megert CLA 2007-03-14 04:28:08 EDT
>Can I vote for this feature.
==> https://bugs.eclipse.org/bugs/votes.cgi?action=show_user&bug_id=60929#vote_60929
Comment 26 Dani Megert CLA 2007-07-05 03:02:30 EDT
*** Bug 195387 has been marked as a duplicate of this bug. ***
Comment 27 Mark A. Ziesemer CLA 2008-04-17 20:30:25 EDT
See also: bug 148233
Comment 28 LeO welsch CLA 2009-06-09 04:22:15 EDT
Is there any progress on this issue. Especially since 3.5 is almost there.

Additional question: Can Bug 63808 also applied to this issue, or is this some kind of separte issue?
Comment 29 Dani Megert CLA 2009-06-09 04:36:57 EDT
>Is there any progress on this issue. Especially since 3.5 is almost there.
Definitely not for 3.5 (RC4 just went out and the code base is basically frozen).

>Additional question: Can Bug 63808 also applied to this issue, or is this some
>kind of separte issue?
This bug is only about folding well defined Java code blocks inside braces. Bug 63808 goes further in the sense that it introduces a syntax to mark custom code blocks in the JDT Core layer. However, if the ProjectionViewer is enhanced/fixed so that it can show custom code blocks it will be easy to support this bug here.
Comment 30 Tal Bar-Zvi CLA 2011-01-06 08:13:06 EST
3.6sp1 is out and no sign of this feature yet....
Comment 31 David Balažic CLA 2013-06-18 12:28:05 EDT
After almost a decade, maybe the status could be changed back to NEW. Just so it makes some sense.
Comment 32 Dani Megert CLA 2013-06-19 03:47:45 EDT
(In reply to comment #31)
> After almost a decade, maybe the status could be changed back to NEW. Just
> so it makes some sense.

No, that would make no sense. NEW means, the bug has not yet been triaged by a developer. ASSIGNED means the bug/feature has been accepted.
Comment 33 Austin Richards CLA 2013-06-29 08:58:36 EDT
Hey all, I'm a GSoC student and I am currently working on this bug.  It is coming along well so far.  If you would like updates then check out my repository at https://github.com/R41D3NN/eclipse.jdt.ui and http://www.google-melange.com/gsoc/project/google/gsoc2013/ahrichards/16001#.
Comment 34 Palmer Eldritch CLA 2013-09-11 13:25:56 EDT
Glad this is worked on - maybe a duplicate https://bugs.eclipse.org/bugs/show_bug.cgi?id=195339

Don't forget anonymous blocks :

{
}
Comment 35 Noopur Gupta CLA 2013-09-11 13:34:35 EDT
*** Bug 195339 has been marked as a duplicate of this bug. ***
Comment 36 Austin Richards CLA 2013-09-11 17:20:59 EDT
I've worked on an implementation for this bug that can be found here:
https://github.com/R41D3NN/eclipse.jdt.ui/tree/Bug-60929--Java-Code-Block-Folding

It includes folding functionality for the following:
* Conditional Blocks
* Loop Blocks
* Switch Blocks
* Try/Catch/Finally Blocks
* Synchronized Blocks

Unnamed (Anonymous) Block folding is currently disabled due to a bug, but I hope to fix this soon.
Comment 37 Wayne Beaton CLA 2013-09-11 17:51:16 EDT
(In reply to Austin Richards from comment #36)
> I've worked on an implementation for this bug that can be found here:
> https://github.com/R41D3NN/eclipse.jdt.ui/tree/Bug-60929--Java-Code-Block-
> Folding

To be clear, I believe that Austin would like to contribute this code to the project. Austin has a signed CLA and the contribution has been signed-off-by. What is Austin's next step?
Comment 38 Dani Megert CLA 2013-09-12 07:32:08 EDT
(In reply to Wayne Beaton from comment #37)
> (In reply to Austin Richards from comment #36)
> > I've worked on an implementation for this bug that can be found here:
> > https://github.com/R41D3NN/eclipse.jdt.ui/tree/Bug-60929--Java-Code-Block-
> > Folding
> 
> To be clear, I believe that Austin would like to contribute this code to the
> project. Austin has a signed CLA and the contribution has been
> signed-off-by. What is Austin's next step?

We are very busy working on Java 8 support, but might find a bit of time for an initial review and give an initial feedback, for that we either need a patch or a Gerrit change. This makes it easier to provide the feedback.
Comment 39 Palmer Eldritch CLA 2013-09-12 12:54:08 EDT
A related but not duplicate bug is : https://bugs.eclipse.org/bugs/show_bug.cgi?id=69684 - discussing adding folding support for anonymous and inner types - as well as top level types (classes/interfaces).

Could be also addressed here ?

Also to bring to your attention the (eternal) : https://bugs.eclipse.org/bugs/show_bug.cgi?id=63808

So adding folding support should be addressed with this in mind (adding support for custom regions, preferably user editable)
Comment 40 Austin Richards CLA 2013-09-17 16:38:19 EDT
Created attachment 235579 [details]
Patch For Bug Fix 60929
Comment 41 Palmer Eldritch CLA 2013-09-17 17:27:03 EDT
> Created attachment 235579 [details]
> Patch For Bug Fix 60929
It is a bit surprising that the folding does not use the AST of the file and instead it reads char by char - is the info not available ? Or is this used in the case the file has compilation errors ?

Anyway - folding is one of the important things IDEs have to offer - so please consider in your design the bugs in https://bugs.eclipse.org/bugs/show_bug.cgi?id=60929#c39 - especially the long lasting https://bugs.eclipse.org/bugs/show_bug.cgi?id=63808 - as well as a family of bugs like https://bugs.eclipse.org/bugs/show_bug.cgi?id=165681 (for PDT but I guess there is the analogous one in JDT) - essentially add the ability to fold any selected lines
Comment 42 Dani Megert CLA 2013-09-18 06:29:51 EDT
(In reply to Palmer Eldritch from comment #41)
> > Created attachment 235579 [details] [diff]
> > Patch For Bug Fix 60929
> It is a bit surprising that the folding does not use the AST of the file and
> instead it reads char by char - is the info not available ? Or is this used
> in the case the file has compilation errors ?
> 
> Anyway - folding is one of the important things IDEs have to offer - so
> please consider in your design the bugs in
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=60929#c39 - especially the
> long lasting https://bugs.eclipse.org/bugs/show_bug.cgi?id=63808 - as well
> as a family of bugs like
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=165681 (for PDT but I guess
> there is the analogous one in JDT) - essentially add the ability to fold any
> selected lines

So far folding does not use (and need) the AST, so that the folding can be presented faster. This is not nailed in stone though. All other comments are better made in the corresponding bugs. This one here is purely for code blocks.
Comment 43 Dani Megert CLA 2013-09-18 06:34:02 EDT
(In reply to Austin Richards from comment #40)
> Created attachment 235579 [details] [diff]
> Patch For Bug Fix 60929

Noopur, please make a first review when you have some spare time during your Java 8 work. Thanks.
Comment 44 Noopur Gupta CLA 2013-10-11 09:13:38 EDT
Created attachment 236373 [details]
Screenshot with issues

Initial review comments:

- Update the bundle version of org.eclipse.jdt.ui to 'Bundle-Version: 3.10.0.qualifier' in MANIFEST.MF.
- Add "@since 3.10" tag to the new DefaultJavaFoldingStructureProvider.FoldingStructureComputationContext.collapse*() methods and update the @since tags for new constants in PreferenceConstants.

- There is no check box for unnamed/anonymous blocks in Preferences.
(In reply to Austin Richards from comment #36)
> Unnamed (Anonymous) Block folding is currently disabled due to a bug, but I
> hope to fix this soon.
This doesn't seem to be supported yet in the attached patch. 
But the related code is partially present in the patch, with some commented code as well. Please update/remove that.

- Default values should be set for new preferences in PreferenceConstants.initializeDefaultValues(IPreferenceStore store).
- New preferences do not work : Check/uncheck has no difference on initial state of folding.
- Uncheck a new preference, click OK, reopen Folding Preferences -> the state of all the checkboxes is lost.
- Check all folding preferences (including old ones) and open this file:
//-------------------------
package code.block.folding.bug60929;

public class C3 {
	/**
	 * test
	 */
	private void foo() {

	}
}
//-------------------------
Expand the comment : The comment is expanded but it is still shown with collapsed marks at each line.
I haven't gone through DefaultJavaFoldingStructureProvider#computeCodeBlockFoldingStructure(...) yet, but this issue is not present when there is no call to this method.
The same issue also exists with newly added switch, try/catch/finally structures etc (See attached screenshot).

Please take care of these general guidelines also:
- Refer http://wiki.eclipse.org/JDT_UI/How_to_Contribute to configure your workspace with JDT UI specific Save Actions and follow the Coding Conventions mentioned there.
- Make sure the copyright date is updated to 2013.
- Add your credentials to the contributors list and follow this one line pattern:
Name <e-mail> - summary - https://bugs.eclipse.org/BUG_NUMBER
- Attach an EGit patch from next time instead of the msysgit patch.
- Post this in the bug report as a comment along with the patch: "This contribution complies with http://www.eclipse.org/legal/CoO.php"

- Dani, please have a look at the texts for new preferences and suggest their default values and order.
Comment 45 Palmer Eldritch CLA 2013-10-12 05:18:50 EDT
(In reply to Noopur Gupta from comment #44)
> Expand the comment : The comment is expanded but it is still shown with
> collapsed marks at each line.
> I haven't gone through
> DefaultJavaFoldingStructureProvider#computeCodeBlockFoldingStructure(...)
> yet, but this issue is not present when there is no call to this method.
> The same issue also exists with newly added switch, try/catch/finally
> structures etc (See attached screenshot).

I had reported the same behavior as a bug : https://bugs.eclipse.org/bugs/show_bug.cgi?id=403358

IIRC I had the coffe-bytes plugin at the time (probably I had already uninstalled it)

HTH
Comment 46 Jonathan Graf CLA 2022-06-23 16:03:40 EDT
VSCode offers code folding for all of the features listed in https://bugs.eclipse.org/bugs/show_bug.cgi?id=60929#c36.