Collection<PsiExpression> (@NotNull PsiVariable psiVariable, final boolean literalsOnly, final PsiElement place) { Ref<Boolean> modificationRef = Ref.create(Boolean.FALSE); PsiElement codeBlock = place == null? null : getTopmostBlockInSameClass(place); int placeOffset = codeBlock != null? place.getTextRange().getStartOffset() : 0; PsiFile containingFile = psiVariable.getContainingFile(); LocalSearchScope scope = new LocalSearchScope(new PsiElement[]{containingFile}, null, true); Collection<PsiReference> references = ReferencesSearch.search(psiVariable, scope).findAll(); List<PsiExpression> list = ContainerUtil.mapNotNull( references, (NullableFunction<PsiReference, PsiExpression>)psiReference -> { if (modificationRef.get()) return null; final PsiElement parent = psiReference.getElement().getParent(); if (parent instanceof PsiAssignmentExpression assignmentExpression) { final IElementType operation = assignmentExpression.getOperationTokenType(); if (assignmentExpression.getLExpression() == psiReference) { if (JavaTokenType.EQ.equals(operation)) { final PsiExpression rValue = assignmentExpression.getRExpression(); if (!literalsOnly || allOperandsAreLiterals(rValue)) { // if there's a codeBlock omit the values assigned later if (PsiTreeUtil.isAncestor(codeBlock, parent, true) && placeOffset < parent.getTextRange().getStartOffset()) { return null; } return rValue; } else { modificationRef.set(Boolean.TRUE); } } else if (JavaTokenType.PLUSEQ.equals(operation)) { modificationRef.set(Boolean.TRUE); } } } return null; }); if (modificationRef.get()) return Collections.emptyList(); PsiExpression initializer = psiVariable.getInitializer(); if (initializer != null && (!literalsOnly || allOperandsAreLiterals(initializer))) { list = ContainerUtil.concat(list, Collections.singletonList(initializer)); } return list; }