disable surround with parenthesis for one-no-type-parameter lambda

This commit is contained in:
Anna Kozlova
2015-06-18 21:26:57 +03:00
parent ecbb43f6a8
commit 36ca5d6a23
4 changed files with 20 additions and 1 deletions
@@ -319,7 +319,8 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase {
if (endOffset <= startOffset) return null;
PsiElement elementAt = PsiTreeUtil.findCommonParent(elementAtStart, elementAtEnd);
if (PsiTreeUtil.getParentOfType(elementAt, PsiExpression.class, false) == null) {
final PsiExpression containingExpression = PsiTreeUtil.getParentOfType(elementAt, PsiExpression.class, false);
if (containingExpression == null || containingExpression instanceof PsiLambdaExpression) {
if (injectedLanguageManager.isInjectedFragment(file)) {
return getSelectionFromInjectedHost(project, file, injectedLanguageManager, startOffset, endOffset);
}
@@ -0,0 +1,8 @@
interface I {
String apply(String s);
}
class Test {
{
I f = <selection>s</selection> -> s;
}
}
@@ -194,6 +194,16 @@ public class JavaSurroundWithTest extends LightCodeInsightTestCase {
doTest(new JavaWithBlockSurrounder());
}
public void testNoParenthesisSurrounderForLambdaParameter() throws Exception {
configureByFile(BASE_PATH + getTestName(false) + ".java");
SurroundDescriptor item = ContainerUtil.getFirstItem(LanguageSurrounders.INSTANCE.allForLanguage(JavaLanguage.INSTANCE));
assertNotNull(item);
SelectionModel selectionModel = getEditor().getSelectionModel();
PsiElement[] elements = item.getElementsToSurround(getFile(), selectionModel.getSelectionStart(), selectionModel.getSelectionEnd());
assertEmpty(elements);
}
private void doTest(Surrounder surrounder) {
doTest(getTestName(false), surrounder);
}