ElementToWorkOn (PsiExpression expr, PsiElement anchorElement) { PsiLocalVariable localVariable = null; if (anchorElement instanceof PsiLocalVariable) { localVariable = (PsiLocalVariable)anchorElement; } else if (expr instanceof PsiReferenceExpression) { PsiElement ref = ((PsiReferenceExpression)expr).resolve(); if (ref instanceof PsiLocalVariable) { localVariable = (PsiLocalVariable)ref; } } else if (expr instanceof PsiArrayInitializerExpression && expr.getParent() instanceof PsiNewExpression) { expr = (PsiExpression)expr.getParent(); } return new ElementToWorkOn(localVariable, expr); }