PsiElementVisitor (@NotNull ProblemsHolder holder, boolean isOnTheFly) { return new JavaElementVisitor() { @Override public void visitPolyadicExpression(@NotNull PsiPolyadicExpression expression) { IElementType type = expression.getOperationTokenType(); boolean andChain = type.equals(JavaTokenType.ANDAND); if (!andChain && !type.equals(JavaTokenType.OROR)) return; for (List<RangeConstraint> run : StreamEx.of(expression.getOperands()).map(ExcessiveRangeCheckInspection::extractConstraint) .groupRuns(RangeConstraint::sameExpression)) { if (run.size() <= 1) continue; BinaryOperator<LongRangeSet> reductionOp = andChain ? LongRangeSet::meet : LongRangeSet::join; LongRangeSet set = run.stream().map(c -> c.myConstraint).reduce(reductionOp).orElse(LongRangeSet.empty()); if (set.isEmpty()) continue; RangeConstraint constraint = run.get(0); if (!andChain) { set = constraint.getFullRange().subtract(set); } Long value = set.getConstantValue(); boolean useHex = SyntaxTraverser.psiTraverser(expression).filter(PsiLiteralExpression.class) .filter(c -> TypeConversionUtil.isIntegralNumberType(c.getType()) && c.getText().startsWith("0x")).isNotEmpty(); if (value != null) { String valueRepresentation = useHex ? "0x" + Long.toHexString(value).toUpperCase(Locale.ROOT) : Long.toString(value); if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) { valueRepresentation += "L"; } String text = constraint.myExpression.getText() + constraint.getExpressionSuffix(); String replacement = text + ' ' + (andChain ? "==" : "!=") + ' ' + valueRepresentation; String message = InspectionGadgetsBundle.message("inspection.excessive.range.check.message", replacement); holder.registerProblem(expression, new TextRange(constraint.myRange.getStartOffset(), run.get(run.size() - 1).myRange.getEndOffset()), message, new ExcessiveRangeCheckFix(replacement)); } } } }; }