PsiField (PsiClass aClass) { Stream<PsiField> fieldStream = Arrays.stream(aClass.getFields()); StreamEx<PsiField> enclosingClassFields = StreamEx.iterate(aClass.getContainingClass(), nonNull(), c -> c.getContainingClass()).filter(nonNull()) .flatMap(c -> Stream.of(c.getFields())); fieldStream = Stream.concat(fieldStream, enclosingClassFields); fieldStream = Stream.concat(fieldStream, Arrays.stream(aClass.getInnerClasses()) .filter(innerClass -> innerClass.hasModifierProperty(PsiModifier.STATIC)) .flatMap(innerClass -> Arrays.stream(innerClass.getFields()))); final List<PsiField> fields = fieldStream.filter(field -> resolveToSingletonField(aClass, field)).limit(2).toList(); return fields.size() == 1 ? fields.get(0) : null; }