Java: Extract method from the whole body of duplicate method, move constants to parameters (IDEA-144957)

This commit is contained in:
Pavel Dolgov
2017-08-21 13:13:56 +03:00
parent 9877ecd8f2
commit 16307e9fdb
@@ -127,9 +127,13 @@ public class CodeInsightUtil {
}
if (endOffset != element2.getTextRange().getEndOffset()) return PsiElement.EMPTY_ARRAY;
if (parent instanceof PsiCodeBlock && parent.getParent() instanceof PsiBlockStatement &&
if (parent instanceof PsiCodeBlock &&
element1 == ((PsiCodeBlock)parent).getLBrace() && element2 == ((PsiCodeBlock)parent).getRBrace()) {
return new PsiElement[]{parent.getParent()};
if (parent.getParent() instanceof PsiBlockStatement) {
return new PsiElement[]{parent.getParent()};
}
PsiElement[] children = parent.getChildren();
return getStatementsInRange(children, ((PsiCodeBlock)parent).getFirstBodyElement(), ((PsiCodeBlock)parent).getLastBodyElement());
}
/*
@@ -139,6 +143,11 @@ public class CodeInsightUtil {
*/
PsiElement[] children = parent.getChildren();
return getStatementsInRange(children, element1, element2);
}
@NotNull
private static PsiElement[] getStatementsInRange(PsiElement[] children, PsiElement element1, PsiElement element2) {
ArrayList<PsiElement> array = new ArrayList<>();
boolean flag = false;
for (PsiElement child : children) {