PsiExpression (@NotNull PsiReferenceExpression referenceExpression, @NotNull PsiField field) { if (!field.hasModifierProperty(PsiModifier.FINAL)) return null; final PsiClass psiClass = ObjectUtils.tryCast(field.getParent(), PsiClass.class); if (psiClass != null) { final boolean isStatic = field.hasModifierProperty(PsiModifier.STATIC); final List<PsiClassInitializer> initializers = ContainerUtil.filter(psiClass.getInitializers(), initializer -> initializer.hasModifierProperty(PsiModifier.STATIC) == isStatic); for (PsiClassInitializer initializer : initializers) { final PsiExpression assignedExpression = getAssignedExpression(initializer, field); if (assignedExpression != null) { return assignedExpression; } } if (!isStatic) { final PsiMethod[] constructors = psiClass.getConstructors(); if (constructors.length == 1) { return getAssignedExpression(constructors[0], field); } for (PsiMethod constructor : constructors) { if (PsiTreeUtil.isAncestor(constructor, referenceExpression, true)) { return getAssignedExpression(constructor, field); } } } } return null; }