mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
no closure folding for synchronized methods (IDEA-87268)
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user