no closure folding for synchronized methods (IDEA-87268)

This commit is contained in:
peter
2012-06-12 19:26:34 +02:00
parent 61b7d0c997
commit 1e90838aba
2 changed files with 24 additions and 3 deletions
@@ -569,7 +569,7 @@ public class JavaFoldingBuilder extends CustomFoldingBuilder implements DumbAwar
}
}
private static boolean hasOnlyOneMethod(@NotNull PsiAnonymousClass anonymousClass, boolean checkResolve) {
private static boolean hasOnlyOneLambdaMethod(@NotNull PsiAnonymousClass anonymousClass, boolean checkResolve) {
PsiField[] fields = anonymousClass.getFields();
if (fields.length != 0) {
if (fields.length == 1 && HighlightUtil.SERIAL_VERSION_UID_FIELD_NAME.equals(fields[0].getName()) &&
@@ -590,8 +590,13 @@ public class JavaFoldingBuilder extends CustomFoldingBuilder implements DumbAwar
return false;
}
PsiMethod method = anonymousClass.getMethods()[0];
if (method.hasModifierProperty(PsiModifier.SYNCHRONIZED)) {
return false;
}
if (checkResolve) {
PsiReferenceList throwsList = anonymousClass.getMethods()[0].getThrowsList();
PsiReferenceList throwsList = method.getThrowsList();
for (PsiClassType type : throwsList.getReferencedTypes()) {
if (type.resolve() == null) {
return false;
@@ -617,7 +622,7 @@ public class JavaFoldingBuilder extends CustomFoldingBuilder implements DumbAwar
final PsiExpressionList argumentList = expression.getArgumentList();
if (argumentList != null && argumentList.getExpressions().length == 0) {
final PsiMethod[] methods = anonymousClass.getMethods();
if (hasOnlyOneMethod(anonymousClass, !quick) && (quick || seemsLikeLambda(anonymousClass.getBaseClassType().resolve()))) {
if (hasOnlyOneLambdaMethod(anonymousClass, !quick) && (quick || seemsLikeLambda(anonymousClass.getBaseClassType().resolve()))) {
final PsiMethod method = methods[0];
final PsiCodeBlock body = method.getBody();
if (body != null) {
@@ -283,6 +283,22 @@ class Test {
assert !foldingModel.getCollapsedRegionAtOffset(text.indexOf("Runnable"))
}
public void "test no closure folding for synchronized methods"() {
def text = """\
class Test {
void test() { new Runnable() {
public synchronized void run() {
System.out.println(<caret>);
}
};
}
}
"""
configure text
def foldingModel = myFixture.editor.foldingModel as FoldingModelImpl
assert !foldingModel.getCollapsedRegionAtOffset(text.indexOf("Runnable"))
}
public void testFindInFolding() {
def text = """\
class Test {