boolean (PsiElement element) { PsiElement scope = PsiTreeUtil.getParentOfType(element, PsiStatement.class, PsiVariable.class); PsiExpression topExpression = scope instanceof PsiIfStatement ifStatement ? ifStatement.getCondition() : scope instanceof PsiVariable variable ? variable.getInitializer() : null; if (!PsiTreeUtil.isAncestor(topExpression, element, false)) return false; return StreamEx.<PsiElement>ofTree(topExpression, e -> StreamEx.of(e.getChildren())) .anyMatch(ConstantValueInspection::isCompileTimeFlagCheck); }