List<PsiElement> (@NotNull final PsiField variable) { final Map<PsiCodeBlock, Collection<PsiReferenceExpression>> refs = new HashMap<>(); final List<PsiElement> newDeclarations = new ArrayList<>(); final PsiClass containingClass = variable.getContainingClass(); if (containingClass == null) return newDeclarations; final PsiClass scope = findVariableScope(containingClass); if (!groupByCodeBlocks(VariableAccessUtils.getVariableReferences(variable, scope), refs)) return newDeclarations; PsiElement declaration; for (Collection<PsiReferenceExpression> psiReferences : refs.values()) { declaration = copyVariableToMethodBody(variable, psiReferences); if (declaration != null) newDeclarations.add(declaration); } if (!newDeclarations.isEmpty()) { final PsiElement lastDeclaration = newDeclarations.get(newDeclarations.size() - 1); deleteField(variable, lastDeclaration); } return newDeclarations; }