private static boolean onTheLeftSideOfConditionalAssignment(final PsiElement psiAnchor) { final PsiElement parent = psiAnchor.getParent(); if (parent instanceof PsiAssignmentExpression) { final PsiAssignmentExpression expression = (PsiAssignmentExpression) parent; if (expression.getLExpression() == psiAnchor) return true; } return false; }
private static void checkSillyAssignment( PsiAssignmentExpression assignment, ProblemsHolder holder) { if (assignment.getOperationTokenType() != JavaTokenType.EQ) return; PsiExpression lExpression = assignment.getLExpression(); PsiExpression rExpression = assignment.getRExpression(); if (rExpression == null) return; lExpression = PsiUtil.deparenthesizeExpression(lExpression); rExpression = PsiUtil.deparenthesizeExpression(rExpression); if (!(lExpression instanceof PsiReferenceExpression)) return; PsiReferenceExpression rRef; if (!(rExpression instanceof PsiReferenceExpression)) { if (!(rExpression instanceof PsiAssignmentExpression)) return; final PsiAssignmentExpression rAssignmentExpression = (PsiAssignmentExpression) rExpression; final PsiExpression assignee = PsiUtil.deparenthesizeExpression(rAssignmentExpression.getLExpression()); if (!(assignee instanceof PsiReferenceExpression)) return; rRef = (PsiReferenceExpression) assignee; } else { rRef = (PsiReferenceExpression) rExpression; } PsiReferenceExpression lRef = (PsiReferenceExpression) lExpression; PsiManager manager = assignment.getManager(); if (!sameInstanceReferences(lRef, rRef, manager)) return; final PsiVariable variable = (PsiVariable) lRef.resolve(); if (variable == null) return; holder.registerProblem( assignment, InspectionsBundle.message("assignment.to.itself.problem.descriptor", variable.getName()), ProblemHighlightType.LIKE_UNUSED_SYMBOL); }