boolean (final PsiExpression cause, final PsiExpression newLocation) { if (cause == null || newLocation == null) return false; assert cause.getTextOffset() > newLocation.getTextOffset(); final PsiCodeBlock block = PsiTreeUtil.getParentOfType(cause, PsiCodeBlock.class); final PsiCodeBlock newBlock = PsiTreeUtil.getParentOfType(newLocation, PsiCodeBlock.class); if (newBlock == null || !PsiTreeUtil.isAncestor(block, newBlock, false)) return false; final int offset = newLocation.getTextOffset(); final Ref<Boolean> result = new Ref<>(Boolean.TRUE); cause.accept(new JavaRecursiveElementWalkingVisitor() { @Override public void visitReferenceExpression(@NotNull PsiReferenceExpression expression) { if (!result.get().booleanValue()) { return; } super.visitReferenceExpression(expression); final PsiElement target = expression.resolve(); if (!(target instanceof PsiVariable)) { return; } final PsiElement[] defs = DefUseUtil.getDefs(block, (PsiVariable)target, cause); for (PsiElement def : defs) { if (def.getTextOffset() > offset) { result.set(Boolean.FALSE); } } } }); return result.get().booleanValue(); }