-
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
custom folding regions #1825
Open
danthe1st
wants to merge
1
commit into
eclipse-jdt:master
Choose a base branch
from
danthe1st:folding
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,026
−53
Open
custom folding regions #1825
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
215 changes: 215 additions & 0 deletions
215
....text.tests/src/org/eclipse/jdt/text/tests/folding/CustomFoldingRegionNewFoldingTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Daniel Schmid and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Daniel Schmid - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.jdt.text.tests.folding; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import org.eclipse.core.runtime.CoreException; | ||
|
||
import org.eclipse.jface.preference.IPreferenceStore; | ||
|
||
import org.eclipse.jface.text.IRegion; | ||
|
||
import org.eclipse.jdt.ui.PreferenceConstants; | ||
|
||
import org.eclipse.jdt.internal.ui.JavaPlugin; | ||
|
||
public class CustomFoldingRegionNewFoldingTest extends CustomFoldingRegionTest { | ||
|
||
@Before | ||
@Override | ||
public void setUp() throws CoreException { | ||
super.setUp(); | ||
IPreferenceStore store= JavaPlugin.getDefault().getPreferenceStore(); | ||
store.setValue(PreferenceConstants.EDITOR_NEW_FOLDING_ENABLED, true); | ||
} | ||
|
||
|
||
@After | ||
@Override | ||
public void tearDown() throws CoreException { | ||
super.tearDown(); | ||
IPreferenceStore store= JavaPlugin.getDefault().getPreferenceStore(); | ||
store.setToDefault(PreferenceConstants.EDITOR_NEW_FOLDING_ENABLED); | ||
} | ||
|
||
@Test | ||
@Override | ||
public void testCustomFoldingRegionsInMethod() throws Exception { | ||
String str= """ | ||
package org.example.test; | ||
public class Test { | ||
void a(){ | ||
// region | ||
|
||
// endregion | ||
} | ||
} | ||
"""; | ||
List<IRegion> projectionRanges= getProjectionRangesOfFile(str); | ||
assertEquals(2, projectionRanges.size()); | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 2, 5); | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 3, 5); | ||
} | ||
|
||
@Test | ||
@Override | ||
public void testCustomFoldingRegionsMultipleLevels() throws Exception { | ||
String str= """ | ||
package org.example.test; | ||
// region outside class | ||
public class Test { | ||
// region outside method | ||
void a(){ | ||
// endregion should be ignored | ||
// region inside method | ||
System.out.println("Hello World"); | ||
// endregion inside method | ||
} | ||
// endregion outside method | ||
} | ||
// endregion outside class | ||
"""; | ||
List<IRegion> projectionRanges= getProjectionRangesOfFile(str); | ||
assertEquals(4, projectionRanges.size()); | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 1, 12);//outside class | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 3, 10);//outside method | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 4, 8);//void a() | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 6, 8);//inside method | ||
} | ||
|
||
@Test | ||
@Override | ||
public void testCustomFoldingRegionsUsingSpecialCommentTypes() throws Exception { | ||
String str= """ | ||
package org.example.test; | ||
|
||
public class Test { | ||
void a(){ | ||
/* region multiline | ||
*/ | ||
/** region javadoc */ | ||
/** endregion javadoc */ | ||
/* endregion multiline | ||
*/ | ||
} | ||
} | ||
"""; | ||
List<IRegion> projectionRanges= getProjectionRangesOfFile(str); | ||
assertEquals(5, projectionRanges.size()); | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 3, 9);//void a() | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 4, 5);// multiline (comment) | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 4, 9);// multiline (folding region) | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 6, 7);// javadoc | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 8, 9);// multiline (last comment) | ||
} | ||
|
||
@Test | ||
@Override | ||
public void testCustomRegionsWithLocalClass() throws Exception { | ||
String str= """ | ||
package org.example.test; | ||
|
||
public class Test { | ||
void a(){ | ||
// region | ||
int i; | ||
|
||
// endregion | ||
class Inner{ | ||
|
||
} | ||
} | ||
} | ||
"""; | ||
List<IRegion> projectionRanges= getProjectionRangesOfFile(str); | ||
assertEquals(2, projectionRanges.size()); | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 3, 10);//void a() | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 4, 7);//region | ||
} | ||
|
||
@Test | ||
@Override | ||
public void testCustomRegionsAroundFieldAndMethod() throws Exception { | ||
String str= """ | ||
package org.example.test; | ||
|
||
public class Test { | ||
// region | ||
int a; | ||
|
||
void b(){ | ||
|
||
} | ||
// endregion | ||
} | ||
"""; | ||
List<IRegion> projectionRanges= getProjectionRangesOfFile(str); | ||
assertEquals(2, projectionRanges.size()); | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 3, 9);//region | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 6, 7);//void b() | ||
} | ||
|
||
@Test | ||
@Override | ||
public void testCommentsInEmptyBlocks() throws Exception { | ||
String str= """ | ||
package org.example.test; | ||
public class Test { | ||
void a(){ | ||
{/* region 1*/} | ||
System.out.println("Hello World"); | ||
{/* endregion 1*/} | ||
} | ||
} | ||
"""; | ||
List<IRegion> projectionRanges= getProjectionRangesOfFile(str); | ||
assertEquals(2, projectionRanges.size()); | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 2, 5);//void a() | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 3, 5);//region 1 | ||
} | ||
|
||
@Test | ||
public void testNotFoldedWithinDifferentControlFlowStatements() throws Exception { | ||
String str= """ | ||
package org.example.test; | ||
public class Test { | ||
void a() { | ||
// region | ||
for (int i = 0; i < 10; i++) { | ||
// endregion | ||
// region | ||
} | ||
boolean b=false; | ||
// region | ||
while (b) { | ||
// endregion | ||
} | ||
} | ||
} | ||
"""; | ||
List<IRegion> projectionRanges= getProjectionRangesOfFile(str); | ||
assertEquals(3, projectionRanges.size()); | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 2, 12);//void a() | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 4, 6);//void a() | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 10, 11);//void a() | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This test class runs all tests from
testCommentsInEmptyBlocks
with the new folding introduced in #1562.The test methods that yield different results (due to the folding being different in some ways, for example #1992) are overridden.