boolean (@NotNull PsiExpression occurrence, @NotNull PsiVariable variable) { String variableName = variable.getName(); if (variableName == null) { return false; } PsiElementFactory factory = JavaPsiFacade.getElementFactory(variable.getProject()); PsiExpression refExpr; try { refExpr = factory.createExpressionFromText(variableName, occurrence); } catch (IncorrectOperationException e) { return false; } return refExpr instanceof PsiReferenceExpression && ((PsiReferenceExpression)refExpr).resolve() == variable; }