diff --git a/python/python-ast/src/com/jetbrains/python/ast/PyAstNumericLiteralExpression.java b/python/python-ast/src/com/jetbrains/python/ast/PyAstNumericLiteralExpression.java index 8aaad5a51979..cd1ab243e274 100644 --- a/python/python-ast/src/com/jetbrains/python/ast/PyAstNumericLiteralExpression.java +++ b/python/python-ast/src/com/jetbrains/python/ast/PyAstNumericLiteralExpression.java @@ -35,43 +35,32 @@ public interface PyAstNumericLiteralExpression extends PyAstLiteralExpression { @Nullable default Long getLongValue() { final BigInteger value = getBigIntegerValue(); - - return Optional - .ofNullable(value) - .map(BigInteger::longValue) - .filter(longValue -> BigInteger.valueOf(longValue).equals(value)) - .orElse(null); + long longValue = value.longValue(); + return BigInteger.valueOf(longValue).equals(value) ? longValue : null; } /** * Returns the value of this literal as a {@code BigInteger} (with any * fraction truncated). */ - @Nullable + @NotNull default BigInteger getBigIntegerValue() { if (isIntegerLiteral()) { return getBigIntegerValue(getNode().getText()); } final BigDecimal bigDecimal = getBigDecimalValue(); - return bigDecimal == null ? null : bigDecimal.toBigInteger(); + return bigDecimal.toBigInteger(); } /** * Returns the exact value of this literal. */ - @Nullable + @NotNull default BigDecimal getBigDecimalValue() { final String text = getNode().getText(); - - if (isIntegerLiteral()) { - return Optional - .ofNullable(getBigIntegerValue(text)) - .map(BigDecimal::new) - .orElse(null); - } - - return new BigDecimal(prepareLiteralForJava(text, 0)); + return isIntegerLiteral() ? new BigDecimal(getBigIntegerValue(text)) + : new BigDecimal(prepareLiteralForJava(text, 0)); } default boolean isIntegerLiteral() { @@ -88,7 +77,7 @@ public interface PyAstNumericLiteralExpression extends PyAstLiteralExpression { return isIntegerLiteral() ? StringUtil.nullize(retrieveSuffix(getText())) : null; } - @Nullable + @NotNull private static BigInteger getBigIntegerValue(@NotNull String text) { if (text.equalsIgnoreCase("0" + retrieveSuffix(text))) { return BigInteger.ZERO; diff --git a/python/python-psi-api/src/com/jetbrains/python/psi/impl/PyVersionCheck.kt b/python/python-psi-api/src/com/jetbrains/python/psi/impl/PyVersionCheck.kt index e4f3c1ef8ab6..ad214e44a548 100644 --- a/python/python-psi-api/src/com/jetbrains/python/psi/impl/PyVersionCheck.kt +++ b/python/python-psi-api/src/com/jetbrains/python/psi/impl/PyVersionCheck.kt @@ -73,7 +73,7 @@ data class PyVersionCheck(val version: Version, val isLessThan: Boolean) { private fun evaluateNumber(expression: PyAstExpression?): Int? { if (expression !is PyAstNumericLiteralExpression) return null if (!expression.isIntegerLiteral) return null - val value = expression.bigIntegerValue ?: return null + val value = expression.bigIntegerValue val intValue = value.toInt() return if (BigInteger.valueOf(intValue.toLong()) == value) intValue else null } diff --git a/python/python-psi-impl/src/com/jetbrains/python/inspections/PyDictDuplicateKeysInspection.java b/python/python-psi-impl/src/com/jetbrains/python/inspections/PyDictDuplicateKeysInspection.java index 7c8da1189a41..e40d6572800b 100644 --- a/python/python-psi-impl/src/com/jetbrains/python/inspections/PyDictDuplicateKeysInspection.java +++ b/python/python-psi-impl/src/com/jetbrains/python/inspections/PyDictDuplicateKeysInspection.java @@ -115,13 +115,11 @@ public final class PyDictDuplicateKeysInspection extends PyInspection { if (node instanceof PyNumericLiteralExpression) { final BigDecimal value = ((PyNumericLiteralExpression)node).getBigDecimalValue(); - if (value != null) { - final String keyValue = value.toPlainString(); - return !value.equals(BigDecimal.ZERO) && - myTypeEvalContext.getType((PyNumericLiteralExpression)node) == PyBuiltinCache.getInstance(node).getComplexType() - ? keyValue + "j" - : keyValue; - } + final String keyValue = value.toPlainString(); + return !value.equals(BigDecimal.ZERO) && + myTypeEvalContext.getType((PyNumericLiteralExpression)node) == PyBuiltinCache.getInstance(node).getComplexType() + ? keyValue + "j" + : keyValue; } return node instanceof PyLiteralExpression || node instanceof PyReferenceExpression ? node.getText() : null; diff --git a/python/python-psi-impl/src/com/jetbrains/python/psi/impl/PyEvaluator.java b/python/python-psi-impl/src/com/jetbrains/python/psi/impl/PyEvaluator.java index c1c544bca63a..d7dfd7965691 100644 --- a/python/python-psi-impl/src/com/jetbrains/python/psi/impl/PyEvaluator.java +++ b/python/python-psi-impl/src/com/jetbrains/python/psi/impl/PyEvaluator.java @@ -128,9 +128,7 @@ public class PyEvaluator { private static Object evaluateNumeric(@NotNull PyNumericLiteralExpression expression) { if (expression.isIntegerLiteral()) { final BigInteger value = expression.getBigIntegerValue(); - if (value != null) { - return fromBigInteger(value); - } + return fromBigInteger(value); } return null;