mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
IDEA-76021 Groovy: Indentation of closing brace for closure is wrong
This commit is contained in:
@@ -24,6 +24,9 @@ import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -99,6 +102,17 @@ public class GeeseUtil {
|
||||
|
||||
//search for start of the line
|
||||
cur = parent;
|
||||
if (cur.getParent() instanceof GrMethodCall) {
|
||||
GrMethodCall call = (GrMethodCall)cur.getParent();
|
||||
GrExpression invoked = call.getInvokedExpression();
|
||||
if (invoked instanceof GrReferenceExpression && ((GrReferenceExpression)invoked).getReferenceNameElement() != null) {
|
||||
cur = ((GrReferenceExpression)invoked).getReferenceNameElement();
|
||||
}
|
||||
else {
|
||||
cur = call;
|
||||
}
|
||||
}
|
||||
cur = PsiTreeUtil.getDeepestFirst(cur);
|
||||
while (!PsiUtil.isNewLine(next = PsiTreeUtil.prevLeaf(cur, true))) {
|
||||
if (next == null) break;
|
||||
cur = next;
|
||||
|
||||
@@ -171,6 +171,7 @@ public class GroovyEnterHandler extends EnterHandlerDelegateAdapter {
|
||||
|
||||
String text = document.getText();
|
||||
int nextLineFeed = text.indexOf('\n', caretOffset + 1);
|
||||
if (nextLineFeed == -1) nextLineFeed = text.length();
|
||||
CodeStyleManager.getInstance(project).reformatText(file, caretOffset, nextLineFeed);
|
||||
|
||||
return true;
|
||||
|
||||
@@ -243,5 +243,33 @@ def c = { a ->
|
||||
|
||||
}
|
||||
|
||||
public void testGeese1() {
|
||||
doTest '''[1, 2, 3, 4].
|
||||
toSet().
|
||||
findAllXxx {
|
||||
it > 2
|
||||
foo {<caret>}
|
||||
}''',
|
||||
'''[1, 2, 3, 4].
|
||||
toSet().
|
||||
findAllXxx {
|
||||
it > 2
|
||||
foo {
|
||||
<caret>
|
||||
} }'''
|
||||
|
||||
}
|
||||
|
||||
public void testGeese2() {
|
||||
doTest '''foo {
|
||||
bar {<caret>}
|
||||
}
|
||||
''', '''foo {
|
||||
bar {
|
||||
<caret>
|
||||
} }
|
||||
'''
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/*
|
||||
* Copyright 2000-2007 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.
|
||||
* You may obtain a copy of the License at
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.plugins.groovy.lang.formatter;
|
||||
@@ -218,5 +218,20 @@ public class FormatterTest extends GroovyFormatterTestCase {
|
||||
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testGeese1() {doGeeseTest();}
|
||||
public void testGeese2() {doGeeseTest();}
|
||||
public void testGeese3() {doGeeseTest();}
|
||||
|
||||
private void doGeeseTest() {
|
||||
GroovyCodeStyleSettings customSettings = myTempSettings.getCustomSettings(GroovyCodeStyleSettings.class);
|
||||
boolean oldvalue = customSettings.USE_FLYING_GEESE_BRACES;
|
||||
try {
|
||||
customSettings.USE_FLYING_GEESE_BRACES = true;
|
||||
doTest();
|
||||
}
|
||||
finally {
|
||||
customSettings.USE_FLYING_GEESE_BRACES = oldvalue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
25
plugins/groovy/testdata/groovy/formatter/geese1.test
vendored
Normal file
25
plugins/groovy/testdata/groovy/formatter/geese1.test
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
foo(2) {
|
||||
foo(2, {
|
||||
foo(2) {
|
||||
print f
|
||||
}})}
|
||||
|
||||
foo(2) {
|
||||
foo(2) {
|
||||
foo(2, {
|
||||
print f
|
||||
})}}
|
||||
-----
|
||||
foo(2) {
|
||||
foo(2, {
|
||||
foo(2) {
|
||||
print f
|
||||
} })
|
||||
}
|
||||
|
||||
foo(2) {
|
||||
foo(2) {
|
||||
foo(2, {
|
||||
print f
|
||||
})
|
||||
} }
|
||||
11
plugins/groovy/testdata/groovy/formatter/geese2.test
vendored
Normal file
11
plugins/groovy/testdata/groovy/formatter/geese2.test
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
foo {
|
||||
bar {
|
||||
test {
|
||||
|
||||
}}}
|
||||
-----
|
||||
foo {
|
||||
bar {
|
||||
test {
|
||||
|
||||
} } }
|
||||
13
plugins/groovy/testdata/groovy/formatter/geese3.test
vendored
Normal file
13
plugins/groovy/testdata/groovy/formatter/geese3.test
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
foo (
|
||||
2) {
|
||||
bar(
|
||||
3) {
|
||||
print a
|
||||
}}
|
||||
-----
|
||||
foo(
|
||||
2) {
|
||||
bar(
|
||||
3) {
|
||||
print a
|
||||
} }
|
||||
Reference in New Issue
Block a user