mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-177288 Compiling evaluator fails inside single expression ifs or loops
This commit is contained in:
+12
-1
@@ -133,7 +133,7 @@ public class ExtractLightMethodObjectHandler {
|
||||
}
|
||||
}
|
||||
|
||||
final PsiElement container;
|
||||
PsiElement container;
|
||||
if (anchor == null) {
|
||||
container = ((PsiClassInitializer)containingClass.add(elementFactory.createClassInitializer())).getBody();
|
||||
anchor = container.getLastChild();
|
||||
@@ -142,6 +142,17 @@ public class ExtractLightMethodObjectHandler {
|
||||
container = anchor.getParent();
|
||||
}
|
||||
|
||||
// add code blocks for ifs and loops if needed
|
||||
if (anchor instanceof PsiStatement && RefactoringUtil.isLoopOrIf(container)) {
|
||||
PsiBlockStatement codeBlockStatement =
|
||||
(PsiBlockStatement)JavaPsiFacade.getElementFactory(project).createStatementFromText("{}", container);
|
||||
codeBlockStatement.getCodeBlock().add(anchor);
|
||||
PsiCodeBlock codeBlock = ((PsiBlockStatement)anchor.replace(codeBlockStatement)).getCodeBlock();
|
||||
anchor = codeBlock.getStatements()[0];
|
||||
originalAnchor = anchor;
|
||||
container = codeBlock;
|
||||
}
|
||||
|
||||
final PsiElement firstElementCopy = container.addRangeBefore(elements[0], elements[elements.length - 1], anchor);
|
||||
final PsiElement[] elementsCopy = CodeInsightUtil.findStatementsInRange(copy,
|
||||
firstElementCopy.getTextRange().getStartOffset(),
|
||||
|
||||
Reference in New Issue
Block a user