/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * 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.
private static PsiElement findTopmostParentOfType(PsiElement el, Class<? extends PsiElement> clazz) {
while (true) {
@SuppressWarnings({"unchecked"})
- PsiElement temp = PsiTreeUtil.getParentOfType(el, clazz, true, PsiAnonymousClass.class);
+ PsiElement temp = PsiTreeUtil.getParentOfType(el, clazz, true, PsiAnonymousClass.class, PsiLambdaExpression.class);
if (temp == null || temp instanceof PsiFile) return el;
el = temp;
}
}
else {
context.extractElement(body, from);
- if (context.myIsEffective) {
+ if (context.myIsEffective && !(from.getParent() instanceof PsiLambdaExpression)) {
PsiStatement emptyStatement = JavaPsiFacade.getElementFactory(from.getProject()).createStatementFromText(";", from);
from.getParent().addBefore(emptyStatement, from);
}
" Sys<caret>tem.gc();\n" +
"}\n");
}
+
+ public void testUnwrapNestedLambda() throws Exception {
+ assertUnwrapped("{\n" +
+ " bar(() -> bar(() -> Sys<caret>tem.gc()));\n" +
+ "}\n",
+
+ "{\n" +
+ " bar(() -> Sys<caret>tem.gc());\n" +
+ "}\n", 1);
+ }
public void testUnwrapExpressionDeclaration() throws Exception {
assertUnwrapped("{\n" +
" null;\n" +
"}\n");
}
+
+ @Override
+ protected String createCode(String codeBefore) {
+ return "public class A {\n" +
+ " void foo() {\n" +
+ indentTwice(codeBefore) +
+ " }\n" +
+ " void bar(Runnable r){}\n" +
+ "}";
+ }
}
\ No newline at end of file