FinishMarker (List<PsiExpression> nonTerminalReturns, PsiReturnStatement terminalReturn, PsiType returnType, PsiElementFactory factory) { boolean isLong = PsiTypes.longType().equals(returnType); LongRangeSet fullSet = requireNonNull(JvmPsiRangeSetUtil.typeRange(returnType)); LongRangeSet set = nonTerminalReturns.stream() .map(CommonDataflow::getExpressionRange) .map(range -> range == null ? fullSet : range) .reduce(LongRangeSet::join) .orElse(fullSet); if (!set.isEmpty() && !set.contains(fullSet)) { PsiExpression terminalReturnValue = terminalReturn == null ? null : terminalReturn.getReturnValue(); LongRangeSet terminal = CommonDataflow.getExpressionRange(terminalReturnValue); Long point; if (terminal != null) { point = terminal.getConstantValue(); if (point != null && !set.contains(point)) { PsiExpression defValue = canMoveToStart(terminalReturnValue) ? (PsiExpression)terminalReturnValue.copy() : factory.createExpressionFromText(point + (isLong ? "L" : ""), null); return new FinishMarker(FinishMarkerType.VALUE_NON_EQUAL, defValue); } } long[] candidates = {0, 1, -1, fullSet.min(), fullSet.max()}; point = null; for (long candidate : candidates) { if (!set.contains(candidate)) { point = candidate; break; } } if (point != null) { String text = point == Integer.MIN_VALUE ? "java.lang.Integer.MIN_VALUE" : point == Integer.MAX_VALUE ? "java.lang.Integer.MAX_VALUE" : point == Long.MIN_VALUE ? "java.lang.Long.MIN_VALUE" : point == Long.MAX_VALUE ? "java.lang.Long.MAX_VALUE" : String.valueOf(point); return new FinishMarker(FinishMarkerType.VALUE_NON_EQUAL, factory.createExpressionFromText(text, null)); } } return new FinishMarker(FinishMarkerType.SEPARATE_VAR, findBestExpression(terminalReturn, nonTerminalReturns, true)); }