boolean (PsiVariable leftVar, @Nullable PsiExpression left, PsiVariable rightVar, @Nullable PsiExpression right) { if (left == null || right == null) return false; if (VariableAccessUtils.variableIsUsed(rightVar, left) || VariableAccessUtils.variableIsUsed(leftVar, right)) { return false; } PsiExpression copy = (PsiExpression)right.copy(); PsiElement[] rightRefs = PsiTreeUtil.collectElements(copy, e -> e instanceof PsiReferenceExpression && ((PsiReferenceExpression)e).resolve() == rightVar); PsiElementFactory factory = JavaPsiFacade.getElementFactory(left.getProject()); String paramName = leftVar.getName(); if (paramName == null) return false; for (PsiElement ref : rightRefs) { PsiElement nameElement = ((PsiReferenceExpression)ref).getReferenceNameElement(); LOG.assertTrue(nameElement != null); nameElement.replace(factory.createIdentifier(paramName)); } return EquivalenceChecker.getCanonicalPsiEquivalence().expressionsAreEquivalent(left, copy); }