-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Folding mechanism for while/for/if/... #1562
base: master
Are you sure you want to change the base?
Folding mechanism for while/for/if/... #1562
Conversation
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/folding/DefaultJavaFoldingStructureProvider.java
Show resolved
Hide resolved
08cd1d9
to
afd4aed
Compare
Bug:
|
c2082f5
to
0390f1c
Compare
c1ac59f
to
80ee66d
Compare
d5cf645
to
a44a7e0
Compare
The test failures seem to be unrelated: https://ci.eclipse.org/jdt/job/eclipse.jdt.ui-github/job/PR-1562/21/testReport/ The only test that fails with age == 1 (i.e. in this PR) is java.lang.AssertionError:
Wrong bundles loaded:
- org.eclipse.jdt.junit
expected:<0> but was:<24>
at org.junit.Assert.fail(Assert.java:89)
at org.junit.Assert.failNotEquals(Assert.java:835)
at org.junit.Assert.assertEquals(Assert.java:647)
at org.eclipse.jdt.text.tests.PluginsNotLoadedTest.pluginsNotLoaded(PluginsNotLoadedTest.java:278)
... Does anyone know the reason for this failure? In the meantime @jakub-suliga, try with another force-push to re-trigger the checks and see if the failure persists. |
a44a7e0
to
b49f6c9
Compare
On a closer look, the test failures are because of the changes introduced in this PR. Run them locally and you will see it. Here's (part of) the console output when running !STACK 0
java.lang.ClassCastException: class org.eclipse.jdt.internal.core.ClassFile cannot be cast to class org.eclipse.jdt.core.ICompilationUnit (org.eclipse.jdt.internal.core.ClassFile and org.eclipse.jdt.core.ICompilationUnit are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @21452f5e)
at org.eclipse.jdt.ui.text.folding.DefaultJavaFoldingStructureProvider.computeFoldingStructure(DefaultJavaFoldingStructureProvider.java:981)
at org.eclipse.jdt.ui.text.folding.DefaultJavaFoldingStructureProvider.update(DefaultJavaFoldingStructureProvider.java:907)
at org.eclipse.jdt.ui.text.folding.DefaultJavaFoldingStructureProvider.initialize(DefaultJavaFoldingStructureProvider.java:852)
at org.eclipse.jdt.ui.text.folding.DefaultJavaFoldingStructureProvider.handleProjectionEnabled(DefaultJavaFoldingStructureProvider.java:822)
at org.eclipse.jdt.ui.text.folding.DefaultJavaFoldingStructureProvider$ProjectionListener.projectionEnabled(DefaultJavaFoldingStructureProvider.java:700)
...
at org.eclipse.jdt.ui.tests.quickfix.AnnotateAssistTest1d5.testAnnotateReturn2(AnnotateAssistTest1d5.java:178)
... It seems the It would be interesting to know when exactly is |
d68c88b
to
baf2632
Compare
@iloveeclipse : Jakub and I were looking into the failed tests and we found the culprit: it was a Do you see any possible problem with this change? We couldn't come up with any but maybe you can? |
5205312
to
397df4a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor comments for the moment.
org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/folding/FoldingTest.java
Outdated
Show resolved
Hide resolved
org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/folding/FoldingTest.java
Outdated
Show resolved
Hide resolved
org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/folding/FoldingTest.java
Outdated
Show resolved
Hide resolved
org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/folding/FoldingTest.java
Outdated
Show resolved
Hide resolved
@@ -102,6 +102,12 @@ public Control createControl(Composite composite) { | |||
addCheckBox(inner, FoldingMessages.DefaultJavaFoldingPreferenceBlock_methods, PreferenceConstants.EDITOR_FOLDING_METHODS, 0); | |||
addCheckBox(inner, FoldingMessages.DefaultJavaFoldingPreferenceBlock_imports, PreferenceConstants.EDITOR_FOLDING_IMPORTS, 0); | |||
|
|||
Label label2= new Label(inner, SWT.LEFT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't need this. Try to improve the overall design of the whole configuration page and make it look more like the Content Assist page, which has Group
s (with borders). You should have 2 groups:
- Initially fold ...
- Extended folding (Experimental) : This one is yours and has
- A
Label
with an explanation like "Enable folding for other code blocks. Activating this feature may cause a significant performance degradation" - A checkbox: "Activate feature".
- A
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- A checkbox: "Activate feature".
Probably better to explicitly say "Enable folding for if/for/while blocks" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, because it enables folding not only for if, for, and while blocks, but also for constructs such as try/catch blocks, lambdas et cetera.
3f5b295
to
60dc8fb
Compare
The test failure is unrelated. #1095 |
org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/folding/FoldingTest.java
Outdated
Show resolved
Hide resolved
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/folding/DefaultJavaFoldingStructureProvider.java
Outdated
Show resolved
Hide resolved
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/folding/DefaultJavaFoldingStructureProvider.java
Outdated
Show resolved
Hide resolved
ac241c8
to
e15cacf
Compare
The build failure seems to be unrelated, it's a timeout. Maybe it will work next time it runs (e.g. when you rebase and push again). 15:42:55 [ERROR] Failed to execute goal org.eclipse.tycho:tycho-apitools-plugin:4.0.11-SNAPSHOT:verify (verify) on project org.eclipse.jdt.ui: Execution verify of goal org.eclipse.tycho:tycho-apitools-plugin:4.0.11-SNAPSHOT:verify failed: Could not mirror artifact osgi.bundle,org.mortbay.jasper.apache-jsp.source,9.0.96 into the local Maven repository.See log output for details. request timed out -> [Help 1] |
e15cacf
to
34817f9
Compare
The code looks much better now, thank you for the corrections @jakub-suliga. Maybe after you fix my last #1562 (comment), a JDT committer (@iloveeclipse?) would like to review again? I'm off for today, have a nice weekend! |
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/folding/DefaultJavaFoldingStructureProvider.java
Outdated
Show resolved
Hide resolved
org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/folding/FoldingTest.java
Outdated
Show resolved
Hide resolved
org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/folding/FoldingTest.java
Outdated
Show resolved
Hide resolved
I can't guarantee I will have time next week, I'm overloaded. The feature itself seems to be useful, so if the new test also covers existing functionality & is green, why not merge? @jjohnstn : are you available to review this? |
34817f9
to
4ae83f5
Compare
@iloveeclipse Sure |
@jakub-suliga Just trying it out, it seems to work well. I tried the given test but it does not fold the switch statement or its cases. Is that expected or is that something that isn't working in my particular test? I ran into a major bug with folding on my Linux platform which is likely Linux specific. If I fold, then hover over the plus and then click on the hover to focus it; there is no way out but Esc. This closes the hover but the flashing cursor is missing and the window pointer can get changed to the window expansion characters if I am on the edges of the hover area at the time of escape. I got similar experiences sometimes after entering via F2 to get focus in the hover window, but it seemed better and I often got the flashing cursor back. Once the cursor was gone, I could only get it back by switching into another Eclipse and its editor and then switching back. Again, likely Fedora specific, but I ask in case you have Windows/Mac and can confirm that it doesn't occur for you. It is not caused by this PR. |
Never mind. I can see from the code that switch statements aren't covered. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, code looks good, but 2 comments to address.
* the region from after the '/**' to the beginning of the content, the other | ||
* from after the first content line until after the comment. | ||
*/ | ||
private static final class CommentPosition extends Position implements IProjectionPosition { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your removal of the CommentPosition class has changed functionality. The old folding for a Javadoc comment will show you the first line after the /** after folding but your code just shows /**
/**
* Function comment
*
*/
Old:
* Function comment ...
New:
/**
*/
@@ -0,0 +1,362 @@ | |||
/******************************************************************************* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to have at least one test that verifies the region values are as expected as opposed to just count (e.g. verify that finally region starts at the beginning of the finally keyword and not the block
Problem:
Currently, there is no folding mechanism for while/for/if/switch-case statements in Eclipse. VSCode and IntelliJ support a folding mechanism for these statements. Therefore, I have created a method that implements this folding mechanism. This is also an open issue: #1426. In addition, I deleted some commented-out code from 2007.
Before:
After:
How to test:
Here is a small program you can use to test:
Bugs: