PsiElement (PsiElement expression, PsiElement declaration, List<? extends PsiElement> occurrences, boolean replaceAll) { PsiElement anchor = replaceAll ? IntroduceHandler.findAnchor(occurrences) : PsiTreeUtil.getParentOfType(expression, PyStatement.class); assert anchor != null; final PsiElement parent = anchor.getParent(); return parent.addBefore(declaration, anchor); }