mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
folding builder style setters (IDEA-86541)
This commit is contained in:
@@ -267,7 +267,7 @@ public class JavaFoldingBuilder extends CustomFoldingBuilder implements DumbAwar
|
||||
PsiCodeBlock body = method.getBody();
|
||||
if (body == null) return false;
|
||||
PsiStatement[] statements = body.getStatements();
|
||||
if (statements.length != 1) return false;
|
||||
if (statements.length == 0) return false;
|
||||
PsiStatement statement = statements[0];
|
||||
if (PropertyUtil.isSimplePropertyGetter(method)) {
|
||||
if (statement instanceof PsiReturnStatement) {
|
||||
@@ -275,6 +275,7 @@ public class JavaFoldingBuilder extends CustomFoldingBuilder implements DumbAwar
|
||||
}
|
||||
}
|
||||
else if (PropertyUtil.isSimplePropertySetter(method)) {
|
||||
if (statements.length > 1 && !(statements[1] instanceof PsiReturnStatement)) return false;
|
||||
if (statement instanceof PsiExpressionStatement) {
|
||||
PsiExpression expr = ((PsiExpressionStatement)statement).getExpression();
|
||||
if (expr instanceof PsiAssignmentExpression) {
|
||||
|
||||
@@ -168,6 +168,27 @@ class Test {
|
||||
assertNotNull closureFolds
|
||||
assertEquals(2, closureFolds.size())
|
||||
}
|
||||
|
||||
public void "test builder style setter"() {
|
||||
myFoldingSettings.COLLAPSE_ACCESSORS = true
|
||||
def text = """\
|
||||
class Foo {
|
||||
private String bar;
|
||||
|
||||
public Foo setBar(String bar) {
|
||||
this.bar = bar;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
configure text
|
||||
def foldingModel = myFixture.editor.foldingModel as FoldingModelImpl
|
||||
int indexOfBar = text.indexOf("this.bar")
|
||||
def accessorStartFold = foldingModel.getCollapsedRegionAtOffset(indexOfBar)
|
||||
assertNotNull accessorStartFold
|
||||
assertFalse accessorStartFold.expanded
|
||||
}
|
||||
|
||||
public void "test closure folding doesn't expand when editing inside"() {
|
||||
def text = """\
|
||||
|
||||
Reference in New Issue
Block a user