IDEA-169404 Don't use ellipsis for empty folded methods

This commit is contained in:
Dmitry Batrak
2017-03-15 15:41:56 +03:00
parent 12d4b2e07d
commit 1a920de862
3 changed files with 26 additions and 9 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -60,9 +60,17 @@ public abstract class JavaFoldingBuilderBase extends CustomFoldingBuilder implem
if (element instanceof PsiImportList) {
return "...";
}
if (element instanceof PsiMethod || element instanceof PsiClassInitializer || element instanceof PsiClass ||
element instanceof PsiLambdaExpression) {
return "{...}";
if (element instanceof PsiMethod) {
return getCodeBlockPlaceholder(((PsiMethod)element).getBody());
}
else if (element instanceof PsiClassInitializer) {
return getCodeBlockPlaceholder(((PsiClassInitializer)element).getBody());
}
else if (element instanceof PsiClass) {
return getCodeBlockPlaceholder(null);
}
else if (element instanceof PsiLambdaExpression) {
return getCodeBlockPlaceholder(((PsiLambdaExpression)element).getBody());
}
if (element instanceof PsiDocComment) {
return "/**...*/";
@@ -82,6 +90,10 @@ public abstract class JavaFoldingBuilderBase extends CustomFoldingBuilder implem
return "...";
}
private static String getCodeBlockPlaceholder(PsiElement codeBlock) {
return codeBlock instanceof PsiCodeBlock && ((PsiCodeBlock)codeBlock).getStatements().length == 0 ? "{}" : "{...}";
}
private static boolean areOnAdjacentLines(@NotNull PsiElement e1, @NotNull PsiElement e2, @NotNull Document document) {
return document.getLineNumber(e1.getTextRange().getEndOffset()) + 1 == document.getLineNumber(e2.getTextRange().getStartOffset());
}

View File

@@ -0,0 +1,4 @@
class Test {
void foo() <fold text='{}'>{
}</fold>
}

View File

@@ -72,9 +72,7 @@ public class JavaFoldingTest extends LightCodeInsightFixtureTestCase {
super.tearDown()
}
public void testEndOfLineComments() {
myFixture.testFolding("$PathManagerEx.testDataPath/codeInsight/folding/${getTestName(false)}.java");
}
public void testEndOfLineComments() { doTest() }
public void testEditingImports() {
configure """\
@@ -412,8 +410,11 @@ class Test {
assertEquals('test1', myFixture.editor.selectionModel.selectedText)
}
public void testCustomFolding() {
myFixture.testFolding("$PathManagerEx.testDataPath/codeInsight/folding/${getTestName(false)}.java");
public void testCustomFolding() { doTest() }
public void testEmptyMethod() { doTest() }
private doTest() {
myFixture.testFolding("$PathManagerEx.testDataPath/codeInsight/folding/${getTestName(false)}.java")
}
public void "test custom folding IDEA-122715 and IDEA-87312"() {