List<PsiField> (@NotNull final PsiField field) { final List<PsiField> referencedElements = new ArrayList<>(); PsiExpression fieldInitializer = field.getInitializer(); PsiClass containingClass = field.getContainingClass(); if (fieldInitializer == null || containingClass == null) { return referencedElements; } Set<PsiField> classFields = myCachedClassFields.get(containingClass); if (classFields == null) { classFields = ContainerUtil.map2Set(containingClass.getFields(), Functions.id()); myCachedClassFields.put(containingClass, classFields); } final Set<PsiField> containingClassFields = classFields; fieldInitializer.accept(new JavaRecursiveElementVisitor() { int myCurrentMethodLookupDepth; private static final int MAX_METHOD_LOOKUP_DEPTH = 3; @Override public void visitReferenceExpression(@NotNull PsiReferenceExpression expression) { PsiElement ref = expression.resolve(); if (ref instanceof PsiField && containingClassFields.contains(ref) && hasSameStaticModifier(field, (PsiField)ref)) { referencedElements.add((PsiField)ref); } else if (ref instanceof PsiMethod && myCurrentMethodLookupDepth < MAX_METHOD_LOOKUP_DEPTH) { myCurrentMethodLookupDepth++; visitMethod((PsiMethod)ref); myCurrentMethodLookupDepth--; } super.visitReferenceExpression(expression); } }); return referencedElements; }