mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-120694 collapsing one liners is overly eager
This commit is contained in:
+12
@@ -69,11 +69,23 @@ public abstract class JavaFoldingBuilderBase extends CustomFoldingBuilder implem
|
||||
return "...";
|
||||
}
|
||||
|
||||
private static boolean areOnAdjacentLines(PsiElement e1, PsiElement e2) {
|
||||
Document document = e1.getContainingFile().getViewProvider().getDocument();
|
||||
return document != null &&
|
||||
document.getLineNumber(e1.getTextRange().getEndOffset()) + 1 == document.getLineNumber(e2.getTextRange().getStartOffset());
|
||||
}
|
||||
|
||||
private static boolean isSimplePropertyAccessor(PsiMethod method) {
|
||||
PsiCodeBlock body = method.getBody();
|
||||
if (body == null || body.getLBrace() == null || body.getRBrace() == null) return false;
|
||||
PsiStatement[] statements = body.getStatements();
|
||||
if (statements.length == 0) return false;
|
||||
|
||||
if (!areOnAdjacentLines(body.getLBrace(), statements[0]) || !areOnAdjacentLines(statements[statements.length - 1], body.getRBrace())) {
|
||||
//the user might intend to type at an empty line
|
||||
return false;
|
||||
}
|
||||
|
||||
PsiStatement statement = statements[0];
|
||||
if (PropertyUtil.isSimplePropertyGetter(method)) {
|
||||
if (statement instanceof PsiReturnStatement) {
|
||||
|
||||
@@ -457,6 +457,7 @@ class Test {
|
||||
configure """class Foo {
|
||||
int field;
|
||||
int field2;
|
||||
int field3;
|
||||
|
||||
int getField()
|
||||
{
|
||||
@@ -467,12 +468,18 @@ class Test {
|
||||
field = f;
|
||||
}
|
||||
|
||||
void setField2(int f){field2=f;}
|
||||
void setField2(int f){field2=f;} // normal method folding here
|
||||
|
||||
// normal method folding here
|
||||
void setField3(int f){
|
||||
|
||||
field2=f;
|
||||
}
|
||||
|
||||
}"""
|
||||
PsiClass fooClass = JavaPsiFacade.getInstance(project).findClass('Foo', GlobalSearchScope.allScope(project))
|
||||
def regions = myFixture.editor.foldingModel.allFoldRegions.sort { it.startOffset }
|
||||
assert regions.size() == 5
|
||||
assert regions.size() == 6
|
||||
|
||||
Closure checkAccessorFolding = { FoldRegion region1, FoldRegion region2, PsiMethod method ->
|
||||
assert region1.startOffset == method.parameterList.textRange.endOffset
|
||||
@@ -489,6 +496,7 @@ class Test {
|
||||
checkAccessorFolding(regions[2], regions[3], fooClass.methods[1])
|
||||
|
||||
assert regions[4].placeholderText == '{...}'
|
||||
assert regions[5].placeholderText == '{...}'
|
||||
}
|
||||
|
||||
private def changeFoldRegions(Closure op) {
|
||||
|
||||
Reference in New Issue
Block a user