mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
return lambda folding in some cases where anonymous->lambda conversion is anyway impossible
This commit is contained in:
+3
-1
@@ -807,7 +807,7 @@ public abstract class JavaFoldingBuilderBase extends CustomFoldingBuilder implem
|
||||
if (argumentList != null && argumentList.getExpressions().length == 0) {
|
||||
final PsiMethod[] methods = anonymousClass.getMethods();
|
||||
PsiClass baseClass = anonymousClass.getBaseClassType().resolve();
|
||||
if (hasOnlyOneLambdaMethod(anonymousClass, !quick) && seemsLikeLambda(baseClass) && !PsiUtil.isLanguageLevel8OrHigher(anonymousClass)) {
|
||||
if (hasOnlyOneLambdaMethod(anonymousClass, !quick) && seemsLikeLambda(baseClass)) {
|
||||
final PsiMethod method = methods[0];
|
||||
final PsiCodeBlock body = method.getBody();
|
||||
if (body != null) {
|
||||
@@ -841,6 +841,8 @@ public abstract class JavaFoldingBuilderBase extends CustomFoldingBuilder implem
|
||||
String type = quick ? "" : getOptionalLambdaType(anonymousClass, expression);
|
||||
String methodName = quick || !isImplementingLambdaMethod(baseClass) ? method.getName() : "";
|
||||
|
||||
if (StringUtil.isEmpty(methodName) && PsiUtil.isLanguageLevel8OrHigher(anonymousClass)) return false;
|
||||
|
||||
final String params = StringUtil.join(method.getParameterList().getParameters(), new Function<PsiParameter, String>() {
|
||||
@Override
|
||||
public String fun(final PsiParameter psiParameter) {
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright 2000-2016 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
|
||||
*
|
||||
* 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 com.intellij.codeInsight.folding
|
||||
|
||||
import com.intellij.codeInsight.folding.impl.CodeFoldingManagerImpl
|
||||
import com.intellij.codeInsight.folding.impl.JavaCodeFoldingSettingsImpl
|
||||
import com.intellij.codeInsight.folding.impl.JavaFoldingBuilder
|
||||
import com.intellij.openapi.editor.ex.FoldingModelEx
|
||||
import com.intellij.openapi.editor.impl.FoldingModelImpl
|
||||
import com.intellij.testFramework.LightProjectDescriptor
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class JavaFolding8Test extends LightCodeInsightFixtureTestCase {
|
||||
|
||||
def JavaCodeFoldingSettingsImpl myFoldingSettings
|
||||
def JavaCodeFoldingSettingsImpl myFoldingStateToRestore
|
||||
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_8
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() {
|
||||
super.setUp()
|
||||
myFoldingSettings = JavaCodeFoldingSettings.instance as JavaCodeFoldingSettingsImpl
|
||||
myFoldingStateToRestore = new JavaCodeFoldingSettingsImpl()
|
||||
myFoldingStateToRestore.loadState(myFoldingSettings)
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() {
|
||||
myFoldingSettings.loadState(myFoldingStateToRestore)
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
public void "test no plain lambda folding where anonymous class can be real lambda but fold otherwise"() {
|
||||
myFixture.addClass('interface Runnable2 { void run(); }')
|
||||
myFixture.addClass('abstract class MyAction { public void run(); public void update() {} }')
|
||||
def text = """\
|
||||
class Test {
|
||||
void test() {
|
||||
Runnable r = new Runnable2() {
|
||||
public void run() {
|
||||
System.out.println();
|
||||
}
|
||||
};
|
||||
MyAction action = new MyAction() {
|
||||
public void run() {
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
configure text
|
||||
def foldingModel = myFixture.editor.foldingModel as FoldingModelImpl
|
||||
|
||||
assert foldingModel.getCollapsedRegionAtOffset(text.indexOf("MyAction(")).placeholderText == 'run() ' + JavaFoldingBuilder.rightArrow + ' { '
|
||||
assert !foldingModel.getCollapsedRegionAtOffset(text.indexOf("Runnable2("))
|
||||
}
|
||||
|
||||
private def configure(String text) {
|
||||
myFixture.configureByText("a.java", text)
|
||||
CodeFoldingManagerImpl.getInstance(getProject()).buildInitialFoldings(myFixture.editor);
|
||||
def foldingModel = myFixture.editor.foldingModel as FoldingModelEx
|
||||
foldingModel.rebuild()
|
||||
myFixture.doHighlighting()
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user